aboutsummaryrefslogtreecommitdiff
path: root/src/col80_modified/xbm2font.pl
blob: 758d57ea5e5b2d30f57e9cd6a5dff4b50ed4460a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl -w

use bytes;

$c = 0;

while(<>) {
	next unless @bytes = (/0x([0-9a-fA-F]{2})/g);
	for(@bytes) {
		if(!($c % 8)) {
			print "        .byte ";
		}

		printf "\$%02X", reverse_bits(hex $_);

		if(($c % 8 == 7) || ($c == $#bytes)) {
			print "\n";
			$c = 0;
		} else {
			print ",";
			$c++;
		}
	}
}

sub reverse_bits {
	my $bitstr = reverse sprintf("%08b", $_[0]);
	return eval "0b$bitstr";
}