/** I was giggling for about 3 hours for something like this, which took about 2 1/2 h to write (Cigarettes & Alcohol [(tm) Oasis] included)... So, here's psf2c. Distributed under the FWIW License :-P Comments ? -----> rasp@spitzner.org **/ #include #include #include #define PSF1_MAGIC0 0x36 #define PSF1_MAGIC1 0x04 #define PSF1_MODE512 0x01 #define PSF1_MODEHASTAB 0x02 #define PSF1_MODEHASSEQ 0x04 #define PSF1_MAXMODE 0x05 #define PSF1_SEPARATOR 0xFFFF #define PSF1_STARTSEQ 0xFFFE struct psf1_header { unsigned char magic[2]; /* Magic number */ unsigned char mode; /* PSF font mode */ unsigned char charsize; /* Character size */ }; char * printbyte(char byte, char *ptr) { int i; for (i = 0; i != 8; i++) { if((byte & (1 << (7 - i))) != 0) ptr[i] = '*'; else ptr[i] = '-'; } ptr[8] = '\0'; return ptr; } /** psf 1 defines this, I don't know what the garbage at the end of most .psf files is.... **/ #define CMAX 256 int main(int ac,char **av) { FILE *in; struct psf1_header head; char w,h; char comment[256]; // yeah, I know.... char binline[256]; char binbuf[256]; int i; int ind; int ccount; ccount = 0; ind = 0; if(!(in = fopen(av[1],"rb"))) { printf("cannot open infile \'%s\'...\n",av[1]); return 0; } fread(&head,1,4,in); printf("/* Magic %02x%02x,mode %02x, charsize %02x (dec %d) */\n",head.magic[0], head.magic[1],head.mode, head.charsize, head.charsize); printf("/* if ^^^^ this is not 3604 it's not a psf...*/\n"); printf("#define FNAME %s\nunsigned char %s[] = {\n",ac == 3 ? av[2]: "font",ac == 3 ? av[2]: "font"); while(fread(binbuf,1,head.charsize,in) == head.charsize) { ccount ++; printf("/* char %d*/\n",ind++); for(i = 0; i < head.charsize; i++) { printf("0x%02x, /* %s */\n",binbuf[i] & 0xff ,printbyte(binbuf[i],binline)); } if(ccount == CMAX) break; } printf("0x00 }; /* padding, nich schoen, aber selten :-P */\n"); return 0; }