#!/bin/tcsh -f

if ( $1 == "" || $2 == "" ) then
  echo "This procedure is for flashing the EPROM on an ICEPIC card."
  echo "Syntax:   ./flashpic <devno> <loadfile>"
  echo "  or       ice flash <devno> <loadfile>"
  echo "where <devno> is the zero-based index of the PIC card, and <loadfile> is "
  echo "the filename to load including the signature suffix (eg. icepic6_hh)."
  exit
endif

set picno   = $1 ; if ( $picno == "" ) set picno = 0
set picsig  = $2 ; if ( $picsig == "" ) set picsig = "bogus"

if ( ! $?ICEROOT ) setenv ICEROOT `readlink -f $0 | sed 's/\/test\/flashpic//'`

echo -n "Loading SIG=$picsig from ICEROOT=$ICEROOT on PIC=$picno.  Are you sure [Y/N]? "
set ans = $<

if ( $ans != "y" && $ans != 'Y' ) then
  echo "Aborting loadflash ... "
  exit
endif

cd $ICEROOT/test

if ( ! -e test ) then
  ./build.lnx
endif

./test pic $picno loadflash $picsig

