#!/bin/sh # genfont - generate font converted to code from pure font data # author Neil Franklin, last modification 2008.10.12 ### ------ 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:" # --- 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 fi ${CMD_INFO} "generating include ${CONF_OUTFILE} from font ${CONF_INFILE}" >&2 # --- 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}" # --- process font cat "${CONF_INFILE}" | while read LINE ; do if [ "${LINE}" = "" ] ; then # blank line: pass trough into font echo "${LINE}" >> "${CONF_OUTFILE}" elif [ "`echo "${LINE}" | cut -c 1`" = "#" ] ; then # comment: drop it, not in font, do nothing true elif [ "`echo "${LINE}" | cut -c 1-5`" = "CHAR " ] ; then # character definition: process that character into font # output progress info, one dot per character processed echo -n "." >&2 # first also output its intro line as comment echo " ; ${LINE}" >> "${CONF_OUTFILE}" # then separator line echo >> "${CONF_OUTFILE}" # then process the 8 lines of pixel data to segments for SEGMENT in 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 ; do read PIXELS # first pixel with pattern behind it as comment, rest without if [ "`echo "${PIXELS}" | cut -c 1-2`" = "()" ] ; then echo " out VGADPORT,FORE ; ${PIXELS}" >> "${CONF_OUTFILE}" else echo " out VGADPORT,BACK ; ${PIXELS}" >> "${CONF_OUTFILE}" fi echo " ld ZL,X+" >> "${CONF_OUTFILE}" if [ "`echo "${PIXELS}" | cut -c 3-4`" = "()" ] ; then echo " out VGADPORT,FORE" >> "${CONF_OUTFILE}" else echo " out VGADPORT,BACK" >> "${CONF_OUTFILE}" fi echo " mov ZH,ZL" >> "${CONF_OUTFILE}" echo " andi ZH,0x3F" >> "${CONF_OUTFILE}" if [ "`echo "${PIXELS}" | cut -c 5-6`" = "()" ] ; then echo " out VGADPORT,FORE" >> "${CONF_OUTFILE}" else echo " out VGADPORT,BACK" >> "${CONF_OUTFILE}" fi echo " andi ZL,0x80" >> "${CONF_OUTFILE}" echo " ori ZL,${SEGMENT}" >> "${CONF_OUTFILE}" if [ "`echo "${PIXELS}" | cut -c 7-8`" = "()" ] ; then echo " out VGADPORT,FORE" >> "${CONF_OUTFILE}" else echo " out VGADPORT,BACK" >> "${CONF_OUTFILE}" fi echo " ijmp" >> "${CONF_OUTFILE}" # fill up 16 instructions with nop for NOP in 0 1 2 3 4 5 ; do echo " nop" >> "${CONF_OUTFILE}" done # separator from segment of next line of pixel data echo >> "${CONF_OUTFILE}" done else # random text: convert to comment lines in font echo " ; ${LINE}" >> "${CONF_OUTFILE}" fi done # finish off progress info output dots with newline echo >&2