#!/usr/bin/perl -w # Read raw font data from atari rom images, plus a few hand-drawn # "text bitmaps" from __DATA__. # Write 3 bitmap font "txt" files in the format txt2psf expects, then # runs txt2psf on them. Results in 3 fonts: # fauxtari-8.psf - 8x8 native size # fauxtari-16.psf - 16x16 scaled up # fauxtari-24.psf - 24x24 scaled up # The fiddly bits of this are getting the Unicode mappings correct. # ROM dumps are mapped to Atari address space at $C000, the regular # charset starts at $E000, so it's at offset $2000 (8192) in the # image. The XL international set is at $CC00, or offset $0C00 (3072). # In the Arabic ROM, the Arabic font takes the place of the standard # charset. All the charsets are 1K in size. # Arabic ROM, plus some info about it and a mention of the Hebrew ROM: # https://www.savetz.com/vintagecomputers/arabic65xe/ # TODO; # BDF fonts too: psf2bdf --iso10646 --fontname ... # Arabic. use bytes; $fontname = "fauxtari"; sub byte2line { my $t = shift; $t = sprintf("%08b", $t); $t =~ y/0/-/; $t =~ y/1/#/; return $t; } sub scale_line { my $line = shift; my $scale = shift; my $one = '#' x $scale; my $zero = '-' x $scale; $line =~ s/#/$one/g; $line =~ s/-/$zero/g; return ($line x $scale); } sub chr2output { my $codepoint = shift; my $bytes = shift; my $scale = shift || 1; my $unicode = ""; if(!ref $codepoint) { $codepoint = [ $codepoint ]; } $unicode .= sprintf("[%04x];", $_) for @$codepoint; my $result = sprintf("%%\nUnicode: %s\nBitmap: \\\n", $unicode); for(0..7) { my $byte = $bytes->[$_]; my $line = byte2line($byte); $result .= scale_line($line, $scale); $result .= " \\" unless $_ == 7; $result .= "\n"; } return $result; } sub internal2byte { my $t = shift; $t =~ y/-/0/; $t =~ y/#/1/; return pack("B*", $t); } sub psf2txt_header { my $charcount = shift; my $scale = shift; my $w = 8 * $scale; my $h = 8 * $scale; return <) { push @scale1, $_; $cnt++ if /^%/; if(/^\s/) { push @scale2, scale_line($_, 2); push @scale3, scale_line($_, 3); } else { push @scale2, $_; push @scale3, $_; } } #warn "$cnt characters\n"; #warn "(padding to 256 characters)\n" unless $cnt >= 256; #warn "(padding to 512 characters)\n" unless $cnt >= 512; if($cnt > 512) { die "$0: too many characters ($cnt > 512)"; } while($cnt < 512) { my $fake = "%\nUnicode: [0000];\nBitmap: "; push @scale1, $fake . (("-" x 8) x 8) . "\n"; push @scale2, $fake . (("-" x 16) x 16) . "\n"; push @scale3, $fake . (("-" x 24) x 24) . "\n"; $cnt++; } #warn "$cnt characters with padding\n"; sub mkfonts { my $px = shift; my $scaled_data = shift; my $scale = shift; open $fh, '>', "$fontname-$px.txt" or die $!; print $fh psf2txt_header($cnt, $scale); print $fh $_ for(@$scaled_data); close $fh; system("txt2psf $fontname-$px.txt $fontname-$px.psf"); system("psf2bdf --iso10646 --fontname=$fontname-$px $fontname-$px.psf | perl ./fixbdf.pl $px > $fontname-$px.bdf"); } mkfonts(8, \@scale1, 1); mkfonts(16, \@scale2, 2); mkfonts(24, \@scale3, 3); exit 0; __DATA__ % // backtick Unicode: [0060]; Bitmap: \ -------- \ --##---- \ --##---- \ ---##--- \ -------- \ -------- \ -------- \ -------- % // curlies Unicode: [007b]; Bitmap: \ ----##-- \ ---##--- \ ---##--- \ --##---- \ ---##--- \ ---##--- \ ----##-- \ -------- % Unicode: [007d]; Bitmap: \ --##---- \ ---##--- \ ---##--- \ ----##-- \ ---##--- \ ---##--- \ --##---- \ -------- % // tilde Unicode: [007e]; Bitmap: \ -------- \ -###--## \ ##-##-## \ ##--###- \ -------- \ -------- \ -------- \ -------- % // euro Unicode: [20ac]; Bitmap: \ ---####- \ --##---- \ -#####-- \ --##---- \ -#####-- \ --##---- \ ---####- \ -------- % // spanish left-quote Unicode: [00ab]; Bitmap: \ -------- \ -------- \ -------- \ -##--##- \ ##--##-- \ -##--##- \ -------- \ -------- % // spanish right-quote Unicode: [00bb]; Bitmap: \ -------- \ -------- \ -------- \ ##--##-- \ -##--##- \ ##--##-- \ -------- \ -------- % // spanish inverted question mark Unicode: [00bf]; Bitmap: \ -------- \ ---##--- \ -------- \ ---##--- \ ----##-- \ -##--##- \ --####-- \ -------- % // copyright Unicode: [00a9]; Bitmap: \ -#####-- \ #-----#- \ #--##-#- \ #-#---#- \ #--##-#- \ #-----#- \ -#####-- \ -------- % // degrees Unicode: [00b0];[00ba]; Bitmap: \ -------- \ ---##--- \ --#--#-- \ ---##--- \ -------- \ -------- \ -------- \ --------