#!/bin/sh
#
# Takes the name of the file (say, foo) _without_ the .mml extension as
# the argument, produces foo.nsf.
#
# Note: make sure that NSF_TEMPLATE is set appropriately, and that the
# files it includes are in the current directory.

NSF_TEMPLATE=make_nsf.txt

(mckc -m1 $1.mml $1.h | tee /tmp/superfoo) || exit 1
COUNT=`awk '/Total Count/ { print $5 }' /tmp/superfoo`
TITLE=`grep Title $1.h | cut -d ' ' -f 3-`
TITLE=`echo "[$TITLE (]" n $COUNT '16.666*1000/d60/n[:]n60%[0n]sadZd0=a1=an[)]nq' | dc`
COMPOSER=`grep Composer $1.h | cut -d ' ' -f 3-`
MAKER=`grep Maker $1.h | cut -d ' ' -f 3-`
echo '	' .include '"'$1.h'"' | cat $NSF_TEMPLATE - | \
    sed -e "s/Song Name/$TITLE/" -e "s/Artist/$COMPOSER/" \
    -e "s/Maker/$MAKER/" > $1.asm
nesasm -raw $1.asm || exit 1
mv $1.nes $1.nsf
rm $1.h $1.asm
exit 0

# EOF
