// little-endian arch only #include #include #include #include static uint8_t *buf; static size_t filesize; static int loadfile(char *filename) { FILE *fp; fp = fopen(filename, "r"); if (fp == NULL) { printf("loadfile: %s open error\n", filename); return -1; } fseek(fp, 0, SEEK_END); filesize = ftell(fp); fseek(fp, 0, SEEK_SET); buf = calloc(filesize, 2); // XXX if (buf == NULL) goto fin0; fread(buf, filesize, 1, fp); fin0: fclose(fp); return 0; } static void put_header(FILE *fp, uint16_t len, uint16_t cmd, uint16_t arg) { uint16_t hdr[3]; hdr[0] = len; hdr[1] = cmd; hdr[2] = arg; fwrite(hdr, 6, 1, fp); } static void convert_zenkaku(FILE *fp) { int h, l, x, j; for (h = 0x21; h < 0x7f; h++) { for (l = 0x21; l < 0x7f; l++) { j = (h << 8) | l; if ((j >= 0x222f && j <= 0x2239) || (j >= 0x2242 && j <= 0x2249) || (j >= 0x2251 && j <= 0x225b) || (j >= 0x226b && j <= 0x2271) || (j >= 0x227a && j <= 0x227d) || (j >= 0x2321 && j <= 0x232f) || (j >= 0x233a && j <= 0x2340) || (j >= 0x235b && j <= 0x2360) || (j >= 0x237b && j <= 0x237e) || (j >= 0x2474 && j <= 0x247e) || (j >= 0x2577 && j <= 0x257e) || (j >= 0x2639 && j <= 0x2640) || (j >= 0x2659 && j <= 0x267e) || (j >= 0x2742 && j <= 0x2750) || (j >= 0x2772 && j <= 0x277e) || (j >= 0x2821 && j <= 0x2f7e) || (j >= 0x7425)) continue; else x = (h - 0x21) * 94 + (l - 0x21); put_header(fp, 72 + 6, 0, j); // CMD_SETGLYPH fwrite(buf + x * 72, 72, 1, fp); } } } int main(int argc, char *argv[]) { FILE *fp; if (loadfile("ASIYA24.BMP") < 0) goto fin0; if ((fp = fopen("output.fch", "w")) != NULL) { put_header(fp, 6, 2, (24 << 8) | 24); // CMD_SETKANJISIZE convert_zenkaku(fp); fclose(fp); } fin0: return 0; }