#!/usr/bin/perl -w $width = 320; $height = 200; $c0 = 0; $c1 = 1; $usage = "$0 input.bmp output.prg"; $bmp = shift || die $usage; unless ($prg = shift) { $prg = $bmp; die $usage unless ($prg =~ s/\.bmp$/\.prg/i); } shift && die $usage; 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 += 1) { $c = ord(substr($line, $x)); if ($c == $c0) { $out[$y] .= "0"; } elsif ($c == $c1) { $out[$y] .= "1"; } else { $out[$y] .= "1"; } } } for ($y = 0; $y < $height; $y++) { print substr($out[$y], 0, 79) . "\n"; } for ($y = 0; $y < $height / 8; $y++) { print $y . "\n"; for ($x = 0; $x < $width / 8; $x++) { foreach $i (0 .. 7) { $line = substr($out[$y*8 + $i], $x*8, 8); $charset .= pack("B8", $line); } } } print "Writing " . length($charset) . " bytes, plus 2\n"; open(PRG, ">$prg") || die; binmode(PRG); print PRG "\x00\x20"; print PRG $charset; close(PRG);