# This is an ide startup file intended for use in the field by customers
# and Field Engineers.

if ($1 == "fe") {
    report=4;
    echo "Report level set to VERBOSE";
    $is_fe = 1;
}
else {
    report=0;
    $is_fe = 0;
}
fi

# Initialize script variables
#   NOTE: At the end of the startup script each variable that is still set
#         to 2 will indicate some tests that haven't been run (like after
#         an error).
$cpufailed=2;
$fpufailed=2;
$scsifailed=2;
$gr2failed=2;
$ng1failed=2;
$impact_failed=2;

$impact_board="";
$impact_ges="";

$audiofailed=0;
$ab1failed=0;
$cc1failed=0;

# Other variables used by ng1 tests.
$ng1_rex3_failed=0;
$ng1_bt445_failed=0;
$ng1_cmap_failed=0;
$ng1_xmap9_failed=0;
$ng1_vc2_failed=0;
$ng1_vram_failed=0;
$ng1_cid_failed=0;

# THE FOLLOWING IS THE STARTUP SCRIPT FOR THE CPU DIAGNOSTICS.
#
# IN ORDER FOR THE SCRIPT TO RUN PROPERLY, THE FOLLOWING MUST BE DONE:
#	1. CONNECT THE TRANSMIT AND RECEIVE PINS ON CHANNEL A AND B OF DUART 0,
#	   CHANNEL B OF DUART 1 (FOR CHANNEL B OF DUART 1, THE REQUEST_TO_SEND
#	   AND CLEAR_TO_SEND PINS MUST ALSO BE CONNECTED).

ip22{
$cpufailed=0;
# Interrupt mask registers data test.";
if (int2) {
    if (!$report) {
	emfail 3;
	wait;
	exit;
    }
    $cpufailed=1;
}

# TLB test. Verify different tlb functions.";
if (tlb) {
    if (!$report) {
	emfail 4;
	wait;
	exit;
    }
    $cpufailed=1;
}

# UTLB miss exception test. Verify the exception generating capability of the
# mips chip during a utlb miss.
if (utlb) {
    if (!$report) {
	emfail 4;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Real time clock test. Verify the accuracy of the real time clock and the carry
# circuitry by using the timer within the ctl1 gate array.
if (clock) {
    if (!$report) {
	emfail 7;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Interval timer test. Verify the accuracy of the interval timer by using the
# real time clock.
if (timer) {
    if (!$report) {
	emfail 7;
	wait;
	exit;
    }
    $cpufailed=1;
}

# DUART 1B/modem, internal loopback test. Execute the internal loopback
# diagnostics provided by the DUART chips.
$tmp = duart -i1;
if ($tmp) {
    resetcons 1;
    if (!$report) {
	emfail 8;
	wait;
	exit;
    }
    $cpufailed=1;
}

# DUART 1B/modem, external loopback test. verify the operation of the
# DUART channels by simulating actual transmission.  JUMPERS ARE NEEDED
# TO CONNECT TRANSMIT AND RECEIVE PINS ON ALL CHANNELS, REQUEST_TO_SEND
# AND CLEAR_TO_SEND PINS ON CHANNEL B OF DUART 1.
# >> FOR FIELD ENGINEERING ONLY <<
if ($tmp) {
    resetcons 1;
    if (!$report) {
	emfail 8;
	wait;
	exit;
    }
    $cpufailed=1;
}

# EEPROM pin signal test. Verify the pin signals provided for the EEPROM.
if (nvram5) {
    if (!$report) {
	emfail 9;
	wait;
	exit;
    }
    $cpufailed=1;
}

# HPC3 peripheral controller register data test.
if (hpc3) {
    if (!$report) {
	emfail 10;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test floating point unit
$fpufailed=0;
if (fpu) {
    if (!$report) {
	emfail 5;
	wait;
	exit;
    }
    $fpufailed=1;
}

# Test parity checking mechanism
if (parity) {
    if (!$report) {
	emfail 11;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test primary data cache
if (dcache1) {
    if (!$report) {
	emfail 1;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test primary instruction cache
if (icache1) {
    if (!$report) {
	emfail 1;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test primary instruction cache functionality
if (icache2) {
    if (!$report) {
	emfail 1;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test secondary cache
if (scache1) {
    if (!$report) {
	emfail 12;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test local memory 0-4Mbytes
if (ldram) {
    if (!$report) {
	emfail 13;
	wait;
	exit;
    }
    $cpufailed=1;
}

$tmp = ldram -p
if ($tmp) {
    if (!$report) {
	emfail 13;
	wait;
	exit;
    }
    $cpufailed=1;
}

# Test local memory above the 4 Mbytes mark
if (dram) {
    if (!$report) {
	emfail 13;
	wait;
	exit;
    }
    $cpufailed=1;
}

$tmp = dram -p
if ($tmp) {
    if (!$report) {
	emfail 13;
	wait;
	exit;
    }
    $cpufailed=1;
}

if (memtest) {
    if (!$report) {
	emfail 13;
	wait;
	exit;
    }
    $cpufailed=1;
}

if (audiofield) {
	$audiofailed=1;
}

# Test SCSI devices
$status1=scsi;
$status2=xscsi;
$scsi_status=$status1 | $status2;
$scsifailed = 0;
if ($scsi_status & 257) {
# SCSI chip 0 or 1 failure
    if (!$report) {
	emfail 15;
	wait;
	exit;
    }
    $cpufailed=1;
}
if ($scsi_status & 98175) {
# 0x10000 (cabling) or any scsi device failure (not 1 or 0x100, which
# means chip failure, since for now, chip is always ID 0)
# scsi() puts the failure in a global for emfail.
    if (!$report) {
	emfail 6;
	wait;
	exit;
    }
    $scsifailed=1;
}

# END OF IP22 SCRIPT
}


# Start of GR2 diagnostics 
$mon=0
gr2_vhwinit {
#Assume that GR2 rev.2 is not used. So, can write 0x47 to bdvers.rd0
gr2_videoclk 0x47
if ($mon ==1 ) gr2_initclock 0x132;
else gr2_initclock 0x107;
fi
gr2_wrconfig 0x0
gr2_delay 3
gr2_wrconfig 0x1
gr2_vinitdac
}
gr2_initre {
	$a = gr2_getGR2ver;
	if ($a < 4) gr2_wrfifo 0 0;
	else if ($a == 4) gr2_wrfifo 0 1;
	else gr2_wrfifo 0 2;
}
gr2_initsys {
gr2_reset
gr2_vhwinit
$mon = gr2_getMonType;
if ($mon == 1) gr2_initvc1 4;
else gr2_initvc1 20;
fi
gr2_xcol
gr2_inithq
gr2_load_ucode ge
gr2_load_ucode hq
gr2_unstall
gr2_initre
}

clear {
gr2_wrfifo 35 0
gr2_wrfifo 6 0
}
gr2_quad {
gr2_wrfifo 33 0
}
gr2_fourquad {
gr2_wrfifo 34 0
}

$tmp = 0;
$gr2_failed = 0;

test_xmap{
	gr2_initsys;
	$a=gr2_txmap;
	return $a;
}

test_xmap_clut{
	gr2_initsys;
	$a=gr2_txmap_clut;
	return $a;
}

gr2 {
	$vc1_sram_failed=0;
	$tram0_failed=0;
	$tram1_failed=0;
	$tram2_failed=0;
	$tram3_failed=0;
	$tram4_failed=0;
	$tram5_failed=0;
	$tram6_failed=0;
	$tram7_failed=0;
	$tram8_failed=0;
	$tram9_failed=0;
	$tram10_failed=0;
	$hq2test_failed=0;
	$shram_failed=0;
	$ram12_failed=0;
	$seedrom_failed=0;
	$sqrom_failed=0;
	$gebus_failed=0;
	$gefloat_failed=0;
	$chkbt457_failed=0;
	$shramre3_failed=0;
	$cpushram_failed=0;
	$cpure3_failed=0;
	$vdma_failed=0;
	$ctxsw_failed=0;
	$bp_failed=0;
	$stride_failed=0 ;
	$zb_failed=0;
	$test_xmap_failed=0;
	$test_xmap_clut_failed=0;
	$quad_failed=0;
	$fourquad_failed=0;

	$gr2failed=0;
	gr2_reset;
	buffon

# HQ2 internal register 19  must read 0xdeadbeef
	gr2_rdhqint 19;

# Test VC1 SRAM 
	gr2_vhwinit
	if (gr2_vc1_sram) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$vc1_sram_failed = 1;
	}
# Test ram 0 at Ge7 at 0
	$tmp = gr2_tram 0;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram0_failed = 1;
	}
# Test ram 0 at Ge7 at 1
	$tmp = gr2_tram 1;
	if ($tmp){
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram1_failed = $tmp;
	}
# Test ram 0 at Ge7 at 2
       $tmp = gr2_tram 2;
       if ($tmp){
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram2_failed = 1;
	}
# Test ram 0 at Ge7 at 3
	$tmp = gr2_tram 3 ;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram3_failed = 1;
	}
# Test ram 0 at Ge7 at 4
	$tmp = gr2_tram 4 ;
	if ($tmp) {
	    if (!$report) {
        	emfail 2;
        	wait;
        	exit;
    	    }	
	    $tram4_failed = 1;
	}
# Test ram 0 at Ge7 at 5
	$tmp = gr2_tram 5 ;
	if ($tmp) {
	    if (!$report) {
        	emfail 2;
        	wait;
        	exit;
    	    }	
	    $tram5_failed = 1;
	}
# Test ram 0 at Ge7 at 6
	$tmp = gr2_tram 6 ;
	if ($tmp) {
	    if (!$report) {
        	emfail 2;
        	wait;
        	exit;
    	    }	
	    $tram6_failed = 1;
	}
# Test ram 0 at Ge7 at 7
	$tmp = gr2_tram 7 ;
	if ($tmp) {
	    if (!$report) {
        	emfail 2;
        	wait;
        	exit;
    	    }	
	    $tram7_failed = 1;
	}
# Test shram  
	$tmp = gr2_tram 8 ;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram8_failed = 1;
	}
# Test Hq2uram
	$tmp = gr2_tram 9 ;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram9_failed = $tmp;
	}
# Test ge7uram
	$tmp = gr2_tram 10;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$tram10_failed = $tmp;
	}
	gr2_initsys;
	clear;

# Test HQ2
	if (gr2_hq2test) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$hq2test_failed = 1;
	}
# Test shareram using Ucode
	if (gr2_shram) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$shram_failed = 1;
	}
# Test internal GE7 ram
	if (gr2_ram12) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ram12_failed =1;
	}
# Test seedrom 
	if (gr2_seedrom) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$seedrom_failed =1;
	}
# Test the squaroot rom
	if (gr2_sqrom) { 
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$sqrom_failed =1;
	}

# needed again ???

	gr2_initsys ;

# Test Ge 7 bus
	if (gr2_gebus) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$gebus_failed =1;
	}

# Test ge floating point unit
	if (gr2_gefloat) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$gefloat_failed = 1;
	}
	gr2_initsys;
	clear;
resetcons
buffoff
$err = 0;
if ($vc1_sram_failed)
{
	echo "VC1 SRAM  test failed"; 
	$err = 1
} 
if ($tram0_failed)
{ 
	echo "Ram 0 at GE7 - 0 failed "; 
	$err = 1
} 
if ($tram1_failed)
{ 
	echo "Ram 0 at GE7 - 1 failed "; 
	$err = 1
} 
if ($tram2_failed)
{ 
	echo "Ram 0 at GE7 - 2 failed "; 
	$err = 1
} 
if ($tram3_failed)
{ 
	echo "Ram 0 at GE7 - 3 failed "; 
	$err = 1
} 
if ($tram4_failed)
{ 
	echo "Ram 0 at GE7 - 4 failed "; 
	$err = 1
} 
if ($tram5_failed)
{ 
	echo "Ram 0 at GE7 - 5 failed "; 
	$err = 1
} 
if ($tram6_failed)
{ 
	echo "Ram 0 at GE7 - 6 failed "; 
	$err = 1
} 
if ($tram7_failed)
{ 
	echo "Ram 0 at GE7 - 7 failed "; 
	$err = 1
} 
if ($tram8_failed)
{ 
	echo "Share ram test failed "; 
	$err = 1
}
if ($tram9_failed)
{ 
	echo "Hq2uram  ram failed "; 
	$err = 1
}
if ($tram10_failed)  
{ 
	echo "ge7uram failed " ;
	$err = 1
}
if ($hq2test_failed)
{ 
	echo "HQ2 Test failed ";
	$err = 1
}
if ($shram_failed)
{ 
	echo "shram test failed";
	$err = 1
}
if ($ram12_failed)
{
	echo "GE7 ram 1/2 test failed "; 
	$err = 1
}
if ($seedrom_failed) 
{ 
	echo "seedrom test failed ";
	$err = 1
}
if ($sqrom_failed)
{
	echo "squaroot teste failed";
	$err = 1
}
if ($gebus_failed) 
{ 
	echo "gebus test failed";
	$err = 1
}
if ($gefloat_failed)  
{ 
	echo "gefloat test failed";
	$err = 1
}

if ( $err )
{
    if (!$report) {
       	emfail 2;
       	wait;
       	exit;
    }	
echo "HQ & GE Tests failed\n";
wait
$err=0
$gr2_failed=1
}
else echo "HQ & GE Tests passed\n"
buffon

# Test bt457 
	if (gr2_chkbt457) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$chkbt457_failed = 1;
		$err=1;
	}
# Test Shared ram and Re
	gr2_initsys
	$tmp = gr2_shramre3
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$shramre3_failed =1;
		$err=1;
	}
# Test DMA between host and GE7 shared ram

	gr2_initsys
	clear
	$tmp = gr2_cpushram
	if ($tmp)  {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$cpushram_failed =1;
		$err=1;
	}

# Test DMA between host and and RE3
	resetcons
	buffon
	gr2_initsys
	$tmp = gr2_cpure3
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$cpure3_failed =1;
		$err=1;
	}

# Test stride DMA between shram and re3
	if(gr2_ctxsw) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
	 	$ctxsw_failed =1;
		$err=1;
	}
	clear;

# Test quad drawing
	$tmp = gr2_quad
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$quad_failed =1;
		$err=1;
	}
	$tmp = gr2_fourquad
	if ($tmp){
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$fourquad_failed = 1;
		$err=1;
	}
	clear;

	resetcons
	buffoff
	if ($chkbt457_failed) echo "Bt457 test failed";
	if ($shramre3_failed) echo "shramre3 test failed"
	if ($cpushram_failed) echo "CPU shram test failed";
	if ($cpure3_failed) echo "cpure3 test failed ";
	if ($ctxsw_failed) echo "context switching test failed ";
	if ($quad_failed) echo "quad test failed";
	if ($fourquad_failed) echo "fourquad test failed";

	if ($err) {
		echo "******  PRESS RETURN TO CONTINUE OR ^C TO EXIT *********"
		wait
		$err=0
		$gr2failed=1
	}
	else echo "BT457, DMA and QUADs Tests Passed.\n"
	buffon

# Test bitplane VM2
	gr2_initsys
	if (gr2_bp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$bp_failed = 1;
		$err=1;
	}
# Test stridedma between shram and re3
	resetcons
	buffon
	gr2_initsys
	$tmp = gr2_stride
	if ($tmp)  {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$stride_failed =1 ;
		$err=1;
	}
# Test Zbuffer
	gr2_initsys
	$tmp=gr2_zb
	if($tmp)  {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$zb_failed =1;
		$err=1;
	}
# Test Xmap 
	if (test_xmap) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$test_xmap_failed =1;
		$err=1;
	}

# Test Xmap CLUT 
	if (test_xmap_clut) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$test_xmap_clut_failed =1;
		$err=1;
	}

	resetcons
	buffoff
	echo "************************* RESULTS ******************************"
	if ($bp_failed) {
		echo "bitplane test failed";
		$gr2failed = 1;
	}
	if ($stride_failed)  {
		echo "stride test failed";
		$gr2failed = 1;
	}
	if ($zb_failed) { 
		echo "Zbuffer test failed";
		$gr2failed = 1;
	}
	if ($test_xmap_failed) {
		echo "test_xmap test failed";
		$gr2failed = 1;
	}
	if ($test_xmap_clut_failed) {
		echo "test_xmap_clut test failed";
		$gr2failed = 1;
	}
	if (!$err) echo "Frame Buffer, Bit-Plane, and XMAPs Test Passed.\n"
	clear
	resetcons 
	buffoff
	if ($gr2failed) echo "ERROR: Failure detected on graphics board."
	else echo "graphics board tests passed"
	fi
	echo " *****************END OF THE TEST *****************"
}

gr2_all {
	$gfxslot = gr2_setboard 0;
	if ($gfxslot) {
		buffoff
		echo "Testing gfx in slot 0.\n"
		gr2;
		if ($gr2_failed)
			echo "ERROR: Failure detected on gfx in slot 0."
	}
	$gfxslot = gr2_setboard 1;
	if ($gfxslot) {
		buffoff
		echo "Testing gfx in slot 1.\n"
		gr2;
		if ($gr2_failed)
			echo "ERROR: Failure detected on gfx in slot 1."
	}
}
# END OF GR2 SUPPORT


# Start of NG1 diagnostics 

ng1_script {
	$ng1failed=0;
	$err=0;
	buffon

# Test Rex3
	if(ng1_rexregs) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_rex3_failed = 1;
		$err=1;
	}
# Test bt445
	if(ng1_bt445test) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_bt445_failed =1;
		$err=1;
	}
# Test cmap
	if(ng1_cmaptest) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_cmap_failed = 1;
		$err=1;
	}
# Test Xmap9
	if(ng1_xmap9test) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_xmap9_failed = 1;
		$err=1;
	}
# Test VC2 
	if(ng1_vc2test) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_vc2_failed = 1;
		$err=1;
	}
# Test VRAM
	if(ng1_vram) {
		 if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_vram_failed = 1;
		$err=1;
	}
# Test CID
	if(ng1_cid) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
		$ng1_cid_failed = 1;
		$err=1;
	}
	resetcons
	buffoff
	echo "************************* RESULTS ******************************"
	if($ng1_rex3_failed) {
		echo "Rex3 Register r/w tests failed.";
		$ng1failed = 1;
	}
	if($ng1_cmap_failed) {
		echo "Cmap r/w tests failed.";
		$ng1failed = 1;
	}
	if($ng1_xmap9_failed) {
		echo "Xmap9 r/w tests failed.";
		$ng1failed = 1;
	}
	if($ng1_vc2_failed) {
		echo "VC2 r/w tests failed.";
		$ng1failed = 1;
	}
	if($ng1_vram_failed) {
		echo "VRAM test failed.";
		$ng1failed = 1;
	}
	if($ng1_cid_failed) {
		echo "CID test failed.";
		$ng1failed = 1;
	}

	if (!$err) echo "REX3, CMAP, XMAP9, VC2, VRAM & CID Test Passed.\n"
	if ($ng1failed) echo "ERROR: Failure detected on NG1 graphics board."
	else echo "NG1 graphics board tests passed"
	fi
	echo " *****************END OF THE TEST *****************"
}

ng1 {
# test board 0 only (mostly for Indy)
	ng1_probe;
	$tmp = ng1_setboard 0;
	if ($tmp)
		ng1_script;
}

ng2 {
# test board 1 only 
        ng1_probe;
        $tmp = ng1_setboard 1;
        if ($tmp)
                ng1_script;
}


ng1_all {
	$tmp = ng1_setboard 0;
	if ($tmp) {
		echo "Testing gfx in slot 0."
		ng1_script;
		if ($ng1failed)
			echo "ERROR: Failure detected on gfx in slot 0."
	}

	$tmp = ng1_setboard 1;
	if ($tmp) {
		echo "Testing gfx in slot 1."
		ng1_script;
		if ($ng1failed)
			echo "ERROR: Failure detected on gfx in slot 1."
	}
}

# END OF NG1 SUPPORT
# START OF MGRAS TESTS
gioslot {
        $tmp = mg_setboard 0;
        if ($tmp) {
#		echo "Found boards in slot 0"
		return 1;
        }
        else {
                $tmp = mg_setboard 1;
                if ($tmp) {
#			echo "Found boards in slot 1"
			return 1;
                }
                else {
#			echo "No boards found in slot 0 or slot 1"
			return 0;
                }
        }
}

enabdisp {
mg_pokexmap -r XMAP_DIB_CTRL0 -d 0x100
}

disabdisp {
mg_pokexmap -r XMAP_DIB_CTRL0 -d 0x100
}

execbitrete {
mg_wr_rss_reg  -g0x13 -d0x0 -x
}

execbitre {
mg_wr_rss_reg  -g0x45 -d0x0 -x
}


delay {
	ide_delay -s 2;
}

gioslot0 {
        mg_setboard 0;
}


gioslot1 {
        mg_setboard 1;
}

allsetup {
        gioslot
	mg_gfxreset;
	delay;
	mg_set_0ge;
	delay;
	mg_reset;
	delay;
	delay;
	resetcons
	if (!mg_gfxconsole) {
		mg_sync_repp
        	mg_sync_pprdram
        	mg_xmapinit
		mg_rdram_ccsearch
        	mg_initppregs
		enabdisp	
		mg0_clear_color
	}
}
hq3test {
#	echo "------	Executing Hq3 Test Suite 	------"
	buffon;
	mg_gfxreset;
	delay;
	mg_set_0ge
        $status  	= 	mg_hq3_initcheck;
#        if ($status) {
#                $failed = 1;
#		echo "mg_hq3_initcheck";
#                return(-1);
#        }


        $status  	= 	mg_hq3;
        if ($status) {
                $failed = 1;
                return(-1);
        }
	mg_gfxreset;
	delay;
     	$status  	= 	mg_hq3_cp;

     	$status  	= 	mg_hq3_converter;
     	if ($status) {
                $failed = 1;
                wait ;
        }

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

#	echo "********	Hq3 Test Suite Execution Completed 	********\n"
	resetcons; buffoff
}


dactest {
#	echo "------	Executing DAC   Test Suite 	------"
        $status 	=	mg_dacreset;
        if ($status) {
                $failed = 1;
                return(-1);
        }


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


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

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

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

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

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

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

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

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

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

#	echo "********	DAC Test Suite Execution Completed 	********"
}

vc3test {
#	echo "------	Executing VC3   Test Suite 	------"
        $status 	=	mg_vc3reset;
        if ($status) {
                $failed = 1;
                return(-1);
        }

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

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

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

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

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


#	echo "********	VC3 Test Suite Execution Completed 	********"
}

cmaptest {
#	echo "------	Executing CMAP   Test Suite 	------"
        $status 	=	mg_vc3init 0x555;
        if ($status) {
                $failed = 1;
		return (-1);
        }


        $status 	=	mg_cmaprev;
        if (!$status) {
                $failed = 1;
		return (-1);
        }


        $status 	=	mg_cmapdatabus 0;
        if ($status) {
                $failed = 1;
		return (-1);
        }

        $status 	=	mg_cmapaddrsbus 0;
        if ($status) {
                $failed = 1;
		return (-1);
        }

        $status 	=	mg_cmappatrn 0;
        if ($status) {
                $failed = 1;
		return (-1);
        }

        $status 	=	mg_cmapaddrsuniq 0;
        if ($status) {
                $failed = 1;
		return (-1);
        }


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


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

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

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

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


#	echo "********	CMAP Test Suite Execution Completed 	********"
}


bkend {
	buffon;
#	echo "------	Executing Back End   Test Suite 	------"
        $status 	=	dactest;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing vc3test....\n\r";
        $status 	=	vc3test;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing cmaptest....\n\r";
#        $status 	=	cmaptest;
        if ($status) {
                $failed = 1;
                return(-1);
        }

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

        $status         =       mg_xmapdcbreg 0;
        if ($status) {
                $failed = 1;
                return(-1);
        }

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

        $tmp = mg_setnumre4s -q
        if ($tmp == 2) {
                $status         =       mg_xmapdcbreg 2;
                if ($status) {
                        $failed = 1;
                        return(-1);
                }
                $status         =       mg_xmapdcbreg 3;
                if ($status) {
                        $failed = 1;
                        return(-1);
                }
        }

        $status 	=	mg_reset; 
        if ($status) {
                $failed = 1;
                return(-1);
        }
	delay;

#	mg_pon_puts -s "testing mg_crcwalk....\n\r";
	$status 	=	mg_crcwalk;
        if ($status) {
                $failed = 1;
                return(-1);
        }

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

#	delay;
#	echo "Executing mg_vc3cursorposition test..."
	mg_reset;
	delay;
	mg_xmapinit;
	delay;
#      	mg0_clear_color -b 100
	repeat 3 {
		delay
	}
#	mg_pon_puts -s "testing mg_vc3cursorposition....\n\r";

	$status 	=	mg_vc3cursorposition;
	if ($status) {
                $failed = 1;
		resetcons; buffoff;
                return(-1);
	}
	

	resetcons; buffoff;
#	echo "********	Back End Test Suite Execution Completed 	********"

}

re4test {
	if ($is_fe == 1) {
		report = 3;
	}
#	echo "------	Executing RE4   Test Suite 	------"
	$status 	=	mg_re_status_reg;
	if ($status) {
		$failed = 1; return(-1);
	}

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

	$status 	=	mg_re_internal_ram -t0;
	if ($status) {
		$failed = 1; return(-1);
	}

	$status 	=	mg_re_internal_ram -t1;
	if ($status)  {
		$failed = 1; return(-1);
	}

	$status 	=	mg_re_internal_ram -t2;
	if ($status) {
		$failed = 1; return(-1);
	}

	$status 	=	mg_re_internal_ram -t3;
	if ($status) {
		$failed = 1; return(-1);
	}


	$status 	=	mg_re_internal_ram -t4;
	if ($status) {
		$failed = 1; return(-1);
	}

	$status 	=	mg_re_internal_ram -t5;
	if ($status) {
		$failed = 1; return(-1);
	}

#	echo "********	RE4 Test Suite Execution Completed 	********"
	if ($is_fe == 1) {
		report = 4;
	}
}

dmatest {
#	echo "------	Executing DMA Test Suite 	------"
        $status 	=	mg_host_hqdma;
        if ($status) {
                $failed = 1;
                return(-1);
        }


        $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
	$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 	********"
}


tramtest {
#	echo "------	Executing TRAM Test Suite 	------"

#	TRAM REV
	$status 	=	mg_dma_tram -e1 -p -r
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	TRAM RAM TEST
	$status 	=	mg_dma_tram -e0  -w
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	echo "********	TRAM Test Suite Execution Completed 	********"
}

# allows colors to be correct for drawings
drawsetup {
	delay;
#	mg_gfxreset;
#	mg_set_0ge;
#	mg_reset;
	delay;
	delay;
	mg_xmapinit;
}

drawclose {
	delay;
#	resetcons;
	delay;
	delay;
}

tex_draw_test {
#	echo "------	Executing tex_draw_test  Suite 	------"

#	mg_pon_puts -s "testing mg_notex_line....\n\r";
	drawsetup;
	$status		=	mg_notex_line
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_notex_poly....\n\r";
	delay;
	$status		=	mg_notex_poly
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_poly....\n\r";
	delay;
	$status		=	mg_tex_poly 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_id....\n\r";
	delay;
	$status		=	mg_tex_1d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_3d....\n\r";
	delay;
	$status		=	mg_tex_3d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_scistri....\n\r";
	delay;
	$status		=	mg_tex_scistri
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_linegl....\n\r";
	delay;
	$status		=	mg_tex_linegl
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_load....\n\r";
	delay;
	$status		=	mg_tex_load
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_persp....\n\r";
	delay;
	$status		=	mg_tex_persp
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_mag....\n\r";
	delay;
	$status		=	mg_tex_mag 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_detail....\n\r";
	delay;
	$status		=	mg_tex_detail
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_bordertall....\n\r";
	delay;
	$status		=	mg_tex_bordertall
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_lut4d....\n\r";
	delay;
	$status		=	mg_tex_lut4d
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_borderwide....\n\r";
	delay;
	$status		=	mg_tex_borderwide
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing mg_tex_mddma....\n\r";
	delay;
	$status		=	mg_tex_mddma
	delay
        if ($status) {
                $failed = 1;
                return(-1);
        }

#	mg_pon_puts -s "testing drawclose....\n\r";
	drawclose;

#	echo "********	tex_draw_test Suite Execution Completed 	********"
}

repp_test {
#	echo "------	Executing RE-PP Test Suite 	------"
	drawsetup;
	$status		=	mg_z_tri 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_lines 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_points 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_stip_tri  
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_xblock 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_chars 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_logicop
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_dither
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay;
	$status		=	mg_color_tri 
	delay;
        if ($status) {
                $failed = 1;
                return(-1);
        }

	delay
	drawclose;

#	echo "********	RE/PP Test Suite Execution Completed 	********"
}

tex_load {
#report=3
mg_hq3_RegWr 0x50080 0x4c0004
mg_hq3_RegWr 0x50080 0x201
mg_wr_rss_reg  -g0x112 -d0x00000004
mg_wr_rss_reg  -g0x111 -d0x0004081b
mg_wr_rss_reg  -g0x180 -d0x00000180
mg_wr_rss_reg  -g0x18a -d0x00000000
mg_wr_rss_reg  -g0x18f -d0x00000000
mg_wr_rss_reg  -g0x1a0 -d0x00000000
mg_wr_rss_reg  -g0x1a1 -d0x00004006
mg_wr_rss_reg  -g0x1a2 -d0x00000230
mg_wr_rss_reg  -g0x1a7 -d0x00000000
mg_wr_rss_reg  -g0x1a3 -d0x00000000
mg_wr_rss_reg  -g0x1a4 -d0x00000000
mg_wr_rss_reg  -g0x1a3 -d0x00000000
mg_wr_rss_reg  -g0x1a5 -d0x00000000
mg_wr_rss_reg  -g0x1a9 -d0x00000008
mg_wr_rss_reg  -g0x1aa -d0x00000004
mg_wr_rss_reg  -g0x1ab -d0x00000000
mg_wr_rss_reg  -g0x1ac -d0x00000000
mg_wr_rss_reg  -g0x153 -d0x00040008
mg_wr_rss_reg  -g0x158 -d0x00040008
mg_wr_rss_reg  -g0x159 -d0x00400080
mg_hq3_RegWr 0x50080 0x4a0204
mg_hq3_RegWr 0x50080 0x20
mg_hq3_RegWr 0x50080 0x4a0604
mg_hq3_RegWr 0x50080 0x4
mg_wr_rss_reg  -g0x102 -d0x00005555 -e0x00000005 -p
#mg_wr_rss_reg  -g0x102 -d0x00000005 
mg_wr_re_cmd -c 0x20
mg_wr_re_data -l 0xff0000ff -h 0x00ff00ff
mg_wr_re_data -l 0x0000ffff -h 0xffffffff
mg_wr_re_data -l 0xff0000ff -h 0x00ff00ff
mg_wr_re_data -l 0x0000ffff -h 0xffffffff
mg_wr_re_cmd -c 0x20
mg_wr_re_data -l 0x00ff00ff -h 0x0000ffff
mg_wr_re_data -l 0xffffffff -h 0xff0000ff
mg_wr_re_data -l 0x00ff00ff -h 0x0000ffff
mg_wr_re_data -l 0xffffffff -h 0xff0000ff
mg_wr_re_cmd -c 0x20
mg_wr_re_data -l 0x0000ffff -h 0xffffffff
mg_wr_re_data -l 0xff0000ff -h 0x00ff00ff
mg_wr_re_data -l 0x0000ffff -h 0xffffffff
mg_wr_re_data -l 0xff0000ff -h 0x00ff00ff
mg_wr_re_cmd -c 0x20
mg_wr_re_data -l 0xffffffff -h 0xff0000ff
mg_wr_re_data -l 0x00ff00ff -h 0x0000ffff
mg_wr_re_data -l 0xffffffff -h 0xff0000ff
mg_wr_re_data -l 0x00ff00ff -h 0x0000ffff
#report=4
}

draw_tri_tex {
#report=3
mg_wr_rss_reg  -g0x110 -d0x00005000
mg_wr_rss_reg  -g0x112 -d0x00000004
mg_wr_rss_reg  -g0x111 -d0x00040813
mg_wr_rss_reg  -g0x180 -d0x00014180
mg_wr_rss_reg  -g0x190 -d0x00000000
mg_wr_rss_reg  -g0x191 -d0x00000000
mg_wr_rss_reg  -g0x190 -d0x00000000
mg_wr_rss_reg  -g0x192 -d0x00000000
mg_wr_rss_reg  -g0x18b -d0x00000000
mg_wr_rss_reg  -g0x18c -d0x00008008
mg_wr_rss_reg  -g0x17b -d0x00000000
mg_wr_rss_reg  -g0x113 -d0xffffffff
mg_wr_rss_reg  -g0x114 -d0xffffffff
mg_wr_rss_reg  -g0x115 -d0x00000000
mg_wr_rss_reg  -g0x142 -d0x00000000
mg_wr_rss_reg  -g0x143 -d0x00000000
mg_wr_rss_reg  -g0x144 -d0x00000000
mg_wr_rss_reg  -g0x145 -d0x00000000
mg_wr_rss_reg  -g0x146 -d0x00000000
mg_wr_rss_reg  -g0x147 -d0x000004ff
mg_wr_rss_reg  -g0x148 -d0x000003ff
mg_wr_rss_reg  -g0x149 -d0x000004ff
mg_wr_rss_reg  -g0x14a -d0x000003ff
mg_wr_rss_reg  -g0x14b -d0x000004ff
mg_wr_rss_reg  -g0x14c -d0x000003ff
mg_wr_rss_reg  -g0x14d -d0x000004ff
mg_wr_rss_reg  -g0x14e -d0x000003ff
mg_wr_rss_reg  -g0x14f -d0x00000000
mg_wr_rss_reg  -g0x156 -d0xffffffff
mg_wr_rss_reg  -g0x157 -d0xffffffff
mg_wr_rss_reg  -g0x159 -d0x00040000
mg_wr_rss_reg  -g0x15a -d0xffffffff
mg_wr_rss_reg  -g0x15b -d0x000f0000
mg_wr_rss_reg  -g0x160 -d0x00000000
mg_wr_rss_reg  -g0x161 -d0x0c004203
mg_wr_rss_reg  -g0x162 -d0x00000000
mg_wr_rss_reg  -g0x163 -d0xfffbffff
mg_wr_rss_reg  -g0x164 -d0x00000000
mg_wr_rss_reg  -g0x165 -d0x80000001
mg_wr_rss_reg  -g0x165 -d0x58840000
mg_wr_rss_reg  -g0x166 -d0x00000007
mg_wr_rss_reg  -g0x167 -d0x0000ffff
mg_wr_rss_reg  -g0x168 -d0x0ffffff1
mg_wr_rss_reg  -g0x169 -d0x00000007
mg_wr_rss_reg  -g0x16a -d0x00000000
mg_wr_rss_reg  -g0x16d -d0x000c8240
mg_wr_rss_reg  -g0x16e -d0x0000031e
mg_wr_rss_reg  -g0x182 -d0x00000000
mg_wr_rss_reg  -g0x183 -d0x00000000
mg_wr_rss_reg  -g0x186 -d0x00000000
mg_wr_rss_reg  -g0x18a -d0x00000000
mg_wr_rss_reg  -g0x18f -d0x00000000
mg_wr_rss_reg  -g0x80  -d0x00004000
mg_wr_rss_reg  -g0x81  -d0x00000000
mg_wr_rss_reg  -g0x82  -d0x00004000
mg_wr_rss_reg  -g0x83  -d0x00000000
mg_wr_rss_reg  -g0x84  -d0x0000000f
mg_wr_rss_reg  -g0x85  -d0x03fff000
mg_wr_rss_reg  -g0x86  -d0x00000000
mg_wr_rss_reg  -g0x87  -d0x00000000
mg_wr_rss_reg  -g0x88  -d0x00000000
mg_wr_rss_reg  -g0x89  -d0x00000000
mg_wr_rss_reg  -g0x8a  -d0x00000000
mg_wr_rss_reg  -g0x8b  -d0x00000000
mg_wr_rss_reg  -g0x8c  -d0x0000003f
mg_wr_rss_reg  -g0xc0  -d0x00000000
mg_wr_rss_reg  -g0xc1  -d0x00000000
mg_wr_rss_reg  -g0xc2  -d0x00000020
mg_wr_rss_reg  -g0xc3  -d0x00000000
mg_wr_rss_reg  -g0xc4  -d0x00000020
mg_wr_rss_reg  -g0xc5  -d0x00000000
mg_wr_rss_reg  -g0xc6  -d0x00000000
mg_wr_rss_reg  -g0xc7  -d0x00000000
mg_wr_rss_reg  -g0xc8  -d0x00000000
mg_wr_rss_reg  -g0xc9  -d0x00000000
mg_wr_rss_reg  -g0xca  -d0x00000000
mg_wr_rss_reg  -g0xcb  -d0x00000000
mg_wr_rss_reg  -g0x068 -d0x00000000
mg_wr_rss_reg  -g0x069 -d0x00000000
mg_wr_rss_reg  -g0x004 -d0x47400100
mg_wr_rss_reg  -g0x005 -d0x47400100
mg_wr_rss_reg  -g0x006 -d0x00000000
mg_wr_rss_reg  -g0x007 -d0x00000000
mg_wr_rss_reg  -g0x008 -d0x00000000
mg_wr_rss_reg  -g0x009 -d0x00000000
mg_wr_rss_reg  -g0x00a -d0x00000000
mg_wr_rss_reg  -g0x00b -d0x00000000
mg_wr_rss_reg  -g0x000 -d0x47400100
mg_wr_rss_reg  -g0x001 -d0x47440000
mg_wr_rss_reg  -g0x002 -d0x47440000
mg_wr_rss_reg  -g0x003 -d0x47440000
mg_wr_rss_reg  -g0x05c -d0x00fff000
mg_wr_rss_reg  -g0x05d -d0x00fc1933
mg_wr_rss_reg  -g0x05e -d0x00028f33
mg_wr_rss_reg  -g0x05f -d0x00000000
mg_wr_rss_reg  -g0x060 -d0x00000000
mg_wr_rss_reg  -g0x061 -d0x00000000
mg_wr_rss_reg  -g0x062 -d0xfffae19a
mg_wr_rss_reg  -g0x063 -d0xfffd70cd
mg_wr_rss_reg  -g0x064 -d0x00000000
mg_wr_rss_reg  -g0x065 -d0x00051e66
mg_wr_rss_reg  -g0x066 -d0x00000000
mg_wr_rss_reg  -g0x067 -d0x00000000
mg_wr_rss_reg  -g0x181 -d0x00002323
#report=4
}

clr {
mg0_clear_color
}

rdram_cur_value{
#report=3
mg_wr_rss_reg -g 0x15c -d 0x2c000161
mg_wr_rss_reg -g 0x15d -d 0x4300
mg_wr_rss_reg -g 0x15c -d 0x2300000c
mg_wr_rss_reg -g 0x15d -d 0x404080c2
mg_wr_rss_reg -g 0x15c -d 0x2c000161
mg_wr_rss_reg -g 0x15d -d 0x4200
#report=4
}



draw_tex_scene {
#	mg_pon_puts -s "testing tex_load....\n\r";
	tex_load;
#	mg_pon_puts -s "testing draw_tri_tex....\n\r";
	draw_tri_tex;
#	mg_pon_puts -s "testing execbitrete....\n\r";
	execbitrete;
}

rdram_mem {
	if ($is_fe == 1) {
		report = 3;
	}
#	echo "------    Executing FRAME BUFFER  Test Suite      ------"
#       Z Buffer Test

	drawsetup
#	if (mg_gfxconsole)
#		mg_pon_puts -s "testing mg_dma_pp Z Buffer....\n\r";
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0 -b 0x0 -p3
        if ($status) {
                $failed = 1;
		return (-1);
        }

#       Color Buffer Test
#	if (mg_gfxconsole)
#		mg_pon_puts -s "testing mg_dma_pp Color Buffer....\n\r";
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x240 -p3
        if ($status) {
                $failed = 1;
		return (-1);
        }

#	Overlay Buffer Test
#	if (mg_gfxconsole)
#		mg_pon_puts -s "testing mg_dma_pp Overlay Buffer....\n\r";
        $status         =       mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x1c0 -p3
        if ($status) {
                $failed = 1;
		return (-1);
        }

	$tmp = mg_setnumre4s -q
        if ($tmp == 2) {
#               Display Buffer-CD Test
                $status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x320 -p3
                if ($status) {
                        $failed = 1;
                        return (-1);
                }
#               ACC36 or AUX 0 Buffer
                if ($status) {
                        $failed = 1;
                        return (-1);
                }
        }

#	echo "********  FRAME BUFFER  Test Suite Execution Completed    ********"
	if ($is_fe == 1) {
		report = 4;
	}
}

tram_mem {
	delay;
#	echo "------    Executing TRAM Memory Test Suite        ------"
	delay;
        $status         =       mg_dma_tram -m 3 -e 0
        if ($status) {
                $failed = 1;
		return (-1);
        }
	delay
        $foo = mg_setnumre4s -q
        delay
        if ($foo == 2) {
                $status         =       mg_dma_tram -m 3 -e 0 -n 1
                if ($status) {
                        $failed = 1;
                        return (-1);
                }
        }
}

re4flextest {
#	echo "------    High Density Flex Connectivity Test ------"
	$status		=		mg_hq3 4
        if ($status) {
                $failed = 1;
        }
}


mg_test_all {
	$failed = 0;
#	if (mg_gfxconsole) {
#		report=2;
#	} else {
#		report=2;
#	}
        repeat 3 delay;
        gioslot;
        if (mg_gfxconsole) {
                mg_reset;
                delay;
                delay;
                resetcons;
        } else {
                allsetup;
        }

	buffon
#	mg_pon_puts -s "Start mg_test_all test script ....\n\r";
	delay;
	delay;
#	mg_pon_puts -s "testing re4flextest....\n\r";
	$status		=	re4flextest;
	if ($failed) {
		echo "Impact RE4 flex cable test failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
               	return($status);
	}
	
#	mg_pon_puts -s "testing hq3test....\n\r";
	$status	=	hq3test;
	if ($failed) {
		echo "Impact HQ3 tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return($status);
	}
	
#	mg_pon_puts -s "testing bkend....\n\r";
	resetcons;
	gioslot;
	mg_reset;
	delay;
	delay;
	resetcons;
	$status		=	bkend;
	if ($failed) {
		echo "Impact back-end tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return($status);
	}

	allsetup;
        buffon

#	mg_pon_puts -s "\rtesting re4test....\n\r";
	$status		=	re4test;
	if ($failed) {
		echo "Impact RE4 tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return(-1);
	}
#	mg_pon_puts -s "testing dmatest....\n\r";
	$status		=	dmatest;
	if ($failed) {
		echo "Impact DMA tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return($status);
	}

#	mg_pon_puts -s "testing rdram_mem....\n\r";
	$status 	=	rdram_mem;
	if ($failed) {
		echo "Impact RDRAM tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return($status);
	}

#	mg_pon_puts -s "testing repp_test....\n\r";
	$status		=	repp_test;
	if ($failed) {
		echo "Impact RE/PP tests failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return($status);
	}

#	mg_pon_puts -s "testing tex_draw_test....\n\r";
	$status		=	tex_draw_test
	if ($failed) {
		echo "Impact Texture draw test failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return(-1);
	}
	
	delay;

	allsetup ;
	delay;
        delay;
	mg_reset;
        delay;
	resetcons; buffoff;
	buffon;

#	echo "Testing TRAM memory"
	repeat 3 delay;
#	mg_pon_puts -s "testing tram_mem....\n\r";
	$status		=	tram_mem;
	if ($failed) {
		echo "Impact Texture RAM test failed."
		resetcons; buffoff;
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
                return(-1);
	}

#	mg_pon_puts -s "All tests have passed....\n\r";
#	echo " All tests have passed"
	delay;
	delay;
	mg_reset;
	resetcons; buffoff;
#	report=4
}

impact {
	$impact_failed = 2;
	$impact_flag = 0;
	$failed = 0;
        $tmp = gioslot;
        if ($tmp) {
		$impact_flag = 1;
		echo "Testing Impact graphics."
                mg_test_all;
        	if ($failed) {
			echo "ERROR: Failure detected on Impact board"
			$impact_failed = 1;	
		}
		else
		{
			$impact_failed = 0;	
					
		}
        }

# XXX not really dual head yet -- fix gioslot
#	$failed = 0;
#        $tmp = mg_setboard 1;
#        if ($tmp) {
#		$impact_flag = 1;
#		echo "Testing Impact graphics in slot 1."
#                mg_test_all;
#	        if ($failed) {
#			echo "ERROR: Failure detected on gfx in slot 1."
#			$impact_failed = 1;
#		}
#		else
#		{
#			$impact_failed = 0;
#		}
#        }
}

# END OF IMPACT SUPPORT

# Here lies what is actually executed at start-up
hinv;
echo "";

ip22;

$express = gr2_probe;
$newport=ng1_probe;
$mardi_gras = mg_probe;

if ($newport) {
    ng1_all;
}
if ($express) {
    gr2_all;
}

if ($mardi_gras) {
   impact;
}

echo "TEST RESULTS:";
if ($cpufailed == 1) echo "Failure detected on CPU board.";
if ($cpufailed == 2) echo "CPU tests NOT completed.";
if (!$cpufailed) echo "CPU tests completed.";

if ($fpufailed == 1) echo "Failure detected on FPU.";
if ($fpufailed == 2) echo "FPU tests NOT completed.";
if (!$fpufailed) echo "FPU tests completed.";

if ($audiofailed == 1) echo "Audio failure or no audio is installed (server models).";
if ($audiofailed == 0) echo "Audio tests completed.";

if ($scsifailed == 1) echo "Failure detected on SCSI device[s].";
if ($scsifailed == 2) echo "SCSI tests NOT completed.";
if (!$scsifailed) echo "SCSI tests completed.";

if ($express) {
    if ($gr2failed == 1) echo "Failure detected on GR2 graphics board.";
    if ($gr2failed == 2) echo "GR2 graphics board tests NOT completed.";
    if (!$gr2failed) echo "GR2 graphics board tests completed.";
}
if ($newport) {
    if ($ng1failed == 1) echo "Failure detected on NG1 graphics board.";
    if ($ng1failed == 2) echo "NG1 graphics board tests NOT completed.";
    if (!$ng1failed) echo "NG1 graphics board tests completed.";
}
if ($mardi_gras) {
    if ($impact_failed == 1) echo "Failure detected on Impact graphics board.";
    if ($impact_failed == 2) echo "Impact graphics board tests NOT completed.";
    if (!$impact_failed) echo "Impact graphics board tests completed.";
}
fi

wait "Diagnostics completed";
