added font2b code to convert linux console fonts to lcd ram layout
[my-code/arm.git] / betty / font2b.c
diff --git a/betty/font2b.c b/betty/font2b.c
new file mode 100644 (file)
index 0000000..6c1af61
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * font2b.c - convert linux console 8x8 font data to betty lcd ram layout
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ * usage:
+ *
+ * first you have to adjust this file two times (see comments!)
+ * don't forget to rebuild.
+ * 
+ * ./font2b > default_font.h
+ *
+ * ONLY 8x8 FONTS SUPPORTED!
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+// put your font data here!
+#include "/usr/src/linux/drivers/video/console/font_pearl_8x8.c"
+
+#define CHAR 1
+#define BINARY 2
+
+int main(int argc,char **argv) {
+
+       unsigned char *font_data;
+       int font,col,row;
+       unsigned char buf;
+       unsigned char stat;
+       int fd=0;
+
+       // adjust the font data pointer here!
+       font_data=(unsigned char *)fontdata_pearl8x8;
+
+       stat=CHAR;
+       if(argc==2) {
+               fd=open(argv[1],O_WRONLY);
+               if(fd<0) {
+                       perror("file open");
+                       return fd;
+               }
+               stat=BINARY;
+       }
+
+       if(stat==CHAR)
+               printf("const unsigned char default_font[%d]={\n",256*8*2);
+
+       for(font=0;font<=0xff;font++) {
+
+               /* print the font number */
+               printf("\t/* %d 0x%02x",font,font);
+               if((font>0x1f)&(font<0x7f))
+                       printf(" %c */\n",font);
+               else
+                       printf(" */\n");
+
+               /* print the array content of the font */
+               for(col=0;col<8;col++) {
+                       buf=0;
+                       for(row=0;row<8;row++)
+                               buf|=(font_data[font*8+row]&(1<<(7-col)));
+                       if(stat==CHAR) {
+                               if(!(col%4))
+                                       printf("\t");
+                               printf("0x%02x,0x%02x",buf,buf);
+                               if((font!=0xff)|(col!=7))
+                                       printf(",");
+                               if(col==3)
+                                       printf("\n");
+                       }
+                       else {
+                               write(fd,&buf,1);
+                               write(fd,&buf,1);
+                       }
+               }
+               if(stat==CHAR)
+                       printf("\n");
+       }
+
+       /* end */
+       if(stat==CHAR)
+               printf("};\n");
+       else
+               close(fd);
+
+       return 0;
+}