#########################################################################
#	IP28 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 "PMT5 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(fpu) {
		echo "Failure detected in fpu test"
		$failed=1;
		return(-1);
	}
	$testnum = "_008"
	if(ecc) {
		echo "Failure detected in ecc test"
		$failed=1;
		return(-1);
	}
	echo "PMT5 Processor Module Tests Passed...."
}

#########################################################################
#	Memory Tests and Scripts					#
#########################################################################
memory {
	echo "Memory tests...."
	$testnum = "_100"
	$tmp = memtest;
	if ($tmp) {
		echo "Failure detected in memtest test"
		$failed = 1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()memtest.pass;
	}
	$testnum = "_101"
	$tmp = ldram;
	if ($tmp) {
		echo "Failure detected in ldram test"
		$failed = 1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()ldram.pass;
	}
	$testnum = "_102"
	$tmp = dram;
	if ($tmp) {
		echo "Failure detected in dram test"
		$failed = 1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()dram.pass;
	}
	$testnum = "_103"
	if(lkh_aa) {
		echo "Failure detected in lkh_aa test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()lkh_aa.pass;
	}
	$testnum = "_104"
	$tmp = memtest 3
	if($tmp) {
		echo "Failure detected in local memory Kh test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()memtest_3.pass;
	}
	$testnum = "_105"
	$tmp = memtest 0
	if($tmp) {
		echo "Failure detected in Address Uniqueness test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()memtest_0.pass;
	}
	$testnum = "_106"
	$tmp = memtest 7
	if($tmp) {
		echo "Failure detected in Butterfly test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()memtest_7.pass;
	}
	$testnum = "_107"
	$tmp = memtest 9
	if($tmp) {
		echo "Failure detected in March Y test"
		$failed=1;
		return(-1);
	}
	if ($oven) {
		boot -f bootp()memtest_9.pass;
	}
	echo "Memory tests Passed...."
}

#########################################################################
#	Audio Tests and Scripts						#
#########################################################################

#########################################################################
#	MEM, INT and SCSI tests and scripts				#
#########################################################################
ip {
	echo "IP28 interrupt, duart, scsi tests...."
	$tmp = 0;

	$testnum = "_200"
	if(int2) {
		echo "Failure detected in int2 test"
		$failed=1;
		return(-1);
	}
	$testnum = "_201"
	if(hpc3) {
		echo "Failure detected in hpc3 test"
		$failed=1;
		return(-1);
	}
	if ($skip_timer !=1) {
		$testnum = "_202"
		if(clock) {
			echo "Failure detected in clock test"
			$failed=1;
			return(-1);
		}
		$testnum = "_203"
		if(timer) {
			echo "Failure detected in timer test"
			$failed=1;
			return(-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;
	}

	ttyprint 0
	$testnum = "_204"
	$tmp = duart -i1;
	if($tmp) {
		resetcons 1;
		echo "Failure detected in duart test"
		$failed=1;
		return(-1);
	}
	ttyprint 1
	if ($skip_eisa != 1) {
		$testnum = "_205"
		if(eisa) {
			echo "Failure detected in eisa test"
			$failed=1;
			return(-1);
		}
	}
	$testnum = "_206"
	$scsi_status = scsi;
	if($scsi_status) {
		echo "Failure detected in SCSI test"
		$failed=1;
		return(-1);
	}

	if ($oven == 0) {
		$testnum = "_212"
		if(print3){
			echo "Failure detected in print3 test"
			$failed=1;
			return(-1);
		}
	}
	echo "IP28 interrupt, duart, scsi tests Passed...."
}	

#########################################################################
#	ALL IP28 (PM/CPU/MEM/AUDIO/SCSI) TESTS and SCRIPTS		#
#########################################################################
ip28 {
	echo "ALL Tests in IP28...."
        $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 "PMT5 Tests FAILED"
		return(-1);
	} else if ($oven) {
		boot -f bootp()pm1.pass;
	}

	if ($oven) {
		memory;
		if($failed) {
			return(-1);
		} 
	} else {
		echo "Memory Tests...."
		$tmp = memtest;
		if ($tmp) {
			echo "MEMORY Tests FAILED"
			$failed = 1;
			return(-1);
		}
		echo "Memory Tests Passed...."
	}

	ip;
	if($failed) {
		echo "IP28 Tests FAILED"
		return(-1);
	} else if ($oven) {
		boot -f bootp()ip.done;
	}

	echo "ALL Tests in IP28 Passed...."
}

#########################################################################
#	ALL IP28 (PM/CPU/MEM/AUDIO/SCSI) WITH VOLTAGE CHANGES		#
#########################################################################
ip28va {
	$skip_timer = 0;
	$skip_eisa = 0;
	$failed =0;

	cv_low;
	ip28;
	if ($failed) {
		return(-1);
	}
	cv_high;
	ip28;
	if ($failed) {
		return(-1);
	}
}

#########################################################################
#	IMPACT GRAPHICS TESTS and SCRIPTS				#
#########################################################################
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"
		}
	}
}

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

bkendsetup {
	$failed = 0;
	echo "Calling mg_bkendreset to do some setup..."
	mg_bkendreset;
	echo "Calling mg_dacreset..."
	mg_dacreset;
	echo "Calling mg_vc3reset..."
	$status = mg_vc3reset;
	if ($status) {
                $failed = 1;
                echo; echo "VC3 reset returned an error. The VC3 may be bad"
                echo;
                return (-1);
        }
	echo "Calling mg_vc3init -t 0x107 to load 1280x1024_60 table"
	mg_vc3init -t 0x107;
	echo "Calling mg_progcmap 0x0 to load the cmaps with a linear ramp"
	mg_progcmap 0x0;
	echo "Calling mg_gammaprog 0x0 to load the gamma tables with a linear ramp"
	mg_gammaprog 0x0;
	echo "Calling mg_vc3init -t 0x107 (2nd time)"
	mg_vc3init -t 0x107;
	enabdisp
        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;
#        if ($status) {
#                $failed = 1;
#		echo "mg_hq3_initcheck";
#                return(-1);
#        }


	$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;
	     }
#	buffoff; resetcons;
}
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);
        	}
	}
#	buffoff; resetcons;
}

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";
	}
}
# End of Ge test scripts

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

#	$testnum = "_33"
#        $status 	=	mg_cmapuniqtest;
#        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 = "_39"
#	mg_stoptiming;
#	$status		=	mg_vc3init -t 0x107
#	if ($status) {
#		$failed = 1;
#		return(-1);
#	}
	$testnum = "_40"
	mg_starttiming;
	$status 	=	mg_crcwalk;
	if ($status) {
		$failed = 1;
		return(-1);
	}
#	$testnum = "_41"
#	$status 	=	mg_reset; 
#	if ($status) {
#		$failed = 1;
#		return(-1);
#	}
#
#	$testnum = "_42"
#	mg_stoptiming;
#	$status		=	mg_vc3init -t 0x130
#	if ($status) {
#		$failed = 1;
#		return(-1);
#	}
#	$testnum = "_43"
#	mg_starttiming;
#	$status 	=	mg_crcwalk;
#	if ($status) {
#		$failed = 1;
#		return(-1);
#	}
#	$testnum = "_44"
#	$status 	=	mg_reset; 
#	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);
	}

#        $status 	=	mg_ge_dma;
#	if ($status) {
#                $failed = 1;
#                return(-1);
#        }

#	DMA PIO Test
	$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 {
        $status = mg_re_rev -r 0
        if ($status) {
		$status = mg_reset;
                if ($status) {
                        $failed = 1;
                        return (-1);
                }
                delay;
                drawsetup
                mg_vc3clearcursor;

                mg_retexlut;
                echo "Checking mg_retexlut PP0 crc..."
                delay; delay; delay;
                mg_dispctrl -o1 -p0
                delay; delay; delay;
                mg_dispctrl -o0 -p1
                delay; delay; delay;
                $status = mg_crc_test -r 0x78 -g 0x19b -b 0x1c3
                if ($status) {
                        echo; echo "mg_retexlut PP0 crc FAILED"; echo
                        $failed = 1;
                        mg_dispctrl -o1 -p1
                        delay;
                        return(-1);
                }
                echo; echo "mg_retexlut PP0 crc PASSED"; echo
                echo "Checking mg_retexlut PP1 crc..."
                delay; delay; delay;
                mg_dispctrl -o1 -p1
                delay; delay; delay
                mg_dispctrl -o0 -p0
                delay; delay; delay
                $status = mg_crc_test -r 0xaf -g 0x302 -b 0x158
                if ($status) {
                        echo; echo "mg_retexlut PP1 crc FAILED"; echo
                        $failed = 1;
                        mg_dispctrl -01 -p0
                        delay;
			echo "Resetting graphics for you"
			allsetup;
                        return(-1);
                }

                echo; echo "mg_retexlut PP1 crc PASSED"; echo

                delay; delay; delay;
                mg_dispctrl -o1 -p0;
                delay; delay; delay;

		echo "Resetting graphics for you"
		allsetup
                echo; echo "mg_retexlut test PASSED"; echo

        }
}

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

#########################################################################
#	IP28 + GFX ASRS OVEN SCRIPT					#
#########################################################################
ip28_gfx_asrs {
	report=2;
	echo "=========================================="
	echo "WELCOME TO IP28 + GFX  ASRS TEST SUITE"
	echo "=========================================="
	$skip_timer =0;
	$skip_eisa = 1;
	$oven = 1;
	$volts = 0;
	$gounix = 0;
	ip28;
	if ($failed) {
		$stmp = "bootp()CPU_L" + $testnum + ".failed"
		send_boot_msg $stmp
		forever wait;
	} else {
		boot -f bootp()CPU_L.pass
	}
	if ($suite == 2) {
		gfxdual;
	} else {
		gfx;
	}
	boot -f bootp()gfx_low.done
	boot -f bootp()start_unix;
	unix;
}

#########################################################################
#	IP28 + GFX  FUNCTION TEST & REPAIR SCRIPT			#
#########################################################################
i2frmenu {
	echo "==================================================="
	echo "WELCOME TO IP28 + GFX FUNCTION TEST & REPAIR SUITE"
	echo "==================================================="
	echo "Command	Description"
	echo "=======	==========="
	echo "ip28	IP28 tests (PM, CPU, MEM)"
	echo "ip28va	IP28 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 ""
}
ip28_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)) {
	ip28_gfx_asrs;
} else {
	ip28_gfx_func_repair;
}
echo ""
