#########################################################################
#	IP22 Script - Includes PM, CPU, MEM, and GFX TESTS		#
#########################################################################
report=4 # set verbose, but not debug
$stoponerr=1
$failed = 0;
$oven = 0;
$quick = 0;
$solid = 0;
$gounix = 1;
$skip_timer = 0;
$skip_eisa = 0;
$testnum=""
$vc3fail=0;
$bothslots=0;
$slot=0;
$suite=0;
$ext_duart_on=0;
hinv -v
delay {
	ide_delay -s 2;
}
cv_low {
	echo "Changing Voltage to 4.75V"
	chg_volt 1; 
	repeat 8 {
		delay;
	}
	chg_volt 0; 
	repeat 8 {
		delay;
	}
}
cv_nom {
	echo "Changing Voltage to 5.00V"
	chg_volt 1;
	repeat 8 {
		delay;
	}
}
cv_high {
	echo "Changing Voltage to 5.25V"
	chg_volt 1; 
	repeat 8 {
		delay;
	}
	chg_volt 2;
	repeat 8 {
		delay;
	}
}
unix {
	echo "<<<< About to boot UNIX......>>>>"
	boot dksc(0,1,0)unix;
}
send_boot_msg {
	boot -f $1
}
#########################################################################
#	Processor Module Tests and Scripts				#
#########################################################################
pm {
	echo "PM Processor Module Tests...."
	$testnum = "_001"
	if(tlb) {
		echo "Failure detected in tlb test"
		$failed=1;
		return(-1);
	}
	$testnum = "_002"
	if(utlb) {
		echo "Failure detected in utlb test"
		$failed=1;
		return(-1);
	}
	$testnum = "_003"
	$tmp = dcache1
	if($tmp) {
		echo "Failure detected in dcache1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_004"
	$tmp = icache1
	if($tmp) {
		echo "Failure detected in icache1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_005"
	$tmp = icache2
	if($tmp) {
		echo "Failure detected in icache2 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_006"
	if(scache1) {
		echo "Failure detected in scache1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_007"
	if(hpc3) {
		echo "Failure detected in hpc3 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_008"
	if(fpu) {
		echo "Failure detected in fpu test"
		$failed=1;
		return(-1);
	}
	echo "Processor Module Tests Passed...."
}
#########################################################################
#	CPU Board Tests and Scripts					#
#########################################################################
cpusc {
	echo "CPU Secondary Cache Tests...."
        if (is_r4600sc) {
		echo "R4600sc found!!!";
		$testnum = "_009"
		if(sc_on){
			echo "Failure detected in sc_on test"
		  	$failed=1;
			return(-1);
        	}
		$testnum = "_010"
		if(sc_hit){
			echo "Failure detected in sc_hit test"
			$failed=1;
			return(-1);
		}
		$testnum = "_011"
		if(sc_miss){
			echo "Failure detected in sc_miss test"
		  	$failed=1;
			return(-1);
        	}
		$testnum = "_012"
        	if(sc_hit_miss){
			echo "Failure detected in sc_hit_miss test"
	  	  	$failed=1;
			return(-1);
        	}
		$testnum = "_013"
        	if(sc_tag){
			echo "Failure detected in sc_tag test"
                  	$failed=1;
			return(-1);
        	}
		$testnum = "_014"
		if(sc_off){
			echo "Failure detected in sc_off test"
			$failed=1;
			return(-1);
		}
        }
	else
	   {
		echo "R4600sc not found!!!";
		$testnum = "_001"
		if(tlb){
			echo "Failure detected in tlb test"
			$failed=1;
			return(-1);
		}
	
		$testnum = "_002"
		if(utlb){
			echo "Failure detected in utlb test"
			$failed=1;
			return(-1);
		}
	fi
	   }
	$testnum = "_003"
	if(dcache1){
		echo "Failure detected in dcache1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_004"
	$tmp=icache1
	if($tmp) {
		echo "Failure detected in icache1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_005"
	$tmp=icache2
	if($tmp) {
		echo "Failure detected in icache2 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_006"
	$tmp=scache1
	if($tmp) {
		echo "Failure detected in scache1 test"
		$failed=1;
		return(-1);
	}	
	$testnum = "_015"
	$tmp=scache2
	if($tmp) {
		echo "Failure detected in scache2 test"
		$failed=1;
		return(-1);
	}	
	$testnum = "_009"
	if(fpu) {
		echo "Failure detected in fpu test"
		$failed=1;
		return(-1);
	}
	echo "CPU Secondary Cache Tests Passed...."
}
#########################################################################
#	Memory Tests and Scripts					#
#########################################################################
memory {
	echo "Memory tests...."
	$testnum = "_100"
	$tmp=khlow
	if($tmp) {
		echo "Failure detected in Knaizuk Hartmann Low Test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()khlow.pass;
	}
	$testnum = "_101"
	$tmp=memtest2 3
	if($tmp) {
		echo "Failure detected in Knaizuk Hartmann Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_3.pass;
	}
	$testnum = "_102"
	$tmp=memtest2 5
	if($tmp) {
		echo "Failure detected in Knaizuk Hartmann Parity  Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_5.pass;
	}
	$testnum = "_103"
	$tmp=memtest2 10
	if($tmp) {
		echo "Failure detected in Threebit Memory Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_10.pass;
	}
	$testnum = "_104"
	$tmp=memtest2 12
	if($tmp) {
		echo "Failure detected in Knaizuk Hartmann Doubleword Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_12.pass;
	}
	$testnum = "_105"
	$tmp=memtest2 11
	if($tmp) {
		echo "Failure detected in Butterfly Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_11.pass;
	}
	$testnum = "_106"
	$tmp=memtest2 8
	if($tmp) {
		echo "Failure detected in March X Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_8.pass;
	}
	$testnum = "_107"
	$tmp=memtest2 9
	if($tmp) {
		echo "Failure detected in March Y Test"
		$failed=1;
		return(-1);
	}	
	if ($oven) {
		boot -f bootp()memtest_9.pass;
	}
	$testnum = "_108"
	$tmp=ldram
	if($tmp) {
		echo "Failure detected in ldram test"
		$failed=1;
		return(-1);
	}	
	echo "Memory tests Passed...."
}
#########################################################################
#	Audio Tests and Scripts						#
#########################################################################
a2test {
	$loopcount = 0;
	report =4;
	$a2tst0pass = 0;
	$a2tst0fail = 0;
	$a2tst1pass = 0;
	$a2tst1fail = 0;
	$a2tst2pass = 0;
	$a2tst2fail = 0;
	$a2tst3pass = 0;
	$a2tst3fail = 0;
	$a2tst4pass = 0;
	$a2tst4fail = 0;
	$a2tst5pass = 0;
	$a2tst5fail = 0;
	$a2tst6pass = 0;
	$a2tst6fail = 0;
	$a2tst7pass = 0;
	$a2tst7fail = 0;
	while ( $loopcount < 3 ) {
		echo ""
		echo "----------------------------------------------------"
		echo "Starting audio test loop" $loopcount
		echo "----------------------------------------------------"
		$a2tst = audio -t0
		if($a2tst) {
			$a2tst0fail = $a2tst0fail + 1;
			$failed = 1;
		}
		else {
			$a2tst0pass = $a2tst0pass + 1;
		}
		a2tst = audio -t1
		if($a2tst) {
			$a2tst1fail = $a2tst1fail + 1;
			$failed = 1;
		}
		else {
			$a2tst1pass = $a2tst1pass + 1;
		}
		a2tst = audio -t2
		if($a2tst) {
			$a2tst2fail = $a2tst2fail + 1;
			$failed = 1;
		}
		else {
			$a2tst2pass = $a2tst2pass + 1;
		}
		a2tst = audio -t3
		if($a2tst) 
			$a2tst3fail = $a2tst3fail + 1;
		else
			$a2tst3pass = $a2tst3pass + 1;
		a2tst = audio -t4
		if($a2tst)
			$a2tst4fail = $a2tst4fail + 1;
		else
			$a2tst4pass = $a2tst4pass + 1;
		a2tst = audio -t5
		if($a2tst) {
			$a2tst5fail = $a2tst5fail + 1;
			$failed = 1;
		}
		else {
			$a2tst5pass = $a2tst5pass + 1;
		}
		a2tst = audio -t6
		if($a2tst) {
			$a2tst6fail = $a2tst6fail + 1;
			$failed = 1;
		}
		else {
			$a2tst6pass = $a2tst6pass + 1;
		}
		a2tst = audio -t7
		if($a2tst) 
			$a2tst7fail = $a2tst7fail + 1;
		else
			$a2tst7pass = $a2tst7pass + 1;
		$loopcount = $loopcount + 1;
	}
	echo "audio test 0: 	Pass =" $a2tst0pass"	fail =" $a2tst0fail
	echo "audio test 1: 	Pass =" $a2tst1pass"	fail =" $a2tst1fail
	echo "audio test 2: 	Pass =" $a2tst2pass"	fail =" $a2tst2fail
	echo "audio test 3: 	Pass =" $a2tst3pass"	fail =" $a2tst3fail
	echo "audio test 4: 	Pass =" $a2tst4pass"	fail =" $a2tst4fail
	echo "audio test 5: 	Pass =" $a2tst5pass"	fail =" $a2tst5fail
	echo "audio test 6: 	Pass =" $a2tst6pass"	fail =" $a2tst6fail
	echo "audio test 7: 	Pass =" $a2tst7pass"	fail =" $a2tst7fail
	wait;
	if( $a2tst7pass == 0 ) {
		# Rerun audio -t7 ten more times to get it to pass
		echo "Audio test 7 failed three loops."
		echo "Press ENTER to run audio test 7 for 10 more loops"
		wait;
		$report=1
		$loopcount = 0;
		while ( $loopcount < 10 ) {
			a2tst = audio -t7
			if($a2tst) {
				$a2tst7fail = $a2tst7fail + 1;
			}
			else {
				$a2tst7pass = $a2tst7pass + 1;
				$loopcount = 10
			}
			$loopcount = $loopcount + 1;
		}
		if( $a2tst7pass == 0 ) {
			echo "Audio test 7 FAILED."
			echo "Reject this system with an Audio failure"
			$failed = 1;
		}
	}
}
#########################################################################
#	MEM, INT and SCSI tests and scripts				#
#########################################################################
ip {
	echo "IP22 interrupt, duart, scsi tests...."
	$tmp = 0;
	$testnum = "_200"
	if(int2) {
		echo "Failure detected in int2 test"
		$failed=1;
		return(-1);
	}
	if ($skip_timer !=1) {
		$testnum = "_201"
		if(clock) {
			echo "Failure detected in clock test"
			$failed=1;
			return(-1);
		}
	}
# Duart External tests turned off and internal tests turned on  rwaits 9/23/92
# originally -i0, -i1 on -i2 off, -e0 off -e2, -e3 on
	ttyprint 0
	$testnum = "_202"
	$tmp=duart -i0;
	if($tmp) {
		echo "Failure detected in duart 0 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_203"
	$tmp= duart -i1;
	if($tmp) {
		echo "Failure detected in duart 1 test"
		$failed=1;
		return(-1);
	}
	ttyprint 1
# only run duart tests if outside of the ASRS and $ext_duart_on == 1
	if ($oven == 0) {
	   ttyprint 0
	   $ext_duart_on = 0;
	   if ($ext_duart_on == 1) {
		$testnum = "_210"
		$tmp= duart -e0;
		if($tmp) {
			echo "Failure detected in duart e0 test"
			$failed=1;
			return(-1);
		}
	   }
	   $ext_duart_on = 1;
	   if ($ext_duart_on == 1) {
		$testnum = "_211"
		$tmp= duart -e1;
		if($tmp) {
			echo "Failure detected in duart e1 test"
			$failed=1;
			return(-1);
		}
		ttyprint 1
	   } 
	   $ext_duart_on = 0;
	}
	$testnum = "_204"
	$tmp = led 0;
	if($tmp){
		echo "Failure detected in led 0 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_205"
	$tmp = led 1;
	if($tmp){
		echo "Failure detected in led 1 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_206"
	if (parity) {
		echo "Failure detected in parity test"
		$failed=1;
		return(-1);
	} else {
		if ($oven) {
			boot -f bootp()parity.pass;
		}
	}
	$testnum = "_207"
	$tmp = scsi;
	if($tmp) {
		echo "Failure detected in scsi test"
		$failed=1;
		return(-1);
	}
	if ($skip_timer != 1) {
		$testnum = "_208"
		if(timer){
			echo "Failure detected in timer test"
			$failed=1;
			return(-1);
		}
 	}	
	if ($skip_eisa != 1) {
		$testnum = "_209"
	    if(eisa){
		echo "Failure detected in eisa test"
		$failed=1;
		return(-1);
	    }
	}
	else {
	    echo "Skipping EIU/EISA interface test"
	}
	if ($oven == 0) {
		$testnum = "_212"
		if(print3){
			echo "Failure detected in print3 test"
			$failed=1;
			return(-1);
		}
	}
	echo "IP22 Memory, interrupt, duart, scsi tests Passed...."
}	
#########################################################################
#	ALL IP22 (PM/CPU/MEM/AUDIO/SCSI) TESTS and SCRIPTS		#
#########################################################################
ip22 {
	echo "ALL Tests in IP22...."
        $skip_eisa = 0;
        $skip_timer = 0;
	$failed = 0;
	if ($oven == 0) {
	   if (pwjumper) {
		echo "Please install the jumper at location JP1\n"
		$failed=1;
		return(-1);
	   }
	}
	pm;
	if($failed) {
		echo "PM Tests FAILED\n"
		return(-1);
	} else if ($oven) {
		boot -f bootp()pm1.pass;
	}
	cpusc;
	if($failed) {
		return(-1);
	} else if ($oven) {
		boot -f bootp()cpu.done;
	}
	if ($oven) {
		$testnum = "_109"
		$tmp = memtest;
		if ($tmp) {
			echo "Failure detected in memtest test"
			$failed=1;
			return(-1);
		}
		$testnum = "_111"
		$tmp = ldram -p;
		if ($tmp) {
			echo "Failure detected in ldram test"
			$failed=1;
			return(-1);
		}
		memory;
		if ($failed) {
			return(-1);
		} else {
			if ($oven) {
				boot -f bootp()khmem.passed;
			}
		}
	} else {
		$tmp = memtest 0xa8800000:0xa9000000 ;
		if ($tmp) {
			echo "Failure detected in memtest test"
			$failed=1;
			return(-1);
		}
	}
	ip;
	if($failed) {
		echo "IP22 Tests FAILED\n"
		return(-1);
	} else if ($oven) {
		boot -f bootp()ip.done;
	}
	echo "ALL Tests in IP22 Passed...."
}
#########################################################################
#	ALL IP22 (PM/CPU/MEM/AUDIO/SCSI) WITH VOLTAGE CHANGES		#
#########################################################################
ip22va {
	$skip_timer = 0;
	$skip_eisa = 0;
	$failed =0;
	cv_low;
	ip22;
	if ($failed) {
		return(-1);
	}
	cv_high;
	ip22;
	if ($failed) {
		return(-1);
	}
}
#########################################################################
#	IMPACT GRAPHICS TESTS and SCRIPTS				#
#########################################################################
gioslot {
	if ($bothslots) {
		if ($slot == 0) {
			$tmp = mg_setboard 0;
			if ($tmp) {
				echo "Found boards in slot 0"
			} else {
				echo "No boards found in slot 0"
			}
		} else {
			$tmp = mg_setboard 1;
			if ($tmp) {
				echo "Found boards in slot 1"
			} else {
				echo "No boards found in slot 1"
			}
		}
	} else {
		$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"
			}
		}
	}
}
# allows colors to be correct for drawings
drawsetup {
	delay;
#	mg_gfxreset;
#	mg_set_0ge;
#	mg_reset;
	delay;
	delay;
	mg_xmapinit;
}
enabdisp {
mg_pokexmap -r XMAP_DIB_CTRL0 -d 0x100
}
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;
}
re4setup {
	$failed =0;
	echo "Calling mg_gfxreset"
	mg_gfxreset;
	delay;
	echo "Calling gioslot"
        gioslot
	delay;
	echo "Calling mg_set_0ge"
	mg_set_0ge;
	delay;
	echo "Calling mg_re4reset"
	$status = mg_re4reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	delay;
	resetcons
	$solid = mg_issolid;
}
ppsetup {
	$failed =0;
	if (!mg_gfxconsole) {
		echo
		echo "Syncing RA Board - re4 to pp0"
		mg_sync_repp -r 0 -p 0
		delay
		echo "Syncing RA Board - re4 to pp1"
		mg_sync_repp -r 0 -p 1
		delay
		$tmp = mg_setnumre4s -q
		echo
		echo "Syncing RA Board - pp0 to rdram-0"
                mg_sync_pprdram_repair -r 0 -p 0 -d 0
		delay
                echo "Syncing RA Board - pp0 to rdram-1"
                mg_sync_pprdram_repair -r 0 -p 0 -d 1
		delay
                echo "Syncing RA Board - pp0 to rdram-2"
                mg_sync_pprdram_repair -r 0 -p 0 -d 2
		delay
                echo "Syncing RA Board - pp1 to rdram-0"
                mg_sync_pprdram_repair -r 0 -p 1 -d 0
		delay
                echo "Syncing RA Board - pp1 to rdram-1"
                mg_sync_pprdram_repair -r 0 -p 1 -d 1
		delay
                echo "Syncing RA Board - pp1 to rdram-2"
                mg_sync_pprdram_repair -r 0 -p 1 -d 2
		delay
                $tmp = mg_setnumre4s -q
		if ($tmp == 2) {
			echo;
			echo "Syncing RB Board - re4 to pp0"
			mg_sync_repp -r 0 -p 0
			delay
			echo "Syncing RB Board - re4 to pp1"
			mg_sync_repp -r 0 -p 1
			delay
			echo;
                        echo "Syncing RB Board - pp0 to rdram-0"
                        mg_sync_pprdram_repair -r 1 -p 0 -d 0
			delay
                        echo "Syncing RB Board - pp0 to rdram-1"
                        mg_sync_pprdram_repair -r 1 -p 0 -d 1
			delay
                        echo "Syncing RB Board - pp0 to rdram-2"
                        mg_sync_pprdram_repair -r 1 -p 0 -d 2
			delay
                        echo "Syncing RB Board - pp1 to rdram-0"
                        mg_sync_pprdram_repair -r 1 -p 1 -d 0
			delay
                        echo "Syncing RB Board - pp1 to rdram-1"
                        mg_sync_pprdram_repair -r 1 -p 1 -d 1
			delay
                        echo "Syncing RB Board - pp1 to rdram-2"
                        mg_sync_pprdram_repair -r 1 -p 1 -d 2
			delay
                }
		echo
		echo "Calling mg_sync_pprdram to sync everybody together"
		mg_sync_pprdram
		echo "Calling mg_xmapinit"
        	mg_xmapinit
		delay; delay
		echo "Calling mg_rdram_ccsearch"
		mg_rdram_ccsearch
		delay
		echo "Calling mg_initppregs"
        	mg_initppregs
		delay
		echo "Calling enabdisp"
		enabdisp	
		delay
		echo "Calling mg0_clear_color"
		mg0_clear_color
	}
	$solid = mg_issolid;
}
alphablend_test {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	drawsetup;
	mg0_clear_color
	mg_vc3clearcursor
	$status = mg_alphablend
	if ($status) {
                $failed = 1;
                echo;
                echo "                                                 -- ERROR"
		echo;
                echo; echo "RDRAM readback FAILED"; echo;
        }
	delay; delay;
	$status = mg_crc_test -r 0x21 -g 0x23e -b 0x2b6;
	if ($status) {
		$failed = 1;
                echo;
                echo "                                                 -- ERROR"
                echo
                echo; echo "CRC FAILED"; echo
		echo "alpha blending test with crc check - FAILED"; echo
	} 
	else {
		echo "alpha blending test with crc check - PASSED"
	}
}
scene1 {
	mg0_clear_color
	fpusetup
	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
	fpusetup
	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
}
scene1_overlay {
	mg0_tri -x 500 900 0 100 0 0 0 -d 0 400 0 50 100 0 0 -n 90 0 0 0 0 100 0 -b 0x41
	mg0_rect -t 1100 100 -d 1200 200 -r100 -g 20 -b 100 -f 0x41
	mg0_line -x 100 500 0 100 0 0 0 -n 800 0 0 100 0 0 0 -f 0x41
	mg0_point -x 600 -y 500 -r 100  -f 0x41
	mg0_point -x 610 -y 500 -r 100  -f 0x41
	mg0_point -x 590 -y 500 -r 100  -f 0x41
	mg0_clear_color -f 0x41 -r 100 -t 800 700 -d 900 800
}
scene_test {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	drawsetup
	mg_vc3clearcursor;
        echo "------    Executing Scene Test with CRC ------"
	echo "------    Testing the scene in the display buffer ------"
	scene1
	if ((mg_gfxconsole) && ($bothslots ==1) && ($slot == 1)) {
			# for ge medical, dual head
			$status = mg_crc_test -r 0x84 -g 0x10f -b 0x35e;	
	}
	else {
		$status = mg_crc_test -r 0x18a -g 0xa4 -b 0x18e;
	}
	if ($status) {
		$failed = 1;
		echo;
                echo "                                                 -- ERROR"
                echo
                echo; echo "CRC FAILED"; echo
		echo "scene in the display buffer with crc check - FAILED"
	} 
	else {
		echo "scene in the display buffer with crc check - PASSED"
	}
	echo "------    Testing the scene in the overlay buffer ------"
	mg_overlay_on;
	mg0_clear_color -f 0x41;
	mg_enabdisp_overlay;
	scene1_overlay;
        $tmp = mg_setnumre4s -q
	if ($tmp == 2) {
		$status = mg_crc_test -r 0x233 -g 0x4b -b 0xd1;
	}
	else {
		if ((mg_gfxconsole) && ($bothslots ==1) && ($slot == 1)) {
			# for ge medical, dual head
			$status = mg_crc_test -r 0x24b -g 0x39d -b 0x22;
		}
		else {
			$status = mg_crc_test -r 0x345 -g 0x236 -b 0x2f2;
		}
	}
	if ($status) {
		$failed = 1;
		echo;
                echo "                                                 -- ERROR"
                echo
                echo; echo "CRC FAILED"; echo
		echo "scene in the overlay buffer with crc check - FAILED"; echo
	} 
	else {
		echo "scene in the overlay buffer with crc check - PASSED"
	}
	mg_disabdisp_overlay;
	mg_overlay_off;
	echo "********	Scene Test with CRC Execution Completed   ********"
}
mg_tram_rev_nobuff {
$status = mg_dma_tram -r -e 1 -p
if ($status) {
	$failed = 1;
	return (-1);
}
$foo = mg_setnumre4s -q
if ($foo == 2) {
	$status = mg_dma_tram -r -e 1 -p -n 1
	if ($status) {
		$failed = 1;
		return (-1);
	}
}
}
hq3test {
	echo "------	Executing Hq3 Test Suite 	------"
	$failed = 0;
	buffon;
	mg_gfxreset;
	delay;
	mg_set_0ge
	$testnum = "_1"
        $status  	= 	mg_hq3_initcheck;
	$testnum = "_02"
        $status  	= 	mg_hq3;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	mg_gfxreset;
	delay;
	$testnum = "_03"
     	$status  	= 	mg_hq3_cp;
     	if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_04"
     	$status  	= 	mg_hq3_converter;
     	if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_05"
        $status  	= 	mg_hq3_cfifo;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	echo "********	Hq3 Test Suite Execution Completed 	********"
	resetcons; buffoff
}
# GE11 test scripts 
gioslot_2GE {
	$tmp = mg_setboard 0;
	if ($tmp) {
		echo "Mgras Gfx init to GIO Slot 0 "
		mg_setboard 0 2;
	}
	else {
		$tmp = mg_setboard 1;
		if ($tmp) {
			echo "Found boards in slot 1"
			mg_setboard 1 2;
	        }
		else {
			echo "No boards found in slot 0 or slot 1"
		}
	}
}
ge_ucode_test {
		$status = mg_ge_reg
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$status = mg_ge_ucode_dbus
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$status = mg_ge_ucode_abus
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$status = mg_ge_ucode_a
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$status = mg_ge_ucode_m
		if ($status) {
			$failed = 1;
			return(-1);
		}
}
ge0_ucode {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if ($ge_no == 0)
	{
		echo "GE11 doesn't exist";
	}
	else if ($ge_no == 1){
		echo "testing GE0 Ucode memory....";	
      
		gioslot;
		buffon;
		mg_gfxreset;
		mg_set_ge 0;
		ge_ucode_test;
	     }
             else if ($ge_no == 2) {
		echo "testing GE0(2GE system) Ucode memory....";	
      
		gioslot_2GE;
		buffon;
		mg_gfxreset;
		mg_set_ge 0;
		ge_ucode_test;
	     }	
}
ge1_ucode {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;	
	if ($ge_no == 2) 
	{
		echo "testing GE1 Ucode memory....";	
		gioslot_2GE;
		buffon;
		mg_gfxreset;
		mg_set_ge 1;
		ge_ucode_test;
	}
	else {
		echo "GE11 doesn't exist";
	     }
}
getest {
        $status 	=	mg_ge_cram;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_eram;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_wram;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_alu;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_dreg;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_inst;
	if ($status) {
                $failed = 1;
                return(-1);
        }
        $status 	=	mg_ge_dma;
	if ($status) {
               $failed = 1;
                return(-1);
        }
	echo "********	GE Test Suite Execution Completed 	********"
}
ge0_setup {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if ($ge_no == 0)
	{
		echo "No GE11 exists";
	}
	if ($ge_no == 2)  {
		echo "------	Executing GE0 test setup 	------"
		gioslot_2GE;
		$status = mg_hq3_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_gfxreset;
		mg_set_ge 0;
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
	 }
	if ($ge_no == 1)  {
		echo "------	Executing GE0 test setup 	------"
		gioslot_2GE;
		mg_set_ge 0;
		$status = mg_hq3_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_gfxreset;
		delay;
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
	     }
}
ge0_test {
	$failed =0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if($ge_no == 0)
	{
		 echo "No GE11 exists";
	}
	else {
		echo "------	Executing GE Test Suite on :: GE0 	------"
		if ($quick == 0) {
			ge0_ucode;
			if ($failed) {
				return (-1);
			}
		}
		ge0_setup;
		buffon
		delay;
		mg_gfxreset
		$status 	=	getest;
       		if ($status) {
       	        	 $failed = 1;
                return(-1);
        	}
	}
}
ge1_setup {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	buffon;
	if($ge_no == 2)
	{
		echo "------	Executing GE1 test setup 	------"
		gioslot_2GE;
		buffon
		mg_gfxreset;
		mg_set_2ge;
		mg_set_ge 0;
		$status = mg_hq3_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
		mg_set_ge 1;
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
		mg_gfxreset;
		mg_set_2ge;
		mg_set_ge 0;
		mg_nextge;
		mg_set_ge 1;
	}
	if($ge_no == 1)
	{
		echo "GE11_1 doesn't exist";
	}
	buffoff; resetcons;
}
ge1_test {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	buffon;
	if($ge_no == 2)
	{
		mg_gfxreset;
		echo "------	Executing GE Test Suite  :: GE1 	------"
		if ($quick == 0) {
			ge1_ucode;
			if ($failed) {
				return (-1);
			}
		}
		ge1_setup;
		$status 	=	getest;
        	if ($status) {
                	$failed = 1;
                	return(-1);
       		 }
	}
	if($ge_no == 1)
	{
		echo "GE11_1 doesn't exist";
	}
	buffoff; resetcons;
}
tge_setup {
	$failed = 0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if ($ge_no  == 2)
	{
		echo "=== tge_setup ===";
		gioslot_2GE;
		buffon;
		$status = mg_hq3_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_gfxreset;
		delay;
		mg_set_ge 0;
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
		mg_set_ge 1;
		$status = mg_ge11_dnload;
		if ($status) {
			$failed = 1;
			return (-1);
		}
		mg_ge_go;
		mg_set_ge 0;
		resetcons; buffoff;
	}
	if($ge_no == 1)
	{
		echo "Setup GE11_0 only";
		ge0_setup;
	}
	if($ge_no == 0)
	{
		echo "NO ge11 exists";
	}
	buffoff; resetcons;
}
tge_test {
	$failed =0;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if ($ge_no == 2)
	{
		if ($quick == 0) {
			ge0_ucode;
			if ($failed) {
				return (-1);
			}
			ge1_ucode;
			if ($failed) {
				return (-1);
			}
		}
		tge_setup;
		gioslot_2GE;
		buffon
		mg_gfxreset
		delay;
		mg_set_2ge;
		mg_set_ge 0
		mg_ge_go
		mg_set_ge 1
		mg_ge_go
		mg_set_ge 0
		echo " testing GE0 COREs....";
		$status = getest;
		if ($status) {
			$failed = 1;
			resetcons; buffoff;
			return(-1);
		}
		mg_nextge;
		mg_set_ge 1;
		mg_ge_go
		echo " testing GE1 COREs....";
		$status = getest
		if ($status) {
			$failed = 1;
			resetcons; buffoff;
			return(-1);
		}
		resetcons; buffoff
	}
	if ($ge_no == 1) 
	{
		echo "Test only GE11_0";
		$status = ge0_test;
		if ($status) {
			$failed = 1;
			resetcons; buffoff;
			return(-1);
		}
		resetcons; buffoff
	}
	if ($ge_no == 0)
	{
		echo "No GE11 exists";
	}
}
dactest {
	echo "------	Executing DAC   Test Suite 	------"
	$testnum = "_06"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_07"
        $status 	=	mg_dacmodereg;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_08"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_09"
        $status 	=	mg_dacaddrreg;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_10"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_11"
        $status 	=	mg_clrpaletteaddrUniq;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_12"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_13"
        $status 	=	mg_clrpalettewalkbit;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_14"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_15"
        $status 	=	mg_clrpalettepatrn;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_16"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	echo "********	DAC Test Suite Execution Completed 	********"
}
vc3test {
	echo "------	Executing VC3   Test Suite 	------"
	$testnum = "_17"
        $status 	=	mg_vc3reset;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_18"
        $status 	=	mg_vc3internalreg;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_19"
        $status 	=	mg_vc3addrsbus;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_20"
        $status 	=	mg_vc3databus;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_21"
        $status 	=	mg_vc3addrsuniq;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_22"
        $status 	=	mg_vc3patrn;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	echo "********	VC3 Test Suite Execution Completed 	********"
}
cmaptest {
	echo "------	Executing CMAP   Test Suite 	------"
	$testnum = "_23"
        $status 	=	mg_vc3init -t 0x555;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_24"
        $status 	=	mg_cmaprev;
	mg_dispcmapcnt;
        if (!$status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_25"
        $status 	=	mg_cmapdatabus 0;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_26"
        $status 	=	mg_cmapaddrsbus 0;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_27"
        $status 	=	mg_cmappatrn -w 0;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_28"
        $status 	=	mg_cmapaddrsuniq 0;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_29"
        $status 	=	mg_cmapdatabus 1;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_30"
        $status 	=	mg_cmapaddrsbus 1;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_31"
        $status 	=	mg_cmappatrn -w 1;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	mg_clrcmpcnt;
	$testnum = "_32"
        $status 	=	mg_cmapaddrsuniq 1;
	mg_dispcmapcnt;
        if ($status) {
                $failed = 1;
		return (-1);
        }
	echo "********	CMAP Test Suite Execution Completed 	********"
}
bkend {
	$failed =0;
	gioslot;
	buffon;
	echo "------	Executing Back End   Test Suite 	------"
        $status 	=	dactest;
        if ($failed) {
                return(-1);
        }
        $status 	=	vc3test;
        if ($failed) {
		$vc3fail = 1;
                return(-1);
        }
        $status 	=	cmaptest;
        if ($failed) {
                return(-1);
        }
        $status 	=	mg_reset; 
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_34"
        $status 	=	mg_xmapdcbreg 0;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_35"
        $status 	=	mg_xmapdcbreg 1;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$tmp = mg_setnumre4s -q
	if ($tmp == 2) {
	$testnum = "_36"
		$status         =       mg_xmapdcbreg 2;
        	if ($status) {
                	$failed = 1;
                	return(-1);
        	}
	$testnum = "_37"
		$status         =       mg_xmapdcbreg 3;
        	if ($status) {
                	$failed = 1;
                	return(-1);
        	}
	}
		
	$testnum = "_38"
        $status 	=	mg_reset; 
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_40"
	mg_starttiming;
	$status 	=	mg_crcwalk;
	if ($status) {
		$failed = 1;
		return(-1);
	}
	echo "Testing 1280_1024_76 timing"
	$testnum = "_45"
	$status		=	mg_vc3init -t 0x139
	if ($status) {
		$failed = 1;
		return(-1);
	}
	$testnum = "_46"
	$status 	=	mg_crcwalk;
	if ($status) {
		$failed = 1;
		return(-1);
	}
	$testnum = "_47"
	$status 	=	mg_reset; 
	if ($status) {
		$failed = 1;
		return(-1);
	}
	if ($solid) {	
		$testnum = "_48"
		echo "Testing 1600x1200 solid timing"
		mg_stoptiming;
		$status	=	mg_vc3init -t 0x156
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$testnum = "_49"
		mg_starttiming;
		$status	=	mg_crcwalk;
	        if ($status) {
			$failed = 1;
			return(-1);
		}
	} else {
		$testnum = "_50"
		echo "Testing 1600x1200 timing"
		mg_stoptiming;
		$status	=	mg_vc3init -t 0x159
		if ($status) {
			$failed = 1;
			return(-1);
		}
		$testnum = "_51"
		mg_starttiming;
		$status	=	mg_crcwalk;
		if ($status) {
			$failed = 1;
			return(-1);
		}
	}
	$testnum = "_52"
	delay;
	echo "Executing mg_vc3cursorposition test..."
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	mg_xmapinit;
	delay;
	repeat 3 {
		delay
	}

	$testnum = "_53"
	$status 	=	mg_vc3cursorposition;
	if ($status) {
                $failed = 1;
		resetcons; buffoff;
                return(-1);
	}
	
	resetcons; buffoff;
	echo "********	Back End Test Suite Execution Completed 	********"
}
re4test {
	$failed =0;
	report = 3;
	echo "------	Executing RE4   Test Suite 	------"
	$testnum = "_54"
	$status 	=	mg_re_status_reg;
	if ($status) {
		$failed = 1; return(-1);
	}
	led 0;
	$testnum = "_55"
	$status 	=	mg_re_rdwr_regs;
	if ($status) {
		$failed = 1; return(-1);
	}
	$testnum = "_56"
	$status 	=	mg_re_internal_ram -t0;
	if ($status) {
		$failed = 1; return(-1);
	}
	$testnum = "_57"
	$status 	=	mg_re_internal_ram -t1;
	if ($status)  {
		$failed = 1; return(-1);
	}
	$testnum = "_58"
	$status 	=	mg_re_internal_ram -t2;
	if ($status) {
		$failed = 1; return(-1);
	}
	led 1;
	$testnum = "_59"
	$status 	=	mg_re_internal_ram -t3;
	if ($status) {
		$failed = 1; return(-1);
	}
	$testnum = "_60"
	$status 	=	mg_re_internal_ram -t4;
	if ($status) {
		$failed = 1; return(-1);
	}
	$testnum = "_61"
	$status 	=	mg_re_internal_ram -t5;
	if ($status) {
		$failed = 1; return(-1);
	}
	echo "********	RE4 Test Suite Execution Completed 	********"
	report = 4;
}
tetest {
	$failed =0;
	report = 3;
	echo "------	Executing TE Test Suite 	------"
	$testnum = "_99"
	$status 	= 	mg_read_te_version;
	if ($status) {
		$failed = 1; return(-1);
	}
	$testnum = "_113"
	$status 	=	mg_re_rdwr_regs -t;
	if ($status) {
		$failed = 1; return(-1);
	}
	echo "********	TE Test Suite Execution Completed 	********"
	report = 4;
}
dmatest {
	$failed =0;
	echo "------	Executing DMA Test Suite 	------"
	$testnum = "_62"
        $status 	=	mg_host_hqdma;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	$testnum = "_63"
        $status 	=	mg_host_hq_cp_dma;
	if ($status) {
		$failed = 1;
		return(-1);
	}
	$testnum = "_64"
	$status 	=	mg_dma_pp  -r1 -e1 -w1 -d1  -t  -m 0 0 -b 0x240 -y 16 -z 192
	if ($status) {
		$failed = 1;
		return(-1);
	}
	echo "********	DMA Test Suite Execution Completed 	********"
}
drawclose {
	delay;
#	resetcons;
	delay;
	delay;
}
re_texlut_test {
	echo "re_texlut_test is not implemented in IP22 yet" 
}
tex_draw_test {
	$failed =0;
	echo "------	Executing tex_draw_test  Suite 	------"
	drawsetup;
	$testnum = "_65"
	$status		=	mg_notex_line
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_66"
	$status		=	mg_notex_poly
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_67"
	$status		=	mg_tex_poly 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_68"
	$status		=	mg_tex_1d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_69"
	$status		=	mg_tex_3d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_70"
	$status		=	mg_tex_scistri
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_71"
	$status		=	mg_tex_linegl
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_72"
	$status		=	mg_tex_load
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_73"
	$status		=	mg_tex_persp
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_74"
	$status		=	mg_tex_mag 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_75"
	$status		=	mg_tex_detail
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_76"
	$status		=	mg_tex_bordertall
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_77"
	$status		=	mg_tex_lut4d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_78"
	$status		=	mg_tex_borderwide
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_79"
	$status		=	mg_tex_mddma
	delay
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
#	allsetup
#	$testnum = "_114"
#	re_texlut_test;
#	delay;
#        if ($failed) {
#                return(-1);
#        }
	drawclose;
	echo "********	tex_draw_test Suite Execution Completed 	********"
}
repp_test {
	$failed =0;
	echo "------	Executing RE-PP Test Suite 	------"
	allsetup;
	if ($failed) {
		return(-1);
	}
	resetcons; buffoff; buffon
	delay; delay; delay;
	mg_vc3clearcursor;
	delay; delay; delay;
	drawsetup;
	delay;
	$testnum = "_80"
	$status		=	mg_z_tri 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_81"
	$status		=	mg_lines 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_82"
	$status		=	mg_points 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_83"
	$status		=	mg_stip_tri  
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_84"
	$status		=	mg_xblock 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_85"
	$status		=	mg_chars 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_86"
	$status		=	mg_logicop 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_87"
	$status		=	mg_dither 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_88"
	$status		=	mg_color_tri  
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;
	$testnum = "_98"
	$status = alphablend_test;
	delay;
        if ($failed) {
                return(-1);
        }
	delay;
	$testnum = "_97"
	$status = scene_test;
	delay;
        if ($failed) {
                return(-1);
        }
	led 1
	delay
	drawclose;
	echo "********	RE/PP Test Suite Execution Completed 	********"
}
rdram_mem_quick {
        $failed =0;
        report = 3;
        echo "------    Executing FRAME BUFFER QUICK Test Suite      ------"
        drawsetup
        if (mg_gfxconsole)
                $testnum = "_112"
        $status         =       mg_dma_pp -r0 -e0 -w0 -d0 -b 0x240 -p0 -x 0 -y 4 -z 12 -m 0 0
        if ($status) {
                $failed = 1;
                return (-1);
        }
}
rdram_mem {
	$failed =0;
	report = 3;
        echo "------    Executing FRAME BUFFER  Test Suite      ------"
#       Z Buffer Test
	drawsetup
	if (mg_gfxconsole)
	$testnum = "_89"
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0 -b 0x0 -p3 -x 0x0
        if ($status) {
                $failed = 1;
		return (-1);
        }
#       Color Buffer Test
	if (mg_gfxconsole)
	$testnum = "_90"
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x240 -p3 -x 0x0
        if ($status) {
                $failed = 1;
		return (-1);
        }
#	Overlay Buffer Test
	if (mg_gfxconsole)
	$testnum = "_91"
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x1c0 -p3 -x 0x0
        if ($status) {
                $failed = 1;
		return (-1);
        }
	$tmp = mg_setnumre4s -q
	if ($tmp == 2) {
#		Display Buffer-CD Test
		if (mg_gfxconsole)
	$testnum = "_92"
        	$status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x320 -p3 -x 0x0
        	if ($status) {
                	$failed = 1;
			return (-1);
        	}
#		ACC36 or AUX 0 Buffer
		if (mg_gfxconsole)
	$testnum = "_93"
        	$status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x0e0 -p3 -x 0x0
        	if ($status) {
                	$failed = 1;
			return (-1);
        	}
	}
		
        echo "********  FRAME BUFFER  Test Suite Execution Completed    ********"
	report = 4;
}
tram_mem {
	$failed =0;
	delay;
        echo "------    Executing TRAM Memory Test Suite        ------"
	delay
	mg_tram_rev_nobuff
	if ($failed) {
		echo "mg_tram_rev_nobuff failed"
		return (-1);
	}
	delay;
	$testnum = "_94"
        $status         =       mg_dma_tram -m 3 -e 0
        if ($status) {
                $failed = 1;
		return (-1);
        }
	delay
	$foo = mg_setnumre4s -q
	delay
	if ($foo == 2) {
		$testnum = "_95"
        	$status         =       mg_dma_tram -m 3 -e 0 -n 1
        	if ($status) {
                	$failed = 1;
			return (-1);
        	}
	}
}
re4flextest {
	buffon;
	$failed =0;
	if ($solid) {
        	echo "------    HQ <---> RSS Bus Test ------"
	} else {
        	echo "------    High Density Flex (HQ<->RE) Connectivity Test ------"
	}
	$testnum = "_96"
	$status		=		mg_hq3 4
        if ($status) {
                $failed = 1;
		return (-1);
        }
	resetcons; buffoff;
}
mg_test_all {
	$failed = 0;
	report=2;
        repeat 3 {
		delay;
	}
        gioslot;
	buffon
        if (mg_gfxconsole) {
                $status = mg_reset;
		$solid = mg_issolid;
                delay;
                delay;
                resetcons;
		if ($status) {
			$failed = 1;
			return (-1);
		}
        } else {
                allsetup;
		if ($failed) {
			echo "Initializing graphics failed"
			return (-1)
		}
        }

	delay;
	delay;
	$status	=	hq3test;
	if ($failed) {
			echo "hq3test FAILED"
			echo "The GD Board may be BAD"
                	return($status);
	}
	if ($oven) {
		boot -f bootp()mg_hq.pass;
	}
	$status		=	re4flextest;
	if ($failed) {
			echo "Flex Test FAILED"
			if ($solid == 0) {
				echo "The RA/RB Board may be BAD"
			} 
			resetcons; buffoff;
                	return($status);
	}
	
	
	resetcons;
	gioslot;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	delay;
	delay;
	resetcons;
	$status		=	bkend;
	if ($failed) {
			echo "bkend FAILED" 
			if ($vc3fail) {
			   echo "The GD Board may be BAD"
			   $vc3fail = 0;
			} else {
			   echo "The RA Board may be BAD"
			}
			resetcons; buffoff;
                	return($status);
	}
	if ($oven) {
		boot -f bootp()mg_bkend.pass;
	}
#	resetcons; 
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
	$ge_no = mg_queryGE;
	if ($ge_no == 2) 					# 2 GE system
	{
		echo "Testing 2GE system...."
		$testnum = "_41"
		$status		=	tge_test;
	}
	
	if ($failed) {
		echo "tge_test FAILED"
		echo "The GD Board may be BAD"
		resetcons; buffoff;
               	return($status);
	}
	
	if ($ge_no == 1) 					# 1 ge system
	{
		echo "Testing 1GE system...."
		$testnum = "_44"
		$status = ge0_test;
	}
	if ($failed) {
		echo "ge_test FAILED"
		echo "The GD Board may be BAD"
		resetcons; buffoff;
               	return($status);
	}
	
	if ($oven) {
		boot -f bootp()mg_ge.pass;
	}
	
	allsetup;
	if ($failed) {
		resetcons; buffoff;
		return(-1);
	}
        buffon
	$status		=	re4test;
	if ($failed) {
			echo "re4test FAILED"
			echo "The RA/RB Board may be BAD"
			resetcons; buffoff;
                	return(-1);
	}
	if ($oven) {
		boot -f bootp()mg_re.pass;
	}
	$status		=	dmatest;
	if ($failed) {
			echo "dmatest FAILED"
			resetcons; buffoff;
                	return($status);
	}
	if ($oven) {
		boot -f bootp()mg_dma.pass;
	}
	$status 	=	rdram_mem_quick;
	if ($failed) {
			echo "RDRAM QUICK FAILED"
			echo "The RA/RB Board may be BAD"
			resetcons; buffoff;
                	return($status);
	}
	if ($quick == 0) {
		$status 	=	rdram_mem;
		if ($failed) {
			echo "RDRAM FAILED"
			echo "The RA/RB Board may be BAD"
			resetcons; buffoff;
                	return($status);
		}
	}
	if ($oven) {
		boot -f bootp()mg_rdram.pass;
	}
	$status		=	repp_test;
	if ($failed) {
			echo "repp_test FAILED"
			echo "The RA/RB Board may be BAD"
			resetcons; buffoff;
                	return($status);
	}
	if ($oven) {
		boot -f bootp()mg_repp.pass;
	}
	delay;
	allsetup;
	if ($failed) {
		resetcons; buffoff;
		return(-1);
	}
	delay;
        delay;
	$status = mg_reset;
	if ($status) {
		$failed = 1;
		return (-1);
	}
        delay;
	resetcons; buffoff;
	buffon;
# perform TRAM memory and TEXTURE draw tests for Max/High Only
	if ($solid) {
		echo "No Texture Subsystem for MG10"
		echo "Tests for Texture Subsystem are skipped..."
	} else {
		$status = tetest
		if ($failed) {
			echo "tetest FAILED"
			echo "The RE-TE connection may be BAD"
			resetcons; buffoff;
                	return(-1);
		}
		if ($quick == 0) {
			echo "Testing TRAM memory"
        		repeat 3 {
				delay;
			}
			$status		=	tram_mem;
			if ($failed) {
				echo "tram test FAILED"
				echo "The RA/RB Board may be BAD"
				resetcons; buffoff;
                		return(-1);
			}
			if ($oven) {
				boot -f bootp()mg_tram.pass;
			}
		}
		$status		=	tex_draw_test
		delay;
		if ($failed) {
			echo "tex_draw_test FAILED"
			echo "The RA/RB Board may be BAD"
			resetcons; buffoff;
                	return(-1);
		}
		if ($oven) {
			boot -f bootp()mg_tex.pass;
		}
	}
	echo ""
	echo " All tests have passed"
	delay;
	delay;
	resetcons; buffoff;
	report=4
}
mg_all {
	$failed = 0;
	$slot = 255;
        $tmp = mg_setboard 0;
        if ($tmp) {
		$slot = 0;
		echo "Testing Impact boards in slot 0."
                mg_test_all;
        	if ($failed) {
			echo "ERROR: Failure detected on gfx in slot 0."
			if ($oven) {
				if ($volts == 0) {
				  $stmp = "bootp()mg0L" + $testnum + ".failed"
				  send_boot_msg $stmp
				}
				else if ($volts == 2) {
				  $stmp = "bootp()mg0H" + $testnum + ".failed"
				  send_boot_msg $stmp
				}
				forever wait;
			}
			return($failed);
		}
		else
		{
			echo "gfx in slot 0 passed."
			if ($oven) {
				boot -f bootp()mg_0.pass;
			}
		}
        }
	$failed = 0;
        $tmp = mg_setboard 1;
        if ($tmp) {
		$slot = 1;
		echo "Testing Impact boards in slot 1."
                mg_test_all;
	        if ($failed) {
			echo "ERROR: Failure detected on gfx in slot 1."
			if ($oven) {
				if ($volts == 0) {
				  $stmp = "bootp()mg1L" + $testnum + ".failed"
				  send_boot_msg $stmp
				}
				else if ($volts == 2) {
				  $stmp = "bootp()mg1H" + $testnum + ".failed"
				  send_boot_msg $stmp
				}
				forever wait;
			}
			return($failed);
		}
		else
		{
			echo "gfx in slot 1 passed."
			if ($oven) {
				boot -f bootp()mg_1.pass;
			}
		}
        }
}
gfx {
    $mgras = mg_probe;
    if ($mgras) {
	mg_all;
    }
    if ($gounix) {
	if ($failed == 0) {
		unix;
	}
    }
} 
gfxva {
    $gounix = 0;
    cv_low;
    gfx;
    $gounix = 1;
    cv_high;
    gfx;
}
gfx_quick {
    $gounix = 0;
    echo "----- Executing the QUICK verision of the GFX Tests -----"
    $quick = 1;
    gfx;
    $quick = 0;
    echo "----- QUICK version of the GFX Tests is DONE -----"
}
gfxva_quick {
    $gounix = 0;
    echo "----- Executing the QUICK verision of the GFX Tests with Chg Vol.-----"
    $quick = 1;
    gfxva;
    $quick = 0;
    echo "----- QUICK version of the GFX Tests with Change Voltage is DONE -----"
}
gfxdual {
	$bothslots = 1;
	gfx;
	$bothslots = 0;
}
gfx_quickdual {
	$bothslots = 1;
	gfx_quick
	$bothslots = 0;
}
gfxva_quickdual {
	$bothslots = 1;
	gfxva_quick
	$bothslots = 0;
}
#########################################################################
#	IP22 + GFX ASRS OVEN SCRIPT					#
#########################################################################
ip22_gfx_asrs {
	report=2;
	cv_low;
	boot -f bootp()voltage_low.pass
	$skip_timer =0;
	$skip_eisa = 1;
	$oven = 1;
	$volts = 0;
	$gounix = 0;
	ip22;
	if ($failed) {
		$stmp = "bootp()CPU_L" + $testnum + ".failed"
		send_boot_msg $stmp
		forever wait;
	} else {
		boot -f bootp()CPU_L.pass
	}
	cv_nom;
	if ($suite == 2) {
		gfxdual;
	} else {
		gfx;
	}
	boot -f bootp()gfx_low.done
	cv_high;
	boot -f bootp()voltage_hi.pass
	$skip_timer =1;
	$volts = 2;
	$skip_eisa = 1;
	ip22;
	if ($failed) {
		$stmp = "bootp()CPU_H" + $testnum + ".failed"
		send_boot_msg $stmp
		forever wait;
	} else {
		boot -f bootp()CPU_H.pass
	}
	if ($suite == 2) {
		gfxdual;
	} else {
		gfx;
	}
	boot -f bootp()gfx_hi.done
	cv_nom;
	boot -f bootp()start_unix;
	unix;
}
#########################################################################
#	IP22 + GFX  FUNCTION TEST & REPAIR SCRIPT			#
#########################################################################
i2frmenu {
	echo "==================================================="
	echo "WELCOME TO IP22 + GFX FUNCTION TEST & REPAIR SUITE"
	echo "==================================================="
	echo "Command	Description"
	echo "=======	==========="
	echo "ip22	IP22 tests (PM, CPU, MEM)"
	echo "ip22va	IP22 tests with automatic voltage change"
	echo ""
	echo "gfx	IMPACT tests (GFX)"
	echo "gfxva	IMPACT tests with automatic voltage change"
	echo ""
	echo "audio	Audio tests"
	echo ""
	echo "i2frmenu	To display the above menu"
	echo ""
	echo "To view the repair menu:"
	echo "	source -f bootp()mg_repair.script"
	echo ""
}
ip22_gfx_func_repair {
	report=4;
	i2frmenu;
}
$suite = mg_test_suite;
# turn on messaging to serial prot if we are on console g or G
ttyprint 1;
if (($suite == 1) || ($suite == 2)) {
	ip22_gfx_asrs;
} else {
	ip22_gfx_func_repair;
}
echo ""
