#created by starwars                                                            
#modified by Freeware
#version 1.2        
echo emulator

#Jump to user folder
cd /mnt/hd/user/

#delete run folder in RAMDISK
rm -rf /var/run/

#remove non-compatible/not-used drivers
rmmod tdmbdrv
rmmod micom
rmmod rmcon
rmmod v43kbd
rmmod ac97_plugin_wm97xx

#set framebuffer
./v43drv/fbio /dev/fb1 enable 0
./v43drv/fbio /dev/fb2 enable 0

#install modules
insmod /mnt/hd/user/v43drv/v43kbd.ko 
insmod /mnt/hd/user/v43drv/cali.ko 
insmod /mnt/hd/user/v43drv/ac97_plugin_wm97xx.ko
insmod /mnt/hd/user/v43drv/keydrv.ko

# Power on USB Host
./usb_host_power_on
sleep 2

if [ ! -f /usr/lib/libSDL-1.2.so  -o ! -f /usr/lib/libiconv.so.2 -o ! -f /usr/lib/libsigc-1.2.so ]; then
        ./sy.sh
fi

if [ ! -f /usr/lib/libbz2.so -o ! -f /usr/lib/libbz2.so.1.0 -o ! -f /usr/lib/libbz2.so.1.0.3 ]; then
        ./sy.sh
fi

if [ ! -f /usr/lib/libz.so -o ! -f /usr/lib/libz.so.1 -o ! -f /usr/lib/libSDL_gfx.so.13 ]; then
        ./sy.sh
fi

if [ ! -f /usr/lib/libSDL_gfx.so -o ! -f /usr/lib/libSDL_image-1.2.so.0 -o ! -f /usr/lib/libSDL_image-1.2.so ]; then
        ./sy.sh
fi

if [ ! -f /usr/lib/libSDL_mixer-1.2.so.0 -o ! -f /usr/lib/libSDL_mixer-1.2.so -o ! -f /usr/lib/libSDL_ttf-2.0.so ]; then
        ./sy.sh
fi

if [ ! -f /usr/lib/libSDL_mixer-1.2.so.0 -o ! -f /usr/lib/libfreetype.so.6 -o ! -f /usr/lib/libfreetype.so ]; then
        ./sy.sh
fi

if [ ! -e /usr/lib/libdevctl.so ]; then
	./sy.sh
fi

if [ ! -f /mnt/hd/system/cali.dat ] ; then 
        ./ts_cali.run
fi




V43APP_CODE=64
LAUNCHER_CODE=65
APP_CODE=66

ret=$LAUNCHER_CODE

while true
do
	echo "infinite loop $ret"

	case $ret in
	$V43APP_CODE)
		echo "goto main"
		break
		;;
	$LAUNCHER_CODE)
		rm /var/lexec
		./Launcher -u
		ret=$?
		;;
	$APP_CODE)
		if [ -e /var/lexec ]; then
			/var/lexec
		else
			/tmp/launcher_exec.run
		fi
		ret=$LAUNCHER_CODE
		;;
	*)	break
		;;
		esac
done

cd /mnt/hd/system

echo $val

exit $V43APP_CODE
