#! /bin/bash
# Used to assemble code and create 'C' header structures
#  for importing into the Z80MBC ISO sketch.

# ANSI COLORS
CRE="$(echo -e '\r\033[K')"
NML="$(echo -e '\033[0;39m')"
RED="$(echo -e '\033[1;31m')"
GRN="$(echo -e '\033[1;32m')"
YEL="$(echo -e '\033[1;33m')"
BLU="$(echo -e '\033[1;34m')"
MAG="$(echo -e '\033[1;35m')"
CYN="$(echo -e '\033[1;36m')"
WHT="$(echo -e '\033[1;37m')"
#
TASM=/opt/tasm/TASM.EXE		# Specify the location to TASM.EXE
export TASMTABS=$( dirname $TASM )
#
if [ $# == 0 ] ; then
  echo
  echo "${CYN}Usage: ${YEL}$(basename $0) [options] [source file]${NML}"
  echo
  wine $TASM 2>/dev/null
  echo
else
  if [ "x$*" != "x" ]; then
    TASMOPTS="-80 -la -h -x -s"
    ARGS=$*
  fi
  echo "${CYN}Spawning: ${MAG}wine $TASM $TASMOPTS $ARGS${NML}"
  wine $TASM $TASMOPTS $ARGS 2>/dev/null
  mv $(basename $ARGS .asm).obj $(basename $ARGS .asm).hex

  # Create 'C' header structure
  xxd -i $1 | sed 's/unsigned char/const byte/g' | sed 's/\[\] = {/\[\] PROGMEM = {/g' > ${1%%.*}.h
fi
