16x16漢字フォント表示テスト

Dependencies:   SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GKanji16.cpp Source File

GKanji16.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 SDFileSystem sd(p5, p6, p7, p8, "sd");
00004 
00005 int Load_Font16(uint16_t req, uint8_t *buff)
00006 {
00007     static FILE *fp = 0;
00008 
00009     if ((fp == 0) || (req == 0xFFF0)) {
00010         fp = fopen("/sd/jiskan16.fnt", "rb");
00011         if (req == 0xFFF0) return((fp) ? 0 : -1);
00012     }
00013 
00014     if (req == 0xFFF1) {
00015         fclose(fp);
00016         return(0);
00017     }
00018 
00019     if (fseek(fp, (req * 32L), SEEK_SET) != -1) {
00020         fread(buff, 1, 32, fp);
00021         return(0);
00022     }
00023     return(-1);
00024 }
00025 
00026 void Disp_Font16(uint16_t k)
00027 {
00028     uint8_t buff[16][2];
00029 
00030     k -= (k > 0x9FFC) ? (0x8140 + 0x4000) : 0x8140;
00031     if (k & 0x00C0) k--;
00032     k = ((k >> 8) * 94 * 2) + (k & 0x00FF);
00033 
00034     Load_Font16(k, buff[0]);
00035 
00036     for (int y = 0; y < 16; y++) {
00037         for (int x = 0; x < 2; x++) {
00038             for (uint8_t m = 0x80; m; m >>= 1) {
00039                 printf((buff[y][x] & m) ? "o" : ".");
00040             }
00041         }
00042         printf("\n");
00043     }
00044     printf("\n");
00045 }
00046 
00047 
00048 void Disp_KANJI(uint16_t *s)
00049 {
00050     while(*s) Disp_Font16(*s++);
00051 }
00052 
00053 uint16_t kstr[] = {
00054     0x93FA, 0x967B, 0x8CEA, 0x955C, 0x8EA6, 0x82CC, 0x8365, 0x8358, 0x8367, 0x82C5, 0x82B7, 0x8142
00055     , 0
00056 };
00057 
00058 
00059 int main()
00060 {
00061     Disp_KANJI(kstr);
00062 
00063     uint16_t ds = 0x93FA;
00064     uint16_t de = 0x94FF;
00065 
00066     for ( ; ds < de; ds++) {
00067         if (ds < 0x8140) continue;
00068         if (ds > 0xE0FC) break;
00069         if ((ds & 0x00FF) <  0x40) continue;
00070         if ((ds & 0x00FF) == 0x7F) continue;
00071         if ((ds & 0x00FF) >  0xFC) continue;
00072 
00073         printf("%04X:\n", ds);
00074         Disp_Font16(ds);
00075     }
00076 }