// SPDX-License-Identifier: WTFPL #include #include #include #define BUILD_FONT_TOOL #include "UC1701_charset_JA.h" static void display_8(const uint8_t *data) { int i, j, k, start, end, width; start = data[2]; end = data[3]; width = data[4]; data += 8; for (i = start; i <= end; i++) { printf("* %d --------\n", i); for (j = 0; j < width; j++) { for (k = 0; k < 8; k++) { printf("%s", (*data & (0x80 >> k)) ? "■" : " "); } printf("|\n"); data++; } } } static void display_16(const uint8_t *data) { int d, i, j, k, start, end, width; const uint8_t *p; start = data[2]; end = data[3]; width = data[4]; p = data + 8; for (i = start; i <= end; i++) { printf("* %d --------\n", i); for (j = 0; j < width; j++) { d = p[j] | (p[j + width] << 8); for (k = 0; k < 16; k++) { printf("%s", (d & (0x8000 >> k)) ? "■" : " "); } printf("|\n"); } p += 16; } } static void display_32(const uint8_t *data) { int d, i, j, k, start, end, width; const uint8_t *p; start = data[2]; end = data[3]; width = data[4]; p = data + 8; for (i = start; i <= end; i++) { printf("* %d --------\n", i); for (j = 0; j < width; j++) { d = (p[j] | (p[j + width] << 8) | (p[j + width * 2] << 16) | (p[j + width * 3] << 24)); for (k = 0; k < 32; k++) { printf("%s", (d & (0x80000000 >> k)) ? "■" : " "); } printf("|\n"); } p += 64; } } static const uint8_t *decompress(const uint8_t *data, uint8_t *out) { int i, j, n; const uint8_t *p; p = data + 1; for (i = 0; i < *data; i++) { n = *p++; for (j = 0; j < *p + 1; j++) *out++ = n; p++; } return data + 1 + *data * 2; } static void display_32_compressed(const uint8_t *data) { int d, i, j, k, start, end, width; uint8_t *tmp; const uint8_t *p; start = data[2]; end = data[3]; width = data[4]; tmp = alloca(data[7]); p = data + 8; for (i = start; i <= end; i++) { printf("* %d --------\n", i); p = decompress(p, tmp); for (j = 0; j < width; j++) { d = (tmp[j] | (tmp[j + width] << 8) | (tmp[j + width * 2] << 16) | (tmp[j + width * 3] << 24)); for (k = 0; k < 32; k++) { printf("%s", (d & (0x80000000 >> k)) ? "■" : " "); } printf("|\n"); } } } int main(int argc, char *argv[]) { int n = (argc < 2) ? -1 : atoi(argv[1]); switch (n) { case 0: display_8(font_6x8); break; case 1: display_8(font_6x8_bold); break; case 2: display_8(font_8x8); break; case 3: display_16(font_8x16); break; case 4: display_32(font_16x32); break; case 5: display_32_compressed(font_16x32_compressed); break; default: /* do nothing */ break; } return 0; }