#*****  cpl.losh  *****#
#                      #
#**********************#

#*****  Init the display *****#
#video-init sonic 16


# New warm boot attempt - pull warmBoot variable value from the .var file
load-var /cpl/bootInfo.var
echo "warm boot is $bootInfo"

#save the warmBoot value to memory where the CPL can access it
w /b 0x8000040c $bootInfo


#***** Load and execute the CPL binary *****#
#echo "Loading cpl.exe...";
load elf /cpl/cpl.exe
#echo "jumping to /cpl/cpl.exe...";
jump



# The CPL.exe returns execution to LoLo at this point.
# It's return value will be resident in the $? LoLo variable.

bootMode = $?
echo "boot mode is $?";

#*****  Show the full screen splash *****#
bitmap /cpl/anritsu.bmp


#*****  Add additional bitmap display based on the cpl.exe's return value *****#
if ($bootMode == 0x000001c8)
	# Bootstrap mode 
	# Bitmaps size = 235 X 23
	# Note: the x axis size needs to be slightly less than original our you'll see a bar at the end of the bitmap.
	bitmap /cpl/Bootstrap.bmp 25,445 259,468
	#echo "Loading Bootstrap.bmp";
else 
	if	($bootMode == 0x00000008)
		# Master Reset
		# Bitmaps size = 222 X 25
		# Note: the x axis size needs to be slightly less than original our you'll see a bar at the end of the bitmap.
		bitmap /cpl/MasterReset.bmp 25,445 245,470
		#echo "Loading MasterReset.bmp";
	else 
		if	($bootMode == 0x0000001b)
			# Factory Reset
			# Bitmaps size = 222 X 25
			# Note: the x axis size needs to be slightly less than original our you'll see a bar at the end of the bitmap.
			bitmap /cpl/FactoryReset.bmp 25,445 245,470
			#echo "Loading FactoryReset.bmp";
		else
			#echo "No additional bitmaps need loading";
		endif
	endif
endif

#*****  Turn on the display now that our bitmaps are up *****#
video-on
#***** Save the CPL's return value so the application can inspect it. *****#
w /w 0x80000408 $bootMode


#***** Load and execute the WinCE image file *****#
loadfile = "/cpl/NK.bin"

if ($bootMode == 0x000001c8)
loadfile = "/cpl/bootstrap.bin";
endif
echo "load file set to $loadfile"


load bin $loadfile
loadfailed = $?

if ($loadfailed)
    echo "Failed to load $loadfile";
else
	#echo "Launching $loadfile...";	
    # Launch the CE image (bootstrap or main)
    exec;

endif

echo "Returned from launching $loadfile...";	

