#!/bin/sh
#
#    Build the stubs.c file.
#    used to trap unimplemented instructions
#

echo
echo "#include \"Log.h\""
echo
echo "typedef struct {"
echo "	void  (*func)();"
echo "	char *fstr;"
echo "	int   ford;"
echo "} TRAPBLOCK;"
echo 
echo "static void traphandler(int );"
echo "extern debuggerbreak();"
echo 

n=500
i=0
while :
do 
	echo "static void trap$i()"
	echo "{"
	echo "  traphandler($i);"
	echo "}"
	echo 
	i=`expr $i + 1`
	if [ "$i" = "$n" ]
	then 
		break;
	fi
done

i=0
echo "TRAPBLOCK wintraps[$n] = { "

while :
do 	
	echo "{ trap$i,0,0 },"
	i=`expr $i + 1`
	if [ "$i" = "$n" ]
	then 
		break;
	fi

done
echo 
echo "};"
echo


echo "static int trapcount;"
echo
echo "static void traphandler(int id)"
echo "{"
echo "	logstr(LF_DEBUG,\"Trapped STUB %s %d\n\","
echo "      wintraps[id].fstr,wintraps[id].ford);"
echo "  debuggerbreak();"
echo "}"
echo 
echo "DWORD"
echo "setstub(char *lpstr,int id)"
echo "{"
echo "  wintraps[trapcount].fstr = lpstr;"
echo "  wintraps[trapcount].ford = id;"
echo "  return (DWORD) wintraps[trapcount++].func;"
echo "}"
echo 
