#!/bin/sh

# Check syntax

if [ $# != 2 ]; then
    echo Syntax: $0 input_filename output_filename
    echo
    echo 'Input is a 737[G] raw VGA font file.'
    echo 'Output is an ISO-8859-7 (ELOT-928) raw VGA font file.'
    echo
    exit 1
fi

input=$1
output=$2


# Check input file

if [ ! -r $input ]; then
    echo Unable to read $input
    exit 1
fi

size=`wc -c <$input`
scanlines=$[ $size / 256]

if [ $[ $scanlines * 256 ] != $size ]; then
    echo $input does not seem to be a raw VGA font file.
    echo If it is, it does not contain all 256 characters.
    exit 1
fi

echo Converting font $1 with $scanlines scanlines per character.


# Dump first 128 characters directly to the output font

dd if=$input of=$output bs=$scanlines count=128 2>/dev/null


# Map the rest onto the ISO-8859-7 character space.

xlation="
    20  20  20  20  20  20  20  20  20  20  20  20  20  20  20  20
    20  20  20  20  20  20  20  20  20  20  20  20  20  20  20  20
    20  22  41  23  23  59  7c  53  22  43  98  22  cf  c4  52  73
    f8  f1  fd  3f  27  a3  50  f9  84  86  88  22  8e  3f  93  97
    e4  80  81  82  83  84  85  86  87  88  89  8a  8b  8c  8d  8e
    8f  90  fa  91  92  93  94  95  96  97  88  93  e1  e2  e3  e5
    e8  98  99  9a  9b  9c  9d  9e  9f  a0  a1  a2  a3  a4  a5  a6
    a7  a8  aa  a9  ab  ac  ad  ae  af  e0  e4  e8  e6  e7  e9  20"

for c in $xlation; do
    dd if=$input >>$output bs=$scanlines skip=$[ 0x$c ] count=1 2>/dev/null
done

# Done
