Initial commit
[savezelda.git] / loader / font2c.pl
1 #!/usr/bin/perl
2
3
4 # Read PPM file.
5
6 $sig = <>; chomp $sig;
7 $sizes = <>; chomp $sizes;
8 $cols = <>; chomp $cols;
9
10 {
11         local $/;
12         $data = <>;
13 }
14
15
16 # Sanity check.
17
18 $sig ne "P6" and die;
19 $sizes ne "90 256" and die;
20 $cols ne "255" and die;
21 (length $data) != 3 * 90 * 256 and die;
22
23
24 # Output header.
25
26 print "// GENERATED FILE DO NOT EDIT\n";
27 print "\n";
28 print "#include \"loader.h\"\n";
29 print "\n";
30 print "const u8 console_font_10x16x4[96*80] = {\n";
31
32 # Output data.
33
34 for my $ch (2..7) {
35         for my $cl (0..15) {
36                 printf "\n\t// %x%x\n", $ch, $cl;
37                 for my $py (0..15) {
38                         print "\t";
39                         for my $px (0..9) {
40                                 my $hor = $px + 10*($ch - 2);
41                                 my $ver = $py + 16*$cl;
42                                 my $wot = $hor + 90*$ver;
43                                 my $bytes = substr($data, 3*$wot, 3);
44                                 my $nyb = int ((ord $bytes) / 16);
45                                 if (($px & 1) == 0) {
46                                         printf "0x%x", $nyb;
47                                 } else {
48                                         printf "%x,", $nyb;
49                                 }
50                         }
51                         print "\n";
52                 }
53         }
54 }
55
56
57 # Output footer.
58
59 print "\n";
60 print "};\n";