#!/bin/sh # genfont - generate font converted to code from pure font data # author Neil Franklin, last modification 2009.01.22 ### ------ configuration for this site # first CONF_* various site or user dependant user config variables # then DEBUG_* various debugging settings # last SYS_* various system internal values # input file, ASCII drawings of characters pixel maps CONF_INFILE=vga_text_font.fon # output file, AVR code for including CONF_OUTFILE=vga_text_font.inc ### ------ actual implementation from here on # no user settings any more below this point set -e # --- get ready to work # sanitise this place, else some commands may fail PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin export PATH # stuff that goes wrong, not expected by user, not in data output, use >&2 # so also with $0 in case this script was called by an other script # something within the system that user does not expect, give up CMD_FATAL="echo $0: FATAL:" # something from users input, user will correct this and continue CMD_ERROR="echo $0: ERROR:" # something we can continue with, but may be wrong, and user may not suspect it CMD_WARNING="echo $0: WARNING:" # something most likely not wrong, but tell user for the odd case it is wrong CMD_NOTE="echo $0: NOTE:" # normal stuff users expect, so to stdout as normal output, no $0, no marking CMD_INFO="echo" # stuff users asked for, so add to stdout as normal output, no $0, but mark it CMD_DEBUG="echo DEBUG:" # --- convert graphical symbols to segment index values names symbol_to_name () { SYMB="$1" if [ "${SYMB}" = "................" ] ; then NAME="SEGM0000" elif [ "${SYMB}" = "............@@@@" ] ; then NAME="SEGM0001" elif [ "${SYMB}" = "........@@@@...." ] ; then NAME="SEGM0010" elif [ "${SYMB}" = "........@@@@@@@@" ] ; then NAME="SEGM0011" elif [ "${SYMB}" = "....@@@@........" ] ; then NAME="SEGM0100" elif [ "${SYMB}" = "....@@@@....@@@@" ] ; then NAME="SEGM0101" elif [ "${SYMB}" = "....@@@@@@@@...." ] ; then NAME="SEGM0110" elif [ "${SYMB}" = "....@@@@@@@@@@@@" ] ; then NAME="SEGM0111" elif [ "${SYMB}" = "@@@@............" ] ; then NAME="SEGM1000" elif [ "${SYMB}" = "@@@@........@@@@" ] ; then NAME="SEGM1001" elif [ "${SYMB}" = "@@@@....@@@@...." ] ; then NAME="SEGM1010" elif [ "${SYMB}" = "@@@@....@@@@@@@@" ] ; then NAME="SEGM1011" elif [ "${SYMB}" = "@@@@@@@@........" ] ; then NAME="SEGM1100" elif [ "${SYMB}" = "@@@@@@@@....@@@@" ] ; then NAME="SEGM1101" elif [ "${SYMB}" = "@@@@@@@@@@@@...." ] ; then NAME="SEGM1110" elif [ "${SYMB}" = "@@@@@@@@@@@@@@@@" ] ; then NAME="SEGM1111" elif [ "${SYMB}" = "....FFFFXXXXBBBB" ] ; then NAME="SEGM0FXB" elif [ "${SYMB}" = "....FFFFXXXX1111" ] ; then NAME="SEGM0FX1" elif [ "${SYMB}" = "....FFFFXXXX2222" ] ; then NAME="SEGM0FX2" elif [ "${SYMB}" = "....BBBBXXXX3333" ] ; then NAME="SEGM0BX3" else # unknown symbol, so we can not process it ${CMD_ERROR} "unknown symbol \"${SYMB}\", aborting ..." >&2 exit 1 fi return 0 } # --- check input if [ ! -f "${CONF_INFILE}" ] ; then # input file nonexistant, so we can not work on it ${CMD_ERROR} "no input file ${CONF_INFILE} to process" >&2 exit 1 fi ${CMD_INFO} "generating include ${CONF_OUTFILE} from font ${CONF_INFILE}" >&2 # --- start output file, header # remove existing output file, as later all is >> additions rm -f "${CONF_OUTFILE}" # make output file header echo "; ${CONF_OUTFILE} - font for generating VGA text - converted to code" \ >> "${CONF_OUTFILE}" echo "; generated from ${CONF_INFILE}, last generation `date "+%Y.%m.%d"`" \ >> "${CONF_OUTFILE}" echo \ >> "${CONF_OUTFILE}" # --- process input file # get rid of comments (cut), then trailing spaces (may be chopped comment, sed) # and then empty lines (may be chopped comment, grep) cut -f 1 -d '#' "${CONF_INFILE}" | sed -e 's/ *$//' | \ grep -v '^ *$' | while read LINE ; do # extract command of this line CMD="`echo "${LINE}" | cut -f 1 -d ' '`" if [ "${CMD}" = "SECTION" ] ; then # section begin definition: process the name into output file NAME="`echo "${LINE}" | cut -f 2 -d ' '`" echo "${NAME}:" \ >> "${CONF_OUTFILE}" # output progress info, one [S]ection processed echo -n "S" >&2 elif [ "${CMD}" = "NAME" ] ; then # character name definition: process the name and value into output file NAME="`echo "${LINE}" | cut -f 2 -d ' '`" VALUE="`echo "${LINE}" | cut -f 3 -d ' '`" echo " .equ ${NAME} = ${VALUE}" \ >> "${CONF_OUTFILE}" # output progress info, one [N]ame processed echo -n "N" >&2 elif [ "${CMD}" = "CHAR" ] ; then # character definition: process that characters segments, next 8 file lines COMMENT="`echo "${LINE}" | cut -f 2- -d ' '`" echo " ; ${COMMENT}" \ >> "${CONF_OUTFILE}" # for each segment: read it in, convert it to .db data name read SYMB0 symbol_to_name "${SYMB0}" NAME0=${NAME} read SYMB1 symbol_to_name "${SYMB1}" NAME1=${NAME} read SYMB2 symbol_to_name "${SYMB2}" NAME2=${NAME} read SYMB3 symbol_to_name "${SYMB3}" NAME3=${NAME} read SYMB4 symbol_to_name "${SYMB4}" NAME4=${NAME} read SYMB5 symbol_to_name "${SYMB5}" NAME5=${NAME} read SYMB6 symbol_to_name "${SYMB6}" NAME6=${NAME} read SYMB7 symbol_to_name "${SYMB7}" NAME7=${NAME} # output this character to include file, as 8/4=2 lines # must be n*2 bytes for each .db line, use 4 to save file length echo " .db ${NAME0}, ${NAME1}, ${NAME2}, ${NAME3}" \ >> "${CONF_OUTFILE}" #echo " .db low(DR${NAME0}), low(DR${NAME1}), low(DR${NAME2}), low(DR${NAME3})" \ # >> "${CONF_OUTFILE}" echo " .db ${NAME4}, ${NAME5}, ${NAME6}, ${NAME7}" \ >> "${CONF_OUTFILE}" #echo " .db low(DR${NAME4}), low(DR${NAME5}), low(DR${NAME6}), low(DR${NAME7})" \ # >> "${CONF_OUTFILE}" # output progress info, one [C]haracter processed echo -n "C" >&2 else # any other random text: may be bug, not in font, warn user echo >&2 ${CMD_WARNING} "unknown command ignored: \"${LINE}\"" >&2 fi done # finish off progress info output dots with newline echo >&2