# This is an ide startup file.
report=4 # set verbose, but not debug
$stoponerr=1
hinv -v

$mcotest=0;
$mcoerrs = 0;
$icofailed = 0;

menu {
    /* Display the version of the diagnostic */
echo "///////////////////////////////////////////////////////////////////////////"
    version;
echo ""
echo "             OPTION BOARD FUNCTIONAL TEST OPTIONS "
echo "             -------------------------------------"
echo "Command   Description"
echo ""
echo "mgv_all   Galileo 1.5 function tests"
# echo "cosmo2_all   Cosmo2.0 function tests"
# echo "vino      VINO function tests"
# echo "camera    Indycam function tests"
# echo ""
# echo "gfxva     XL/XZ/Extreme diagnostics with automatic voltage change"
# echo ""
# echo "a2testva  A2 audio diagnostics with automatic voltage change"
echo ""
echo ""
echo "                     TECHNICIAN BENCH OPTIONS"
echo "                     ------------------------"
echo "mgv_menu  Galileo 1.5 menu"
echo "c2_menu Cosmo2.0 menu"
echo "ico_menu  ICO menu"
echo ""
echo "///////////////////////////////////////////////////////////////////////////"
}


unix {
	echo "<<<< About to to boot UNIX......>>>>"
	boot dksc(0,1,0)unix;
}


#START of Galileo1.5 diagnostics
mgv_menu {
echo ""
echo "=================== IMPACT VIDEO IDE COMMANDS ======================"
echo "mg_setboard(0)      mg_reset           mgv_init          mgv_galregl1"
echo "mgv_abdcb           mgv_abaddrbus      mgv_abdatabus     mgv_abpatrn"
echo "mgv_ccdcb           mgv_ccaddrbus      mgv_ccdatabus     mgv_ccpatrn"
echo "mgv_vgiregpatrn     mgv_vgiregwalk     mgv_vgiint        mgv_vgidma"
echo "mgv_voutl0          mgv_voutl1         mgv_vgivoutl0"
echo "mgv_extvin          mgv_vinl1"
echo "mgv_cctovgi         mgv_cctovgix       mgv_readcc        mgv_gpitrig"
echo "mgv_csc_probe       mgv_csc_bus        mgv_csc_coef      mgv_csc_outlut "
echo "help_mgv_csc" 
echo "===================================================================="
echo "mgv_initall         mgv_aball          mgv_ccall	       "
echo "mgv_vgiregall       mgv_vgiintall      mgv_vgidmaall     mgv_vgiall"
echo "mgv_voutall         mgv_vinall         mgv_loopbackall"
echo "mgv_csc_all	  csc_loop"
echo "mgv_all"
echo "=================================================="
echo "*******  USE mgv_all to run all of them  *********"
echo "=================================================="
echo ""
}

help_mgv_csc {
echo "                  HELP FOR RUNNING MGV CSC TESTS "
echo " mgv_csc_probe  : This test checks to see if the option board is attached"
echo " Usage          : mgv_csc_probe"
echo "                        "
echo " mgv_csc_bus    : This performs the address bus test and data bus test, when"
echo "                  different arguments are passed"
echo " Usage          : Data bus test:     mgv_csc_bus -b 1 -t 3"
echo "                  Address bus test:  mgv_csc_bus -b 0 -t 0"
echo " "
echo " mgv_csc_outlut : Performs the output lut test"
echo " Usage          : mgv_csc_outlut"
echo " "
echo " mgv_csc_coef   : Performs the csc coeff test"
echo " Usage          : mgv_csc_coef"
echo ""
echo " mgv_csc_all    : Runs the mgv_csc_probe and the mgv_csc_bus tests "
echo " csc_loop	      : Runs the mgv_csc_all command 20 times and then "
echo "                : boots Unix"
}

mgv_initall {
	$failed = 0;
	echo ""
	buffon;
	mg_setboard 0;
	mg_reset;
	resetcons;
	buffoff;
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_aball {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test AB and DRAM"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_abdcb;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_abaddrbus -r -g -b -a
	if ($status) {
		$failed = 1;
		return($status);
	}

	$status = mgv_abdatabus -r -g -b -a
	if ($status) {
		$failed = 1;
		return($status);
	}

	$status = mgv_abpatrn -r -g -b -a
	if ($status) {
		$failed = 1;
		return($status);
	}

#	$status = mgv_abpatrnslow -r -g -b -a
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_ccall {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test CC and Frame Buffer"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_ccdcb;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_ccaddrbus 
	if ($status) {
		$failed = 1;
		return(1);
	}

	$status = mgv_ccdatabus
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_vgiregall {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test VGI registers"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	$status = mgv_vgiregpatrn
	if ($status) {
		$failed = 1;
		return($status);
	}

	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	$status = mgv_vgiregwalk
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_vgiintall {
	$failed = 0;
#	echo ""
#	echo "=====Initialize & Test VGI Interrupts"
#	$status = mgv_init;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x1;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x2;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x4;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x8;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x10;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -i 0x20;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}

#	$status = mgv_init;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -c 2 -i 0x1;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}

#	$status = mgv_vgiint -c 2 -i 0x2;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}

#	$status = mgv_vgiint -c 2 -i 0x4;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -c 2 -i 0x8;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -c 2 -i 0x10;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
#
#	$status = mgv_vgiint -c 2 -i 0x20;
#	if ($status) {
#		$failed = 1;
#		return($status);
#	}
}

mgv_vgidmaall {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test VGI DMA's"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -t 1 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -v 1 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -v 2 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

#	$status = mgv_vgidma -o 1 -v 3 -z 50; 
#	if ($status) {
#		return($status);
#	}

	ide_delay -s 2;

	$status = mgv_vgidma -v 4 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -t 1 -v 5 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -t 1 -v 5 -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -t 1 -v 6 -y 0x40404040  -z 50; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_initall;
	if ($failed) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -t 1; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -v 1; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -v 2; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

#	$status = mgv_vgidma -c 2 -o 1 -v 3; 
#	if ($status) {
#		return($status);
#	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -v 4; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -t 1 -v 5; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -t 1 -v 5; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -t 1 -v 6 -y 0x40404040 ; 
	if ($status) {
		$failed = 1;
		return($status);
	}

}

mgv_vgiall {
	$failed = 0;
	$status = mgv_vgiregall;
	if ($failed) {
		return($status);
	}
	$status = mgv_vgiintall;
	if ($failed) {
		$failed = 1;
		return($status);
	}
	$status = mgv_vgidmaall;
	if ($failed) {
		$failed = 1;
		return($status);
	}
}


mgv_voutall {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test Video Output"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	echo ""
	echo "******** Please select Channel A on the WFM 601i ********"
	echo "Press <Space> when ready"
	$status = mgv_waitforspace -s 36000
	echo ""
	echo "Confirm patterns on Channel 1 Video Monitor"
	$status = mgv_voutl0 1;
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -ms 10000 ;

	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	echo ""
	$status = mgv_vgivoutl0;
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -ms 10000 ;

	echo ""
	echo "******** Please select Channel B on the WFM 601i ********"
	echo "Press <Space> when ready"
	$status = mgv_waitforspace -s 36000
	echo ""
	echo "Confirm patterns on Channel 2 Video Monitor"
	$status = mgv_voutl0 2;
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -ms 10000 ;

	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	echo ""
	$status = mgv_vgivoutl0 2;
	if ($status) {
		$failed = 1;
		return($status);
	}

}

mgv_vinall {
	$failed = 0;
	echo ""
	echo "=====Initialize & Test Video input"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	echo "Video Input Tests for Channel 1"
	$status = mgv_extvin;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	echo "Video Input Tests for Channel 2"
	$status = mgv_extvin 2;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	$status = mgv_vinl1;
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_loopbackall {
	$failed = 0;
	echo "=====Initialize & Test Loop Back"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	echo ""
	echo "******** Please select the Loop Back switch on the IDE switch box ********"
	echo "Press <Space> when ready"
	$status = mgv_waitforspace -s 36000
	if ($status) {
		echo ""
		echo "CC1 to VGI1 Loop Back Test Timed Out"
		echo ""
	} else {
		echo ""
		echo "CC1 to VGI1 Loop Back Test for Channel 1"
		echo ""
		$status = mgv_cctovgi 1;
		if ($status) {
			$failed = 1;
			return($status);
		}
	}

	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}
	echo "CC1 to VGI1 Loop Back Test for Channel 2"
	$status = mgv_cctovgi 2;
	if ($status) {
		$failed = 1;
		return($status);
	}
}

mgv_csc_all	{
        mgv_initall;	
	echo "Verifying  whether the CSC/TMI optional board is present ..." 
	$failed = 0;
	$status = mgv_csc_probe ;
	if ($status)	{
		echo "CSC/TMI optional board is NOT present"
		return 0;
	}
	else {
		echo "Running CSC diagnostics ...."

		$status = mgv_csc_reset;
                if ($status) {
                        echo "CSC Reset test failed"
                        $failed = 1;
                        return ($status);
                }


		$status = mgv_csc_bus -b 0 -t 0 ;

		if ($status) {
			echo "CSC Address Bus test failed"
			$failed = 1;
			return ($status);
		}
		else {
			echo "CSC Address Bus test passed"
		}

		$status = mgv_csc_bus -b 1 -t 3 ;
		
		if ($status) {
			echo "CSC Data Bus test failed"
			$failed = 1;
			return($status);
		}
		else {
			echo "CSC Data Bus test passed"
		}


		return $status ;
	}
}

csc_loop {

	$status = 0;
	$failed = 0;
        $loop_count = 0;
	while ($loop_count < 20) {
		$status = mgv_csc_all;
		if ($failed) 
		    return($status);
		else { 
		    $loop_count = $loop_count + 1;
		    echo $loop_count;
		}
	}
        unix
}

mgv_all {
	$status = 0;
	$failed = 0;
	echo ""
	echo "Impact Video IDE Test Suite"
	echo ""

############### Initialize & Test GALILEO 1.5 Register Access
	echo ""
	echo "=====Initialize & Test GALILEO 1.5 Register Access"
	$status = mgv_initall;
	if ($failed) {
		return($status);
	}
	$status = mgv_galregl1;
	if ($failed) {
		return($status);
	}

############### Initialize & Test CC and Frame Buffer
	$status = mgv_ccall;
	if ($failed) {
		return($status);
	}

############### Initialize & Test AB and DRAM
	$status = mgv_aball;
	if ($failed) {
		return($status);
	}

############### Initialize & Test VGI registers
	$status = mgv_vgiregall;
	if ($failed) {
		return($status);
	}

############### Initialize & Test VGI Interrupts
#	$status = mgv_vgiintall;
#	if ($failed) {
#		return($status);
#	}

############### Initialize & Test Video Output
	$status = mgv_voutall;
	if ($failed) {
		return($status);
	}

############### Initialize & Test Video input
#	$status = mgv_vinall;
#	if ($failed) {
#		return($status);
#	}

############### Initialize & Test VGI DMA's
	$status = mgv_vgidmaall;
	if ($failed) {
		return($status);
	}

############### Initialize & Test CSC
	$status = mgv_csc_all;
	if ($failed) {
	return($status);
	}

############### Initialize & Test All Loop Back
	$status = mgv_loopbackall;
	if ($failed) {
		return(-1);
	}

############### Test GPI Trigger
	echo "GPI Trigger Polarity Test"
	echo "Please set the GPI trigger switch to the OFF position"
	echo "Press <Space> when ready"
	$status = mgv_waitforspace -s 36000
	if ($status) {
		echo ""
		echo "GPI Trigger Polarity Test Timed Out"
		echo ""
	} else {
		$status = mgv_gpitrig -p 0;
		if ($status) {
			return(-1);
		}
		$status = mgv_gpitrig -p 1;
		if ($status) {
			return(-1);
		}
        }

        echo; echo; echo;
        echo "Please select the TSG422 switch on the IDE switch box"
        echo "Press <Space> when ready"
        $status = mgv_waitforspace -s 36000
        if ($status) {
                 echo ""
                 echo "Test timed out after waiting an hour!"
                 return(-1)
        }

############### Initialize & Exit
	echo ""
	echo "=====Initialize & Exit"
	$status = mgv_init;
	if ($status) {
		return($status);
	}
	echo ""
	echo "Impact Video IDE Test Suite Completed"
	unix
}

#END of Galileo1.5 diagnostics


$status=0
$failed = 0;



#
# Start of ICO diags
#

ico_menu {
echo "///////////////////////////////////////////////////////////////////////////"
    version;
echo ""
echo "                       MCO DEBUG TEST OPTIONS "
echo "                       -----------------------"
echo "Command      Description"
echo ""
echo "gioslot      Find MGRAS boardset and set mgbase to point to last MGRAS boardset"
echo "mg_setboard  mg_setboard GIOslot  Set mgbase to MGRAS bd in GIO slot "
echo ""
echo "mco_put      mco_put CRSindex VALUE"
echo "mco_get      mco_get CRSindex"
echo "mco_probe    Probe for MCO board.  mco_probe -d runs extra verification"
echo "mco_initfpga     Load fpga ucode.  mco_initfpga -f bootp()machine:/path/file"
echo "mcoDACmenu	ICO DAC test menu"
echo "mcoVC2menu	ICO VC2 test menu"
echo "mcoPPmenu		ICO Pixel Path tests menu"
echo ""
echo "mcoinit     Set mgbase, probe for MCO, and load fpga ucode."
echo "mco_indextest   Write, Read, and compare 0-0xff to MCO Index Register"
echo "mco_setvof  Load ICO video format 	mco_setvof -g ICO_format "
echo "		ICO_formats: "
echo "			4test_800x600_60, mini_800x600_60, mini_640x480_60"
echo ""
echo "testpat[1-8]	Draws specified test pattern into Impact frame buffer"
echo "icoscreen   Run all ICO verification programs"
echo ""
echo "///////////////////////////////////////////////////////////////////////////"
}

mcoDACmenu {
echo "mco_indextest    Write, Read, and compare 0-0xff to MCO Index Register"
echo "                       -----------------------"
echo "                    7162 DAC Register Tests"
echo "                       -----------------------"
echo "mco_7162probe    Basic Initialization of 7162 DAC.  mco_7162 A|B"
echo "mco_7162addrreg  7162 DAC Address Reg Test.         mco_7162addrreg A|B"
echo "mco_7162ctrlreg  7162 DAC Control Reg Tests.        mco_7162ctrlreg A|B"
echo "mco_7162modereg  7162 DAC Mode Reg Test.            mco_7162modereg A|B"
echo "                       -----------------------"
echo "                    7162 DAC Color Palette Tests"
echo "                       -----------------------"
echo "mco_7162clrpaletteaddrUniq   mco_7162clrpaletteaddrUniq A|B"
echo "mco_7162clrpalettewalkbit    mco_7162clrpalettewalkbit A|B"
echo "mco_7162clrpalettepatrn      mco_7162clrpalettepatrn A|B"
echo "                       -----------------------"
echo "                    473 DAC Register Tests"
echo "                       -----------------------"
echo "mco_473probe    Basic Initialization of 473 DAC.  mco_473 A|B"
echo "                       -----------------------"
echo "                    473 DAC Color Palette Tests"
echo "                       -----------------------"
echo "mco_473clrpaletteaddrUniq   mco_473clrpaletteaddrUniq A|B"
echo "mco_473clrpalettewalkbit    mco_473clrpalettewalkbit A|B"
echo "mco_473clrpalettepatrn      mco_473clrpalettepatrn A|B"
echo "                       -----------------------"
echo "                    473 DAC Overlay Register Tests"
echo "                       -----------------------"
echo "mco_473overlayaddrUniq   mco_473overlayaddrUniq A|B"
echo "mco_473overlaywalkbit    mco_473overlaywalkbit A|B"
echo "mco_473overlaypatrn      mco_473overlaypatrn A|B"
}

mcoVC2menu {
echo ""
echo "                       -----------------------"
echo "                    ICO VC2 Tests"
echo "                       -----------------------"
echo "mco_VC2probe   	   MCO VC2 probe and initialization"
echo "mco_vc2internalreg   MCO VC2 Internal Register Tests"
echo "mco_vc2addrsbus	   MCO VC2 Address Bus Tests"
echo "mco_vc2databus	   MCO VC2 Data Bus Tests"
echo "mco_vc2addrsuniq	   MCO VC2 Address Uniqueness Tests"
echo "mco_vc2patrn	   MCO VC2 Address SRAM Pattern Tests"
echo ""
}

mcoPPmenu {
echo ""
echo "                       -----------------------"
echo "                    ICO Input/Output Swizzle (Pixel Path) Tests"
echo "                       -----------------------"
echo ""
echo "mco_chkcmpbittest	  Test MCO Check Compare bits"
echo "mco_oschksumtest	  mco_oschksumtest vga pattern_no"
echo "mco_daccrctest	  mco_daccrctest A|B pattern_no"
echo ""
echo "oschecksum	  Run mco_oschksumtest with all patterns"
echo "DACcrc		  Run mco_daccrctest with all patterns on both 7162 DACs"
}

gioslot {
	$tmp = mg_setboard 0;
	if ($tmp) {
		echo "Found boards in slot 0"
	}
	else {
		$tmp = mg_setboard 1;
		if ($tmp) {
			echo "Found boards in slot 1"
		}
		else {
			echo "No boards found in slot 0 or slot 1"
		}
	}
}

enabdisp {
mg_pokexmap -r XMAP_DIB_CTRL0 -d 0x100
}


delay {
	ide_delay -s 2;
}

allsetup {
	$failed =0;
	mg_gfxreset;
	delay;
        gioslot
	delay;
	mg_set_0ge;
	delay;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	delay;
	resetcons
	if (!mg_gfxconsole) {
		$status = mg_sync_repp
		if ($status) {
			$failed = 1;
			return (-1);
		}
        	$status = mg_sync_pprdram
		if ($status) {
			$failed = 1;
			return (-1);
		}
        	mg_xmapinit
		$status = mg_rdram_ccsearch
		if ($status) {
			$failed = 1;
			return (-1);
		}
        	mg_initppregs
		enabdisp	
		mg0_clear_color
	}
	$solid = mg_issolid;
}

mcoinit {
	allsetup;
	report=4;
	$tmp = mco_probe -d;
	if ($tmp) {
		mco_initfpga -f bootp()mco_a0c0f0.rbf;
	}
}

vline {
	mg0_line -x $1 1023 0 100 100 100 100 -n $1 0 0 100 100 100 100
}

hline {
	mg0_line -x 1279 $1 0 100 100 100 100 -n 0 $1 0 100 100 100 100
}

vline1 {
	mg0_line -x $1 1200 0 100 100 100 100 -n $1 0 0 100 100 100 100
}

hline1 {
	mg0_line -x 1600 $1 0 100 100 100 100 -n 0 $1 0 100 100 100 100
}

#############################################################################
# mg0_clear_color -r[red] -g[green] -b[blue] -a[alpha] -f[buffer]
# 	-t [optional xstart] [optional ystart] 
#	-d [optional xend] [optional yend]
#	-s [optional rss num]
#
# Color params (red, green, blue, alpha) specified are on a 0-100 integer
# scale and will be scaled to be floats ranging from 0-1.0  
# We do the scaling internally to the function since ide does not have 
# atof support and it's easier to cast than to add atof support.
#############################################################################

#############################################################################
# UI to the mg0_FillTriangle routine 
#
# Expects the following:
#	-x (max point) x-coord y-coord z-coord red green blue alpha
#	-d (mid point) x-coord y-coord z-coord red green blue alpha
#	-n (min point) x-coord y-coord z-coord red green blue alpha
#	-c (constant color) red geen blue alpha.
#		-c will ignore any other specified color. So if you use
#		-c you don't need to specify individual vertex colors.
#	colors are on a 0-100 int scale and will be converted to floats
#	ranging from 0-1.0
#	-r [optional rss number]
#	-o [optional max color]
#
#############################################################################

#############################################################################
# UI to the _mg0_line routine
#                                                                         *
#  Expects the following:                                                 *
#       -x (max point) x-coord y-coord z-coord red green blue alpha       *
#       -n (min point) x-coord y-coord z-coord red green blue alpha       *
#       colors are on a 0-100 int scale and will be converted to floats   *
#       ranging from 0-1.0                                                *
#       -s (stipple enable)                                               *
#       -l [line stipple pattern]                                         *
#       -a (anti-alias enable)                                            *
#       -X (X-line enable)                                                *
#       -r [optional rss number]                                          *
#       -t (optional texture enable) - but no tram data supplied right now*
#       -c [optional maximum color value - default is 100]                *
#                                                                         *
#  Textured lines not yet supported via this routine(see the texture tests*
#  in mgras_re4func.c)                                                    *
#                                                                         *
#  Lines with different colors don't seem to work right -- it's probably  *
#  in my port. Leave it for now. Single colors work fine.                 *
#   
#############################################################################

#############################################################################
# UI to the mg0_rect routine
#
#  Draws a rectangle and can read the values back via pio
# 
#  Usage: -t [xstart ystart] 
#	  -d [xend yend] 
#	  -r[red] -g[green] -b[blue]
#	  -c (do the compare) 
#	  -x (draw a textured rect with data already in the tram -- 
#	      decal mode for now)
#	  -m [optional mode, default = 1 (rgb12), 0=rgba8888)
# 
#############################################################################

#############################################################################
# UI to the mg0_point routine
#
# mg0_point
#       -x [x-coord]                                                       *
#       -y [y-coord]                                                       *
#       -r [red]                                                           *
#       -g [green]                                                         *
#       -b [blue]                                                          *
#       -a [alpha]                                                         *
#       -t (enables anti-aliased points)                                   *
#       -X (enables X-points)                                              *
#       -i (enables color index)                                           *
#       -c [color index]                                                   *
#       -s [optional rss number]                                           *
#       -o [optional max color]                                            *
#       -d (optional dither off, default is on)                            *
# 
#############################################################################


scene1 {
	mg0_clear_color
	mg0_tri -x 0 1000 0 100 0 0 0 -d 1200 500 0 0 100 0 0 -n 0 0 0 0 0 100 0
	mg0_tri -x 100 200 0 99 6 8 2 -d 150 100 0 50 96 9 1 -n 0 20 0 0 6 98 7
	mg0_line -x 1000 1000 0 100 100 0 0 -n 0 0 0 100 100 0 0
	mg0_line -x 0 1000 0 100 0 100 0 -n 1000 0 0 100 100 0 0
	mg0_clear_color -t 500 500 -d 600 600
	mg0_point -x 551 -y 551 -r 100 -g100 -b100 -a100
	mg0_rect -t 900 100 -d 1000 200 -r100 -g 20 -b 100
}

testpat1 {
	echo "**********************************"
	echo "ICO Test Pattern (Green 50%)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -g 128 -d 1600 1200
}

testpat2 {
	echo "**********************************"
	echo "ICO Test Pattern (Solid Black)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -r 0 -g 0 -b 0 -d 1600 1200
}

testpat3 {
	echo "**********************************"
	echo "ICO Test Pattern (Solid Red 0xff)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -r 255 -d 1600 1200
}

testpat4 {
	echo "**********************************"
	echo "ICO Test Pattern (Solid Green 0xff )"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -g 255 -d 1600 1200
}

testpat5 {
	echo "**********************************"
	echo "ICO Test Pattern (Solid Blue 0xFF)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -b 255 -d 1600 1200
}

testpat6 {
	echo "**********************************"
	echo "ICO Test Pattern (Solid White)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -r 255 -g 255 -b 255 -a 0 -d 1600 1200
}

testpat7 {
	echo "**********************************"
	echo "ICO Test Pattern (R=0xAA, G=0xAA, B=0xAA)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -r 170 -g 170 -b 170 -a 0 -d 1600 1200
}

testpat8 {
	echo "**********************************"
	echo "ICO Test Pattern (R=0x55, G=0x55, B=0x55)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -r 85 -g 85 -b 85 -a 0 -d 1600 1200
}

oschecksum {
#	 Set VOF on ICO board
	$tmp = mco_setvof 4test_800x600_60
	if ($tmp = 0) {
	    echo "ERROR -- couldn't load MCO format \\"4test_800x600_60\\" "
	    $mcoerrs = $mcoerrs + 1;
	    wait;
	}
	delay

#	 Draw the test pattern
# 	testpat1
# 	delay
# 
# 	# Read and compare OS chksums
#	$tmp = mco_oschksumtest vga 1
#	if ($tmp != 0) {
# 	    echo "Error in MCO Output Swizzle Checksum test (Red ramp)"
# 	    $mcoerrs = $mcoerrs + 1;
# 	    wait;
#	}
#	delay

#	Draw the test pattern
	testpat2
	delay

#	Read and compare OS chksums
	$tmp = mco_oschksumtest vga 2
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (Solid Black)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat3
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 3
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (Solid Red)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat4
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 4
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (Solid Green)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat5
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 5
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (Solid Blue)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat6
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 6
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (Solid White)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat7
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 7
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (RGB=0xAAAAAA)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat8
	delay

	# Read and compare OS chksums
	$tmp = mco_oschksumtest vga 8
        if ($tmp != 0) {
	    echo "Error in MCO Output Swizzle Checksum test (RGB=0x555555)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	if ($mcoerrs) {
		$icofailed = 1;
	}
}

DACcrc {
	# Set VOF on ICO board
	$tmp = mco_setvof -g 4test_800x600_60
        if ($tmp != 0) {
	    echo "ERROR -- couldn't load MCO format \\"4test_800x600_60\\" "
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
#	testpat1
#	delay

#	# Read and compare 7162 CRCs
#	$tmp = mco_daccrctest A 1
#	if ($tmp != 0) {
#	    echo "Error in MCO 7162A DAC Checksum test (50% Green)"
#	    $mcoerrs = $mcoerrs + 1;
#	    wait;
#	}

	# Read and compare 7162 CRCs
#	$tmp = mco_daccrctest B 1
#	if ($tmp != 0) {
#	    echo "Error in MCO 7162B DAC Checksum test (50% Green)"
#	    $mcoerrs = $mcoerrs + 1;
#	    wait;
#	}
#	delay

	# Draw the test pattern
	testpat2
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 2
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (Solid Black)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 2
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (Solid Black)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat3
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 3
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (Solid Red)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 3
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (Solid Red)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat4
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 4
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (Solid Green)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 4
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (Solid Green)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat5
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 5
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (Solid Blue)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 5
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (Solid Blue)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat6
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 6
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (Solid White)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 6
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (Solid White)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat7
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 7
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (R=0x2AA, G=0x2AA, B=0x2AA)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 7
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (R=0x2AA, G=0x2AA, B=0x2AA)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	# Draw the test pattern
	testpat8
	delay

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest A 8
        if ($tmp != 0) {
	    echo "Error in MCO 7162A DAC Checksum test (R=0x155, G=0x155, B=0x155)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }

	# Read and compare 7162 CRCs
	$tmp = mco_daccrctest B 8
        if ($tmp != 0) {
	    echo "Error in MCO 7162B DAC Checksum test (R=0x155, G=0x155, B=0x155)"
	    $mcoerrs = $mcoerrs + 1;
	    wait;
        }
	delay

	if ($mcoerrs) {
		$icofailed = 1;
	}
}

icoscreen {
	$mcoerrs = 0;
	$tmp = mg_setboard 0;
	if ($tmp) {
		echo "Found boards in slot 0"
	}
	else {
		$tmp = mg_setboard 1;
	        if ($tmp) {
	                echo "Found boards in slot 1"
	        }
	        else {
	                echo "No boards found in slot 0 or slot 1"
	        }
	}
	echo "Setting up MardiGras Frame buffer"
	allsetup
	mco_setvof mini_800x600_60
	mg0_clear_color -d 1600 1200 -r 100 -g 0 -b 0 -a 0

	$tmp = mco_probe -d ;
	if ($tmp = 0) {
		echo "Error detected in MCO probe test -- extended version"
		$mcoerrs = $mcoerrs + 1;
		wait;
	}
	$tmp = mco_initfpga -f bootp()mco_a0c0f0.rbf

	if ($tmp) {
		echo "Error detected in MCO FPGA initialization"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162probe A;
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A probe"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162probe B;
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B probe"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473probe A;
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A probe"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473probe B;
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B probe"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	# Check ADV7162 DAC A registers
	echo "******************************"
	echo "Check ADV7162 DAC A registers"
	echo "******************************"
	$tmp = mco_7162addrreg A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Address Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162ctrlreg A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Control Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162modereg A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Mode Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

		
	# Check ADV7162 DAC A Color Palette RAM
	echo "Check ADV7162 DAC A Color Palette RAM"
	$tmp = mco_7162clrpaletteaddrUniq A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162clrpalettewalkbit A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162clrpalettepatrn A
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}


	# Check ADV7162 DAC B registers
	echo "******************************"
	echo "Check ADV7162 DAC B registers"
	echo "******************************"
	$tmp = mco_7162addrreg B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Address Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162ctrlreg B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Control Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162modereg B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Mode Reg Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

		
	# Check ADV7162 DAC B Color Palette RAM
	echo "Check ADV7162 DAC B Color Palette RAM"
	$tmp = mco_7162clrpaletteaddrUniq B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162clrpalettewalkbit B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_7162clrpalettepatrn B
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	# Check ADV473 DAC A Color Palette RAM
	echo "******************************"
	echo "Check ADV473 DAC A Color Palette RAM"
	echo "******************************"
	$tmp = mco_473clrpaletteaddrUniq A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473clrpalettewalkbit A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473clrpalettepatrn A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "******************************"
	echo "Check ADV473 DAC A Overlay Register"
	echo "******************************"
	$tmp = mco_473overlayaddrUniq A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473overlaywalkbit A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473overlaypatrn A
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	# Check ADV473 DAC B Color Palette RAM
	echo "******************************"
	echo "Check ADV473 DAC B Color Palette RAM"
	echo "******************************"
	$tmp = mco_473clrpaletteaddrUniq B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473clrpalettewalkbit B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473clrpalettepatrn B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Color Palette RAM"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "******************************"
	echo "Check ADV473 DAC B Overlay Register"
	echo "******************************"
	$tmp = mco_473overlayaddrUniq B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473overlaywalkbit B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_473overlaypatrn B
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B Overlay Register"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "******************************"
	echo "Probe MCO VC2"
	echo "******************************"
	$tmp = mco_VC2probe
	if ($tmp) {
		echo "Error detected probing  MCO VC2"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "******************************"
	echo "MCO VC2 Internal Registers Test"
	echo "******************************"
	$tmp = mco_vc2internalreg
	if ($tmp) {
		echo "Error detected in MCO VC2 Internal Register Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "******************************"
	echo "MCO VC2 SRAM Tests"
	echo "******************************"
	$tmp = mco_vc2addrsbus
	if ($tmp) {
		echo "Error detected in MCO VC2 SRAM Address Bus Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_vc2databus
	if ($tmp) {
		echo "Error detected in MCO VC2 SRAM Data Bus Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_vc2addrsuniq
	if ($tmp) {
		echo "Error detected in MCO VC2 SRAM Address Uniqueness Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	$tmp = mco_vc2patrn
	if ($tmp) {
		echo "Error detected in MCO VC2 SRAM Pattern Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "*******************************************************"
	echo "MCO Input Swizzle/Output Swizzle Check Compare Bit Test"
	echo "*******************************************************"
	echo
	mco_initfpga -f bootp()fpgas.rbf
	$tmp = mco_chkcmpbittest;
	if ($tmp) {
		echo "Error detected in MCO VC2 IS/OS Check Compare Bit Test"
		$mcoerrs = $mcoerrs +1;
		wait;
	}

	echo "*******************************************************"
	echo "MCO Input Swizzle/Output Swizzle Checksum Test"
	echo "*******************************************************"
	echo
	oschecksum

	echo "*******************************************************"
	echo "MCO 7162 DAC CRC Test"
	echo "*******************************************************"
	echo
	DACcrc

	if ($mcoerrs) {
		$icofailed = 1;
	}

	if ($icofailed == 0) {
    		unix
	}
}

menu
