added u32 type
[my-code/arm.git] / betty / font2b.c
1 /*
2  * font2b.c - convert linux console 8x8 font data to betty lcd ram layout
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  * usage:
7  *
8  * first you have to adjust this file two times (see comments!)
9  * don't forget to rebuild.
10  * 
11  * ./font2b > default_font.h
12  *
13  * ONLY 8x8 FONTS SUPPORTED!
14  *
15  */
16
17 #define _GNU_SOURCE
18 #include <stdio.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23
24 typedef unsigned int u32;
25
26 // put your font data here!
27 #include "/usr/src/linux/drivers/video/console/font_pearl_8x8.c"
28
29 #define CHAR 1
30 #define BINARY 2
31
32 int main(int argc,char **argv) {
33
34         unsigned char *font_data;
35         int font,col,row;
36         unsigned char buf;
37         unsigned char stat;
38         int fd=0;
39
40         // adjust the font data pointer here!
41         font_data=(unsigned char *)fontdata_pearl8x8;
42
43         stat=CHAR;
44         if(argc==2) {
45                 fd=open(argv[1],O_WRONLY|O_CREAT);
46                 if(fd<0) {
47                         perror("file open");
48                         return fd;
49                 }
50                 stat=BINARY;
51         }
52
53         if(stat==CHAR)
54                 printf("const unsigned char default_font[%d]={\n",256*8);
55
56         for(font=0;font<=0xff;font++) {
57
58                 /* print the font number */
59                 if(stat==CHAR) {
60                         printf("\t/* %d 0x%02x",font,font);
61                         if((font>0x1f)&(font<0x7f))
62                                 printf(" %c */\n",font);
63                         else
64                                 printf(" */\n");
65                 }
66
67                 /* print the array content of the font */
68                 for(col=0;col<8;col++) {
69                         buf=0;
70                         for(row=0;row<8;row++)
71                                 buf|=(((font_data[font*8+row]>>(7-col))&1)<<row);
72                         if(stat==CHAR) {
73                                 if(col==0)
74                                         printf("\t");
75                                 printf("0x%02x",buf);
76                                 if((font!=0xff)|(col!=7))
77                                         printf(",");
78                         }
79                         else {
80                                 write(fd,&buf,1);
81                         }
82                 }
83                 if(stat==CHAR)
84                         printf("\n");
85         }
86
87         /* end */
88         if(stat==CHAR)
89                 printf("};\n");
90         else
91                 close(fd);
92
93         return 0;
94 }