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

$mcotest=0;
$mcoerrs = 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 "c2main_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 "kva       Galileo video board diagnostics with automatic voltage change"
# echo "kvaloop   Loop Galileo board diagnostics 3 times with voltage change"
echo ""
echo "                     TECHNICIAN BENCH OPTIONS"
echo "                     ------------------------"
# echo "gfx       XL/XZ/Extreme diagnostics with no voltage change"
# echo "a2test    A2 audio diagnostics with no voltage change"
# echo "kv        Galileo video board diagnostics with no voltage change"
# echo "kvloop    Loop Galileo board diagnostics 3 times with no voltage change"
echo "mgv_menu  Galileo 1.5 menu"
echo "cosmo2_menu  Cosmo2.0 menu"
echo "mco_menu  MCO menu"
echo ""
echo "///////////////////////////////////////////////////////////////////////////"
}

unix {
	echo "<<<< About to to boot UNIX......>>>>"
	setenv AutoLoad yes
#XXX For now, because of a problem with UNIX we don't boot unix
#XXX This is temporary... should go away pretty soon
#	setenv AutoLoad No
	unsetenv diagmode
#	unsetenv idebinary
	reset;
}


#START of Galileo1.5 diagnostics
mgv_menu {
echo ""
echo "=================== IMPACT VIDEO IDE COMMANDS ======================"
echo "mgv_probe           mgv_set_br"
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;
	echo ""
	echo "===== Probing for Galileo15 board"
	echo ""
	$port = mgv_probe;
	if (!$port) {
		$failed = 1;
		return($status);
	}
	$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 for VGI 1"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

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

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

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

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

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

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

        $status = mgv_vgiregwalk -v 2
        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 for VGI 1"
	$status = mgv_init;
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

	$status = mgv_vgidma -t 1 -v 6 -y 0x40404040  -z 50 -a 1; 
	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 -a 1; 
	if ($status) {
		$failed = 1;
		return($status);
	}

	ide_delay -s 2;

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

	ide_delay -s 2;

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

	ide_delay -s 2;

	$status = mgv_vgidma -c 2 -v 2 -a 1; 
	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 15
	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 15
	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 15
	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 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 15
	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 15
        if ($status) {
                 echo ""
                 echo "Test timed out after waiting an hour!"
                 return(-1)
        }

        echo; echo; 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 & 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

##### BEGIN COSMO2 scripts #########

c2_delay {
	ide_delay -s 2;
}

c2_setpiomode  {
    $status = cos2_setpiomode ;
    if ($status == 0) {
        echo "  PIO Mode Failed "
        $failed = 1;
        return  ;
    }
    return (1);
}

c2_unsetpiomode  {
        $status = cos2_unsetpio ;
        if ($status == 0) {
                echo "  Diable PIO Mode Failed "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_reset_chips {
    $failed = 0
Reset_050_016_FBC_CPC
Reset_SCALER_UPC
}

flush {

c2_flush -c 0;
c2_flush -c 1;
c2_flush -c 2;
c2_flush -c 3;
}

c2_reseterror {
    $failed = 0
    cos2_set_var -e 0;
}

c2_cbar_patrn {
    c2_resetchannel

    echo "   CBAR Testing in progress "
    $status = cos2_CbarPatrn  ;
    if ($status == 0) {
        echo "   CBAR Test Failed "
        $failed = 1;
        return ;
        }

            echo "   CBAR ADDR UNIQUE "
        $status = cos2_CbarAddrUniq  ;
        if ($status == 0) {
            echo "   CBAR ADDR UNIQUE "
            $failed = 1;
            return ;
        }
    return (1);

}

c2_cgi1_on {
cgi1put -o 8  -v 0x2
}
c2_cgi1_off {
cgi1put -o 8  -v 0x0
}

c2_cgi1_rev {
    $status = cos2_getrev ;
    if ($status == 0) {
        echo "  Read Revision Failed "
            $failed = 1;
            return  ;
        }
    return (1);
}

c2_reset {
    $failed = 0
    cos2_set_var -e 0;
#$status = cos2_init;

    c2_probe
    if ($failed == 1) return ;
    c2_cgi1_rev ;
    if ($failed == 1) return ;
    $status = cos2_BrdRst;
    if ($status == 0) {
        echo "  cos2_BoardReset Failed "
                $failed = 1;
                return  ;
        }
	c2bridge;
	cos2_16mhz;
    return (1);
}

c2_cgi1tests {
    echo "  cgi1tests "

    $status = cos2_databustest ;
    if ($status == 0) {
        echo "cos2_Cgi1DataBusTest Failed "
                $failed = 1;
                return ;
        }

    $status = cos2_cgi1_patrn ;
    if ($status == 0) {
        echo "  cos2_Cgi1PatrnTest Failed "
                $failed = 1;
                return ;
        }

    $status = cos2_cgi1_uniq ;
    if ($status == 0) {
        echo "  cos2_Cgi1AddrUniq Failed "
                $failed = 1;
                return ;
        }
    return (1);

}

c2_fifoflags1 {
        echo "    DataFifo Flags in channel 1        "
        c2_resetchannel;
        $status = cos2_fifoflagspatrn  -c 0 ;
        if ($status == 0) {
                echo "   cos2_fifoflagspatrn Failed in chnl 0"
                $failed = 1;
                return ;
        }

        $status = cos2_fifoflagaddruniq -c 0;
        if ($status == 0) {
                echo "   cos2_fifoflagaddruniq Failed in chnl 0"
                $failed = 1;
                return ;
        }
}

c2_fifoflags2 {
        echo "    DataFifo Flags in channel 2        "
        $status = cos2_fifoflagspatrn  -c 1 ;
        if ($status == 0) {
                echo "   cos2_fifoflagspatrn Failed in chnl 1"
                $failed = 1;
                return ;
        }

        $status = cos2_fifoflagaddruniq -c 1;
        if ($status == 0) {
                echo "   cos2_fifoflagaddruniq Failed in chnl 1"
                $failed = 1;
                return ;
        }
}

c2_fifoflags3 {

        echo "    DataFifo Flags in channel 3        "
        $status = cos2_fifoflagspatrn  -c 2 ;
        if ($status == 0) {
                echo "   cos2_fifoflagspatrn Failed in chnl 2"
                $failed = 1;
                return ;
        }
        $status = cos2_fifoflagaddruniq -c 2;
        if ($status == 0) {
                echo "   cos2_fifoflagaddruniq Failed in chanl 2"
                $failed = 1;
                return ;
        }
}

c2_fifoflags4 {
        echo "    DataFifo Flags in channel 4        "
        $status = cos2_fifoflagspatrn  -c 3 ;
        if ($status == 0) {
                echo "   cos2_fifoflagspatrn Failed in chnl 3"
                $failed = 1;
                return ;
        }

        $status = cos2_fifoflagaddruniq -c 3;
        if ($status == 0) {
                echo "   cos2_fifoflagaddruniq Failed in chanl 3"
                $failed = 1;
                return ;
        }
}

c2_mcuflags {

        $status = cos2_mcufifoflagpatrn ;
        if ($status == 0) {
                echo "   cos2_mcufifoflagpatrn Failed "
                $failed = 1;
                return ;
        }

        $status = cos2_mcufifoflagaddruniq ;
        if ($status == 0) {
                echo "   cos2_mcufifoflagaddruniq Failed "
                $failed = 1;
                return ;
        }

        $status = cos2_mcufifolpb ;
        if ($status == 0) {
                echo "   cos2_mcufifolpb Failed "
                $failed = 1;
                return ;
        }

    c2_reset ;
        if ($failed == 1) return ;
        echo "   Data Fifo Test Passed        "
    return (1);

}

c2_fifoflags {
    c2_fifoflags1
    if ($failed )  return ;
    c2_fifoflags2
    if ($failed )  return ;
    c2_fifoflags3
    if ($failed )  return ;
    c2_fifoflags4
    if ($failed )  return ;
    c2_mcuflags
    if ($failed )  return ;
}

# DMA tests
c2_dma_test1 {

    c2_setwm ;

c2_resetchannel
repeat 3  c2_delay ;
echo " testing dma channel 1 to 2"
    $status = cos2_dma01
        if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_dma_test2 {
c2_setwm;

c2_resetchannel
repeat 3  c2_delay ;
echo " testing dma channel 2 to 1"
    $status = cos2_dma10
        if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}


c2_dma_test3 {
c2_setwm

c2_resetchannel
repeat 3  c2_delay ;
echo " testing dma channel 3 to 4"
    $status = cos2_dma23
        if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_dma_test4 {
c2_setwm
c2_resetchannel
repeat 3  c2_delay ;
echo " testing dma channel 4 to 3"
    $status = cos2_dma32
        if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_dma_test {
c2_dma_test1
if ($failed )  return ;
c2_dma_test2
if ($failed )  return ;
c2_dma_test3
if ($failed )  return ;
c2_dma_test4
if ($failed )  return ;
}

c2_fifo_lpb1 {
        c2_resetchannel;
        $status = cos2_fifo_lb -c 0 ;
        if ($status == 0) {
            echo " fifo loop back from 1 to 2 Failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_lpb2 {
        $status = cos2_fifo_lb -c 1 ;
        if ($status == 0) {
            echo " fifo loop back from 2 to 1 Failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_lpb3 {
        $status = cos2_fifo_lb -c 2 ;
        if ($status == 0) {
            echo " fifo loop back from 3 to 4 Failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_lpb4 {
        $status = cos2_fifo_lb -c 3 ;
        if ($status == 0) {
            echo " fifo loop back from 4 to 3 Failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_uniq1 {
        echo " fifo uniqueness test "
        c2_resetchannel;
        $status = cos2_fifo_uniqueness -c 0 ;
        if ($status == 0) {
            echo " fifo uniqueness in chnl 1 failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_uniq2 {
        $status = cos2_fifo_uniqueness -c 1 ;
        if ($status == 0) {
            echo " fifo uniqueness in chnl 2 failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fifo_uniq3 {

        $status = cos2_fifo_uniqueness -c 2;
        if ($status == 0) {
            echo " fifo uniqueness in chnl 3 failed "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_fifo_uniq4 {
        $status = cos2_fifo_uniqueness -c 3;
        if ($status == 0) {
            echo " fifo uniqueness in chnl 4 failed "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_fifo_uniq {
c2_fifo_uniq1
if ($failed )  return ;
c2_fifo_uniq2
if ($failed )  return ;
c2_fifo_uniq3
if ($failed )  return ;
c2_fifo_uniq4
if ($failed )  return ;
}

c2_tpsl1 {
        c2_resetchannel;

        echo "    Table Pass Testing for channel 1....    "
        $status = c2_tblslave -c 0;
        if ($status == 0) {
                echo "  cos2_tblpass Failed "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_tpsl2 {
        c2_resetchannel;

        echo "    Table Pass Testing for channel 2....    "
        $status = c2_tblslave -c 1;
        if ($status == 0) {
                echo "  cos2_tblpass Failed "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_tp1 {
        c2_resetchannel;

        echo "    Table Pass Testing for channel 1....      "
        $status = c2_tblpass -c 0;
        if ($status == 0) {
                echo "   cos2_tblpass Failed "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_tp2 {
        c2_resetchannel;
        echo "    Table Pass Testing for channel 2....     "
        $status = c2_tblpass -c 1;
        if ($status == 0) {
                echo "   cos2_tblpass Failed "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_mug1 {
    c2_resetchannel;
    c2_setpiomode ;
    $status = cos2_mcu2upc2fifo -c 0 -v 0xe0;
        if ($status == 0) {
                echo " mcu 2 cpc 2 fifo of video channel 1 Failed"
               $failed = 1;
                return ;
        }
}

c2_mug2 {
    c2_resetchannel;
    c2_setpiomode ;
    $status = cos2_mcu2upc2fifo -c 1 -v 0xe1;
        if ($status == 0) {
                echo "  mcu 2 upc 2 fifo of video channel 1 Failed=="
                $failed = 1;
                return ;
        }

}

c2_mug3 {
    c2_resetchannel;
    c2_setpiomode ;
    $status = cos2_mcu2upc2fifo -c 2 -v 0xe0;
        if ($status == 0) {
                echo "  mcu 2 cpc 2 fifo of video channel 2 Failed"
                $failed = 1;
                return ;
        }
}

c2_mug4 {
    c2_resetchannel;
    c2_setpiomode ;
    $status = cos2_mcu2upc2fifo -c 3 -v 0xe1;
        if ($status == 0) {
                echo " mcu 2 upc 2 fifo of video channel 2 Failed"
                $failed = 1;
                return ;
        }
}

c2_mug {
c2_mug1
if ($failed )  return ;
c2_mug2
if ($failed )  return ;
c2_mug3
if ($failed )  return ;
c2_mug4
if ($failed )  return ;
}

c2_fbc_ch1 {
        echo "    FBC patrn Testing....        "
        c2_resetchannel;
            $status = cos2_fbc_patrn1  ;
        if ($status == 0) {
            echo "   FBC Patrn Failed....        "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fbc_ch2 {
        echo "    FBC patrn Testing....        "
        c2_resetchannel;
        $status = cos2_fbc_patrn2 ;
        if ($status == 0) {
            echo "   FBC Patrn Failed....        "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_fbc_ch {
c2_fbc_ch1
if ($failed )  return ;

c2_fbc_ch2
if ($failed )  return ;

}

c2_z050_ch1 {
        c2_resetchannel
        echo "    Z050 Patrn Testing....        "
        $status = cos2_z050Patrn 1 ;
        if ($status == 0) {
                echo "   Z050 Patrn Failed....        "
        $failed = 1;
        return ;
    }

        echo "    Z050 Walking Testing....        "
        $status = cos2_z050Walk 1;
        if ($status == 0) {
                echo "   Z050 walk Failed....        "
                $failed = 1;
                return ;
        }
        echo "    Z050 Address Unique Testing....        "
        $status = cos2_z050AddrUniq1;
        if ($status == 0) {
                echo "          Z050 Address Unique Failed....           "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_z050_ch2 {
        c2_resetchannel
        echo "    Z050 Patrn Testing....        "
        $status = cos2_z050Patrn 2;
        if ($status == 0) {
                echo "   Z050 Patrn Failed....        "
        $failed = 1;
        return ;
    }

        echo "    Z050 Walking Testing....        "
        $status = cos2_z050Walk 2;
        if ($status == 0) {
                echo "   Z050 walk Failed....        "
                $failed = 1;
                return ;
        }
        echo "    Z050 Address Unique Testing....        "
        $status = cos2_z050AddrUniq2;
        if ($status == 0) {
                echo "   Z050 Address Unique Failed....        "
                $failed = 1;
                return ;
        }
    return (1);
}

c2_scaler_ch1 {
        c2_resetchannel;
        echo "    scaler patrn video channel 1"
         $status = cos2_gvs_patrn0  ;
        if ($status == 0) {
            echo "   scaler pattern test video channel 1 failed "
            $failed = 1;
            return ;
        }
    return (1);
}

c2_scaler_ch2 {

        echo "    scaler patrn test in video channel 2"
         $status = cos2_gvs_patrn1  ;
        if ($status == 0) {
            echo "   scaler pattern test video channel 2 failed "
            $failed = 1;
            return ;
        }
    return (1);

}

c2_scaler_ch {
c2_scaler_ch1
  if ($failed )  return ;
c2_scaler_ch2
  if ($failed )  return ;
}

c2_upc_ch1 {
        c2_resetchannel;
        $status = cos2_upc_patrn1 ;
        if ($status == 0) {
                echo "= UPC  pattern Test Failed in video channel 1   "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_upc_ch2 {
        c2_resetchannel;
        $status = cos2_upc_patrn2 ;
        if ($status == 0) {
                echo "=   UPC  Patrn Test Failed video channel 2        "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_upc_ch {
c2_upc_ch1
if ($failed )  return ;
c2_upc_ch2
if ($failed )  return ;
}

c2_comp1 {
    echo " compression test in channel 1 in progress"
        c2_resetchannel ;
        $count = 0
        while ($count < 16) {
        $status = cos2_patcomp -c 0 -m 0 -a 1 -v 0
        if ($status == 0) {
                $failed = 1 ;
                return ;
        }
        $count = $count + 1
    }

    return (1);
}

c2_compsl1 {
    echo " compression test in slave mode in channel 1 in progress"
        c2_resetchannel ;
        c2_resetchannel ;
        $count = 0
        while ($count < 16) {
        $status = cos2_patcomp_slave -c 0 -m 0 -a 1 -v 0
        if ($status == 0) {
            echo " compression in slave mode failed in video channel 1"
                $failed = 1 ;
                return ;
        }
        $count = $count + 1
    }

    return (1);
}

c2_comp2 {
    echo " compression test in channel 2 in progress"
        c2_resetchannel;
        $count = 0
        while ($count < 16) {
        $status = cos2_patcomp -c 1 -m 0 -a 1 -v 0
        if ($status == 0) {
        echo " compression test failed in video channel 2"
                $failed = 1;
                return ;
        }
        $count = $count + 1
    }
    return (1);
}

c2_compsl2 {
    echo " compression test in slave mode in channel 2 in progress"
        c2_resetchannel;
        $count = 0
        while ($count < 16) {
        $status = cos2_patcomp_slave -c 1 -m 0 -a 1 -v 0
        if ($status == 0) {
            echo " compression test in video channel 2 failed in slave mode "
                $failed = 1;
                return ;
        }
        $count = $count + 1
    }
    return (1);
}

c2_comp {
c2_comp1
if ($failed )  return ;
c2_comp2
if ($failed )  return ;
}


c2_compsl {
c2_compsl1
if ($failed )  return ;
c2_compsl2
if ($failed )  return ;
}

tablepass_tests {
    c2_init
     c2_tp1
        if ($failed )  return ;
     c2_tp2
        if ($failed )  return ;
     c2_tpsl1
        if ($failed )  return ;
     c2_tpsl2
        if ($failed )  return ;
}

c2_fbc1_buf1 {
        c2_setwm ;
        echo "    fbc field buffer 1 test in video channel 1....        "
        c2_init
        $status = cos2_fbc_scaler_test -c 0 -s 1 -b 0;
        if ($status == 0) {
                    $failed = 1;
                    return;
        } else {
            echo "    fbc field buffer 1 test in video channel 1....passed"
        }
}

c2_fbc1_buf2 {
        c2_setwm ;
        echo "    fbc field buffer 2 test in video channel 1....        "
        c2_init
        $status = cos2_fbc_scaler_test -c 0 -s 1 -b 1;
        if ($status == 0) {
                    $failed = 1;
                    return;
        } else {
            echo "    fbc field buffer 2 test in video channel 1....passed"
        }
}
c2_fbc2_buf1 {
        c2_setwm ;

        echo "    fbc field buffer 1 test in video channel 2....        "
        c2_init
        $status = cos2_fbc_scaler_test -c 1 -s 1 -b 0;
         if ($status == 0) {
                    $failed = 1;
                    return;
        } else {
            echo "    fbc field buffer 1 test in video channel 2....passed"
        }
}

c2_fbc2_buf2 {
        c2_setwm ;
        echo "    fbc field buffer 2 test in video channel 2....        "
        c2_init
        $status = cos2_fbc_scaler_test -c 1 -s 1 -b 1;
         if ($status == 0) {
                    $failed = 1;
                    return;
        } else {
            echo "    fbc field buffer 2 test in video channel 2....passed"
        }
}

c2_scaler1 {
        c2_init ;
        c2_setwm ;
        echo "  scaler tests in buffer 1 video channel 1       "
        $status = cos2_fbc_scaler_test -c 0 -s 0 -b 0;
        if ($status == 0) {
                $failed = 1 ;
                return;
        }
}

c2_scaler2 {
        c2_init
        c2_setwm ;
        echo "scaler tests in buffer 1 video channel 2        "
        $status = cos2_fbc_scaler_test -c 1 -s 0 -b 0
        if ($status == 0) {
                $failed = 1 ;
                return;
        }
}

c2_decompsl1 {

      $status = cos2_decomp_slave -c 0 -m 0 -f  white.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
      $status = cos2_decomp_slave -c 0 -m 0 -f black.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_decompsl2 {

      $status = cos2_decomp_slave -c 1 -m 0 -f white.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
      $status = cos2_decomp_slave -c 1 -m 0 -f black.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_decompsl {
c2_decompsl1
if ($failed )  return ;
c2_decompsl2
if ($failed )  return ;
}

c2_decomp1 {

       $status = cos2_decomp -c 0 -m 0 -f white.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
       $status = cos2_decomp -c 0 -m 0 -f black.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_decomp2 {

        $status=cos2_decomp -c 1 -m 0 -f white.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
        $status=cos2_decomp -c 1 -m 0 -f black.jfif -s $local_server
                if ($status == 0) {
                $failed = 1;
                return ;
        }
    return (1);
}

c2_decomp {
c2_decomp1
if ($failed )  return ;
c2_decomp2
if ($failed )  return ;
}

c2_cc1_test {
    $status = cc1_revision
        if ($status == 0 ) {
            $failed
            return
        }
    $status = cc1_data_bus
        if ($status == 0) {
            $failed
            return ;
        }

    c2_ledoff
}

c2_z016_ch1 {
        c2_resetchannel;
        echo "    Z050 walk Testing in video channel 1        "
        $status = cos2_z016Walk ;
        if ($status == 0) {
                echo "=   Z016 Patrn Failed....        "
                $failed = 1;
                return ;
        }

        echo "    Z016 pattern Testing in video channel 1        "
        $status = cos2_z016Patrn1 ;
        if ($status == 0) {
                echo "=   Z016 walk Failed        "
                $failed = 1;
                return ;
        }

    return (1);
}

c2_z016_ch2 {
        c2_resetchannel;
        echo "    Z050 walk Testing in video channel 2        "
        $status = cos2_z016Walk ;
        if ($status == 0) {
                echo "=   Z016 walk Failed....        "
                $failed = 1;
                return ;
        }

        echo "    Z016 pattern Testing in video channel 2        "
        $status = cos2_z016Patrn2 ;
        if ($status == 0) {
                echo "=   Z016 pattern Failed....        "
                $failed = 1;
                return ;
        }

    return (1);
}


zoran_tests {
     c2_z050_ch1
    if ($failed )  return ;
     c2_z050_ch2
    if ($failed )  return ;
     c2_z016_ch1
    if ($failed )  return ;
     c2_z016_ch2
    if ($failed )  return ;
}

c2_gpsw {
    i2c_init;
    $status =  c2_i2cgpsw
    if ($status == 0) {
        $failed = 1;
        return ;
    }
}

c2_pad2gio1 {
    $status  = fbc2upc2fifo -c 0;
    if ($status == 0) {
        $failed = 1;
        return ;
    }
}

c2_pad2gio2 {
    $status  = fbc2upc2fifo -c 1;
    if ($status == 0) {
        $failed = 1;
        return ;
    }
}

c2_dummy_fbcbuffer_tests {
	report=0
	cos2_fbc_scaler_test -c 0 -s 1 -b 0 -w 1 -r 1
	cos2_fbc_scaler_test -c 0 -s 1 -b 1 -w 1 -r 1
	cos2_fbc_scaler_test -c 1 -s 1 -b 0 -w 1 -r 1
	cos2_fbc_scaler_test -c 1 -s 1 -b 1 -w 1 -r 1
	report=2
}

fbc_buffers_tests {
	c2_reset;
    c2_fbc1_buf1
        if ($failed )  return  ;
	c2_delay; c2_delay ;
    c2_fbc1_buf2
        if ($failed )  return  ;

	c2_delay; c2_delay ;
    c2_fbc2_buf1
        if ($failed )  return  ;

	c2_delay; c2_delay ;
    c2_fbc2_buf2
        if ($failed )  return  ;

}


scaler_tests {
    c2_setwm ;
    c2_scaler1
        if ($failed )  return ;
    c2_scaler2
        if ($failed )  return  ;
}

c2_video_tests {

    mg_pon_puts -s "VIDEO  Tests in progress....\n\r";
    c2_init
   repeat 3  c2_delay  ;
    c2_init
    c2_setwm ;
    echo " COSMO20 video test from channel 1 to 2 in progress:  "
    echo " This test takes 2-3 minutes:  "
    $status  = cosmo2_vid -c 0 -s 1 -g 0
    if ($status == 0) { $failed = 1; return ; }

    c2_init
    c2_setwm ;
    echo " COSMO20 video test from channel 2 to 1 in progress "
    echo " This test takes 2-3 minutes:  "
    $status  = cosmo2_vid -c 1 -s 1 -g 0
    if ($status == 0) { $failed = 1; return ; }

}

c2main_all {
    report=1
    c2_reset
    c2_ledoff
    c2_reseterror
    report=2

    c2_init
    c2_cgi1_rev
    if ($failed)  return ;
    c2_cgi1tests
    if ($failed)  return ;

        $status = cos2_mcufifoflagpatrn ;
        if ($status == 0) {
                echo "   cos2_mcufifoflagpatrn Failed "
                $failed = 1;
                return ;
        }

        $status = cos2_mcufifoflagaddruniq ;
        if ($status == 0) {
                echo "   cos2_mcufifoflagaddruniq Failed "
                $failed = 1;
                return ;
        }


    repeat 3  c2_delay   ;
    c2_upc_ch1
    if ($failed )  return ;
    c2_scaler_ch1
    if ($failed )  return ;

    report=1
    c2_reset
    c2_ledoff
    c2_reseterror
    report=2


    c2_mug1
        if ($failed )  return ;
    c2_mug2
        if ($failed )  return ;
    echo " fifo loop back tests "
    c2_fifo_lpb1
    if ($failed)  return ;
    c2_fifo_lpb2
    if ($failed)  return ;
     c2_z050_ch1
    if ($failed )  return ;
     c2_z016_ch1
    if ($failed )  return ;
     c2_cbar_patrn
    if ($failed )  return ;
     c2_fbc_ch1
    if ($failed )  return ;
    c2_init
    c2_pad2gio1
    if ($failed )  return ;
    c2_pad2gio2
    if ($failed )  return ;
    c2_cc1_test
    if ($failed )  return ;


    report=1
    c2_reset
    c2_ledoff
    c2_reseterror
    report=2

    c2_dma_test
        if ($failed )  return ;

    report=0
    c2_reset
    c2_ledoff
    c2_reseterror
    report=2
	c2_reset
	c2_dummy_fbcbuffer_tests;
	c2_reset
	fbc_buffers_tests
	if ($failed )  return ;

	tablepass_tests
		if ($failed )  return 

    c2_init
    c2_comp
    if ($failed )  return ;

	c2_decomp
	if ($failed )  return ;

    c2_setwm ;
	scaler_tests
	if ($failed )  return ;

     c2_decompsl
    if ($failed )  return ;

#    c2_compsl
#   if ($failed )  return ;

    c2_gpsw
    if ($failed )  return ;

	c2_video_tests
	if ($failed )  return ;
	
}

c2_forever {
	$c2_count = 0;
	while (1) {
	echo " cosmo2 all scripts running at iteration " $c2_count
	c2main_all
		if ($failed )  {
		echo " cosmo2 all scripts FAILED at iteration " $c2_count
		return;
		}
	$c2_count = $c2_count + 1
	}
}

c2_voint {
c2_cc -c 1 -p 0xa3a1a2 -s 1 -g 0
}

c2_gl {
c2_cc -c 1 -p 0xa3a1a2 -s 1 -g 1
}

c2_vivo {
mcuput -o 0x400001 -v 0
}


c2_vicd {
echo "avi > c > gal > d > avo "
mcuput -o 0x400006 -v 0x00
mgv_write_ind -o 18 -v 0x44
mcuput -o 0x400001 -v 0x36
}

c2_vica {
echo "avi > c > gal > a > avo "
mcuput -o 0x400006 -v 0x00
mgv_write_ind -o 18 -v 0x4e
mcuput -o 0x400001 -v 0x24
}

c2_vicb {
echo "avi > c > gal > b  > avo "
mcuput -o 0x400006 -v 0x00
mgv_write_ind -o 18 -v 0x4f
mcuput -o 0x400001 -v 0x2d
}

# a to d/b
c2_viad {
echo "avi > a > gal > d > avo "
mgv_write_ind -o 18 -v 0xee
mcuput -o 0x400004 -v 0x0
mgv_write_ind -o 18 -v 0xe4
mcuput -o 0x400001 -v 0x36
}

c2_viab {
echo "avi > a > gal > b > avo "
mgv_write_ind -o 18 -v 0xee
mcuput -o 0x400004 -v  0x0
mgv_write_ind -o 18 -v 0xef
mcuput -o 0x400001 -v 0x2d
}

# b to d/a
c2_vibd {
echo "avi > b > gal > d > avo "
mgv_write_ind -o 18 -v 0xff
mcuput -o 0x400005 -v 0x00
mgv_write_ind -o 18 -v 0xf4
mcuput -o 0x400001 -v 0x36
}

c2_viba {
echo "avi > b > gal > a > avo "
mgv_write_ind -o 18 -v 0xff
mcuput -o 0x400005 -v 0x00
mgv_write_ind -o 18 -v 0xfe
mcuput -o 0x400001 -v 0x24
}

c2_ch1cd {
echo "channel 1 > c > gal > d > avo "
mcuput -o 0x400006 -v 0x12
mgv_write_ind -o 18 -v 0x44
mcuput -o 0x400001 -v 0x36
}

c2_ch1ca {
echo "channel 1 > c > gal > a > avo "
mcuput -o 0x400006 -v 0x12
mgv_write_ind -o 18 -v 0x4e
mcuput -o 0x400001 -v 0x24
}

c2_ch1cb {
echo "channel 1 > c > gal > b > avo "
mcuput -o 0x400006 -v 0x12
mcuput -o 0x400006 -v 0x12
mgv_write_ind -o 18 -v 0x4f
mcuput -o 0x400001 -v 0x2d
}

# a to d/b
c2_ch1ad {
echo "channel 1 > a > gal > d > avo "
mgv_write_ind -o 18 -v 0xee
mcuput -o 0x400004 -v 0x12
mgv_write_ind -o 18 -v 0xe4
mcuput -o 0x400001 -v 0x36
}


c2_ch1ab {
echo "channel 1 > a > gal > b > avo "
mgv_write_ind -o 18 -v 0xee
mcuput -o 0x400004 -v 0x12
mgv_write_ind -o 18 -v 0xef
mcuput -o 0x400001 -v 0x2d
}

# b to d/a
c2_ch1bd {
echo "channel 1 > b > gal > d > avo "
mgv_write_ind -o 18 -v 0xff
mcuput -o 0x400005 -v 0x12
mgv_write_ind -o 18 -v 0xf4
mcuput -o 0x400001 -v 0x36
}

c2_ch1ba {
echo "channel 1 > b > gal > a > avo "
mgv_write_ind -o 18 -v 0xff
mcuput -o 0x400005 -v 0x12
mgv_write_ind -o 18 -v 0xfe
mcuput -o 0x400001 -v 0x24
}

c2gal_menu {
echo "c2_voint: sets the video in internal mode"
echo "c2_gl: sets the video in genlock mode"
echo "c2_vivo: display the video from avi to avo"

echo "c2_cb1: plays the colorbars from ch 1 in internal mode"
echo "c2_cb2: plays the colorbars from ch 2 in internal mode"
echo "c2_bur1: plays the fr_burst from ch 1 in internal mode"
echo "c2_bur2: plays the fr_burst from ch 2 in internal mode"

echo "c2_vicd: avi > c > gal > d > avo "
echo "c2_vica: avi > c > gal > a > avo "
echo "c2_vicb: avi > c > gal > b  > avo "
echo "c2_viba: avi > b > gal > a > avo "
echo "c2_vibd: avi > b > gal > d > avo "
echo "c2_viab: avi > a > gal > b > avo "
echo "c2_viad: avi > a > gal > d > avo "

echo "c2_ch1cd: channel 1 > c > gal > d > avo "
echo "c2_ch1ca: channel 1 > c > gal > a > avo "
echo "c2_ch1cb: channel 1 > c > gal > b > avo "
echo "c2_ch1ab: channel 1 > a > gal > d > avo "
echo "c2_ch1ad: channel 1 > a > gal > b > avo "
echo "c2_ch1ba: channel 1 > b > gal > d > avo "
echo "c2_ch1bd: channel 1 > b > gal > a > avo "
}


c2mg_init {
buffon ; mg_setboard 0 ;  mg_reset ; mgv_init ; resetcons ; buffoff
}

c2_readme {
echo " DO YOU HAVE THESE FILES IN YOUR SERVER"
echo "      white.jfif, black.jfif, fbc.exo, cosmo2.ide"
echo " to write cgi1 registers   : cgi1put -o offset -v value"
echo " to read cgi1 registers    : cgi1get -o offset"
echo " to write cosmo2 registers : mcuput -o offset -v value"
echo " to read cosmo2 registers  : mcuget -o offset"
echo " Please make SURE you have daugther card plugged into the board"
echo " c2_repeat runs forever.   c2_all runs for one iteration"
echo " if you are using galileo, type c2mg_init"
}

c2_menu {
echo "===== COSMO2 IDE COMMANDS     =="
echo "c2_readme      c2_repeat          c2_all"
echo "c2_load_xlx    c2_init            c2_probeslot"
echo "c2_rev         c2_cc1_test        c2_cgi1_rev"
echo "c2_reset       c2_cgi1tests       c2_dc   "
echo "c2_ledoff                c2_ledon"
echo "c2_cgi1_on               c2_cgi1_off"
echo "c2_dma_test(1-4)         c2_sram_test"
echo "c2_fifoflags(1-4)        c2_mug(1-4)"
echo "c2_fifo_uniq(1-4)        c2_mcuflags"
echo "c2_fbc_ch(1-2)           c2_z050_ch(1-2)"
echo "c2_z016_ch(1-2)          c2_upc_ch(1-2)"
echo "c2_scaler_ch(1-2)        c2_fifo_lpb(1-4)"
echo "c2_cbar_patrn            c2_gpsw"
echo "c2_pad2gio1              c2_pad2gio2"
echo "c2_tp1                   c2_tp2"
echo "c2_tpsl1                 c2_tpsl2"
echo "c2_fbc1_buf1             c2_fbc1_buf2"
echo "c2_fbc2_buf1             c2_fbc2_buf2"
echo "c2_scaler1               c2_scaler2"
echo "c2_comp(1-2)             c2_compsl(1-2)"
echo "c2_decomp(1-2)           c2_decompsl(1-2)"
echo "c2_video_tests           c2gal_menu"
}

##### END COSMO2 scripts #########

#
# Start of MCO diags
#

mco_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	MCO DAC test menu"
echo "mcoVC2menu	MCO VC2 test menu"
echo "mcoPPmenu		MCO 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 MCO video format 	mco_setvof -g MCO_format "
echo "		MCO_formats: "
echo "			4test_800x600_60, mini_800x600_60, mini_640x480_60"
echo "mco_loadvof  Load MCO video format (MCO only!) 	mco_loadvof -g MCO_format "
echo "		MCO_formats: "
echo "			4test_800x600_60, mini_800x600_60, mini_640x480_60"
echo "mgras_loadvof  Load MGRAS video format (MGRAS only!) 	mgras_loadvof -g MCO_format "
echo "		MCO_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 "mcoscreen   Run all MCO 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"
echo "mco_7162addrreg  7162 DAC Address Reg Test.         mco_7162addrreg A"
echo "mco_7162ctrlreg  7162 DAC Control Reg Tests.        mco_7162ctrlreg A"
echo "mco_7162modereg  7162 DAC Mode Reg Test.            mco_7162modereg A"
echo "                       -----------------------"
echo "                    7162 DAC Color Palette Tests"
echo "                       -----------------------"
echo "mco_7162clrpaletteaddrUniq   mco_7162clrpaletteaddrUniq A"
echo "mco_7162clrpalettewalkbit    mco_7162clrpalettewalkbit A"
echo "mco_7162clrpalettepatrn      mco_7162clrpalettepatrn A"
echo "                       -----------------------"
echo "                    473 DAC Register Tests"
echo "                       -----------------------"
echo "mco_473probe    Basic Initialization of 473 DAC.  mco_473 A|B|C"
echo "                       -----------------------"
echo "                    473 DAC Color Palette Tests"
echo "                       -----------------------"
echo "mco_473clrpaletteaddrUniq   mco_473clrpaletteaddrUniq A|B|C"
echo "mco_473clrpalettewalkbit    mco_473clrpalettewalkbit A|B|C"
echo "mco_473clrpalettepatrn      mco_473clrpalettepatrn A|B|C"
echo "                       -----------------------"
echo "                    473 DAC Overlay Register Tests"
echo "                       -----------------------"
echo "mco_473overlayaddrUniq   mco_473overlayaddrUniq A|B|C"
echo "mco_473overlaywalkbit    mco_473overlaywalkbit A|B|C"
echo "mco_473overlaypatrn      mco_473overlaypatrn A|B|C"
}

mcoVC2menu {
echo ""
echo "                       -----------------------"
echo "                    MCO 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 "                    MCO Input/Output Swizzle (Pixel Path) Tests"
echo "                       -----------------------"
echo ""
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 = 1;
        mg_gfxreset;
        delay;
        delay;
        $status = mg_setboard ;
        if ($status == 0) return (1);
        delay;
        mg_hqfifoinit;
#
        delay;
        mg_set_0ge;
        delay;
        if ( mg_reset) return (1);
        delay;
        delay;
	resetcons
        if (! mg_gfxconsole) {
                if ( mg_sync_repp) return (1);
                if ( mg_sync_pprdram) return (1);
                mg_xmapinit
                if ( mg_rdram_ccsearch) return (1);
		mg_initppregs
		enabdisp
		mg0_clear_color
        }
        $solid = mg_issolid;
        $failed = 0;
}

mcoinit {
	allsetup;
	report=4;
	$tmp = mco_probe -d;
	if ($tmp) {
		mco_initfpga -f dksc(0,1,0)/usr/stand/fpgas.diag_vga.rbf;
	}
}

mco7162Atests {
	$mcoerrs = 0;

	$tmp = mco_7162probe A;
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC A 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 "*************************************"
	echo "Check ADV7162 DAC A Color Palette RAM"
	echo "*************************************"
	$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;
	}

	return $mcoerrs;

}

mco7162Btests {
	$mcoerrs = 0;

	$tmp = mco_7162probe B;
	if ($tmp) {
		echo "Error detected in MCO 7162 DAC B probe"
		$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 "*************************************"
	echo "Check ADV7162 DAC B Color Palette RAM"
	echo "*************************************"
	$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;
	}

	return $mcoerrs;

}

mco473Atests {
	$mcoerrs = 0;

	$tmp = mco_473probe A;
	if ($tmp) {
		echo "Error detected in MCO 473 DAC A probe"
		$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;
	}

	return $mcoerrs;

}

mco473Btests {
	$mcoerrs = 0;

	$tmp = mco_473probe B;
	if ($tmp) {
		echo "Error detected in MCO 473 DAC B probe"
		$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;
	}

	return $mcoerrs;

}

mco473Ctests {
	$mcoerrs = 0;

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

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

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

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

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

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

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

	return $mcoerrs;

}

mcoVC2tests {
	$mcoerrs = 0;

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

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

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

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

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

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

	return $mcoerrs;
}

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
}

scene2 {
	mg0_clear_color -d 1608 1208
	mg0_tri -x 0 1200 0 100 0 0 0 -d 1600 600 0 0 100 0 0 -n 0 0 0 0 0 100 0
	mg0_tri -x 150 250 0 99 6 8 2 -d 200 150 0 50 96 9 1 -n 0 20 0 0 6 98 7
	mg0_line -x 1200 1200 0 100 100 0 0 -n 0 0 0 100 100 0 0
	mg0_line -x 0 1200 0 100 0 100 0 -n 1200 0 0 100 100 0 0
	mg0_clear_color -t 600 600 -d 700 700
	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 "MCO Test Pattern (Green 50%)"
	echo "**********************************"
	echo "Setting up MardiGras Frame buffer"
	mg0_clear_color -c 256 -g 128 -d 1600 1200
}

testpat2 {
	echo "**********************************"
	echo "MCO 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 "MCO 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 "MCO 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 "MCO 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 "MCO 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 "MCO 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 "MCO 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 {
	$mcoerrs = 0;

#	 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 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

	return $mcoerrs;

}

DACcrc {
	$mcoerrs = 0;

	# 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;
#	}

	# 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;
        }
	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;
        }
	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;
        }
	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;
        }
	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;
        }
	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;
        }
	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;
        }
	delay

	return $mcoerrs;

}

mcoscreen {
	$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 -g 4test_800x600_60
	mgras_loadvof -g 4test_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;
		return(1);
	}
	$tmp = mco_initfpga -f dksc(0,1,0)/usr/stand/fpgas.diag_vga.rbf;

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

	if ( mco7162Atests )	return(1);

	if ( mco473Atests )	return(1);
	if ( mco473Btests )	return(1);
	if ( mco473Ctests )	return(1);

	if ( mcoVC2tests )	return(1);

	echo "*******************************************************"
	echo "Setting MCO VOF to 4test_800x600_60"
	echo "*******************************************************"
	mco_loadvof 4test_800x600_60
	mgras_setgenlock on

	echo "*******************************************************"
	echo "MCO Input Swizzle/Output Swizzle Checksum Test"
	echo "*******************************************************"
	echo
	if ( oschecksum )	return(1);

	echo "*******************************************************"
	echo "MCO 7162 DAC CRC Test"
	echo "*******************************************************"
	echo
	if ( DACcrc )	return(1);

	# If we made it this far, then we passed all ide tests.
	unix
}

menu
