#!/usr/bin/perl -w $width = 72; $height = 21; $c0 = 0; $c1 = 1; $c2 = 2; $c3 = 3; $bmp = shift || die; $sprite = shift || die; open(BMP, $bmp) || die; binmode(BMP); while () { $bmp .= $_; } close(BMP); $bitmap = substr($bmp, -$width * $height); foreach $yy (0 .. $height - 1) { $y = $height - $yy - 1; $line = substr($bitmap, $width * $yy); for ($x = 0; $x < $width; $x += 2) { $c = ord(substr($line, $x)); if ($c == $c0) { $out[$y] .= "00"; } elsif ($c == $c1) { $out[$y] .= "01"; } elsif ($c == $c2) { $out[$y] .= "10"; } elsif ($c == $c3) { $out[$y] .= "11"; } else { $out[$y] .= ".."; } } } for ($y = 0; $y < $height; $y++) { print substr($out[$y], 0, 80) . "\n"; } for ($s = 0; $s < $width / 24; $s++) { print $s . "\n"; foreach $y (0..20) { foreach $x (0..2) { $line = substr($out[$y], $s*24 + $x*8, 8); $spriteset .= pack("B8", $line); } } $spriteset .= "\x00"; # pad } print "Writing " . length($spriteset) . " bytes, plus 2\n"; open(SPRITE, ">$sprite") || die; binmode(SPRITE); print SPRITE "\x00\x20"; print SPRITE $spriteset; close(SPRITE);