#!/bin/bash
|
#!/bin/bash
|
|
|
if [ "$1" = "" ]; then
|
if [ "$1" = "" ]; then
|
echo "Usage: $0 <C file> <bmp flags> <sdcc flags>"
|
echo "Usage: $0 <C file> <bmp flags> <sdcc flags>"
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
SDCC=$(which sdcc)
|
SDCC=$(which sdcc)
|
if [ -z "$SDCC" ]; then
|
if [ -z "$SDCC" ]; then
|
echo "E: bmpsdcc: sdcc is not in PATH."
|
echo "E: bmpsdcc: sdcc is not in PATH."
|
echo "I: sdcc is not related with ztex and ships with many Linux distributions or "
|
echo "I: sdcc is not related with ztex and ships with many Linux distributions or "
|
echo " is available at http://sdcc.sourceforge.net/ ."
|
echo " is available at http://sdcc.sourceforge.net/ ."
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
exe=""
|
exe=""
|
if [ "$WINDIR" != "" ]; then
|
if [ "$WINDIR" != "" ]; then
|
exe=".exe"
|
exe=".exe"
|
fi
|
fi
|
|
|
BINDIR=`dirname $0`
|
BINDIR=`dirname $0`
|
BMP=bmp
|
BMP=bmp
|
if [ -x "$BINDIR/bmp$exe" ]; then
|
if [ -x "$BINDIR/bmp$exe" ]; then
|
BMP="$BINDIR/bmp$exe"
|
BMP="$BINDIR/bmp$exe"
|
fi
|
fi
|
|
|
if [ -f "$BINDIR/peeph.def" ]; then
|
if [ -f "$BINDIR/peeph.def" ]; then
|
PEEPH="--peep-file $BINDIR/peeph.def"
|
PEEPH="--peep-file $BINDIR/peeph.def"
|
elif [ -f "/usr/local/share/ztex/peeph.def" ]; then
|
elif [ -f "/usr/local/share/ztex/peeph.def" ]; then
|
PEEPH="$PEEPH --peep-file /usr/local/share/ztex/peeph.def"
|
PEEPH="$PEEPH --peep-file /usr/local/share/ztex/peeph.def"
|
elif [ -f "/usr/share/ztex/peeph.def" ]; then
|
elif [ -f "/usr/share/ztex/peeph.def" ]; then
|
PEEPH="$PEEPH --peep-file /usr/share/ztex/peeph.def"
|
PEEPH="$PEEPH --peep-file /usr/share/ztex/peeph.def"
|
fi
|
fi
|
|
|
inp="$1"
|
inp="$1"
|
if [ ! -f "$inp" -a -f "$inp.c" ]; then
|
if [ ! -f "$inp" -a -f "$inp.c" ]; then
|
inp="$1.c"
|
inp="$1.c"
|
fi
|
fi
|
base=${inp%*.c}
|
base=${inp%*.c}
|
|
|
if [ ! -f "$inp" ]; then
|
if [ ! -f "$inp" ]; then
|
echo "File not found: $inp"
|
echo "File not found: $inp"
|
exit 2
|
exit 2
|
fi
|
fi
|
|
|
bytePad=""
|
bytePad=""
|
while true; do
|
while true; do
|
if [ "$LINEINFO" = "no" ]; then
|
if [ "$LINEINFO" = "no" ]; then
|
li='//line %2 "%1"'
|
li='//line %2 "%1"'
|
else
|
else
|
li='#line %2 "%1"'
|
li='#line %2 "%1"'
|
fi
|
fi
|
$BMP -c -l "$li" $2 $bytePad $inp -o $base.tmp.c
|
$BMP -c -l "$li" $2 $bytePad $inp -o $base.tmp.c
|
ec="$?"
|
ec="$?"
|
if [ "$ec" != 0 ]; then
|
if [ "$ec" != 0 ]; then
|
exit $ec
|
exit $ec
|
fi
|
fi
|
|
|
"$SDCC" -mmcs51 --code-loc 0x0200 --code-size 0x3800 --xram-loc 0x3A00 --xram-size 0x600 --iram-size 256 $PEEPH $3 $base.tmp.c -o $base.ihx
|
"$SDCC" -mmcs51 --code-loc 0x0200 --code-size 0x3800 --xram-loc 0x3A00 --xram-size 0x600 --iram-size 256 $PEEPH $3 $base.tmp.c -o $base.ihx
|
ec="$?"
|
ec="$?"
|
if [ "$ec" != 0 ]; then
|
if [ "$ec" != 0 ]; then
|
exit $ec
|
exit $ec
|
fi
|
fi
|
|
|
addr=`grep ".*:.* _DeviceDescriptor" $base.map | (
|
addr=`grep ".*:.* _DeviceDescriptor" $base.map | (
|
read a b c
|
read a b c d
|
if [ "$c" = "_DeviceDescriptor" ]; then
|
if [ "$c" = "_DeviceDescriptor" ]; then
|
echo 0x${b#*:}
|
echo 0x${b#*:}
|
else
|
else
|
echo 0x${a#*:}
|
echo 0x${a#*:}
|
fi
|
fi
|
)`
|
)`
|
echo "Addr=$addr"
|
echo "Addr=$addr"
|
if [ $((addr & 1)) = "0" ]; then
|
if [ $((addr & 1)) = "0" ]; then
|
exit 0
|
exit 0
|
else
|
else
|
if [ "$bytePad" != "" ]; then
|
if [ "$bytePad" != "" ]; then
|
echo "USB Descriptors not word aligned, -DPAD_BYTE has no effect"
|
echo "USB Descriptors not word aligned, -DPAD_BYTE has no effect"
|
exit 3
|
exit 3
|
else
|
else
|
bytePad="-D PAD_BYTE"
|
bytePad="-D PAD_BYTE"
|
fi
|
fi
|
fi
|
fi
|
done
|
done
|
|
|