//**************************************************************************************
//UTVFC.TST
//Rev. B
//V.Vysin                                                      June 19.1978
//Main Test Program and Subroutines for UTVFC Controller Module
//**************************************************************************************


//**************************************************************************************
//To include the following definition files in the compilation
get "tester.d"
get "UTVFC.d"

//**************************************************************************************
//To define bus structure
//{CTask: CTask.0, CTask.1, CTask.2, CTask.3}
//{IAddr: Iaddr.0, Iaddr.1, Iaddr.2, Iaddr.3, Iaddr.5, Iaddr.6, Iaddr.7}
//{IDataM: Idata.00, Idata.01, Idata.02, Idata.03, Idata.04, Idata.05, Idata.06, Idata.07}
//{IDataL:  Idata.08, Idata.09, Idata.10, Idata.11, Idata.12, Idata.13, Idata.14, Idata.15}
//{IData0: Idata.00, Idata.01, Idata.02, Idata.03}
//{IData1: Idata.04, Idata.05, Idata.06, Idata.07}
//{IData2: Idata.08, Idata.09, Idata.10, Idata.11}
//{IData3: Idata.12, Idata.13, Idata.14, Idata.15}
//{ODataM: Odata.00, Odata.01, Odata.02, Odata.03, Odata.04, Odata.05, Odata.06, Odata.07}
//{ODataL:  Odata.08, Odata.09, Odata.10, Odata.11, Odata.12, Odata.13, Odata.14, Odata.15}
//{OData0: Odata.00, Odata.01, Odata.02, Odata.03}
//{OData1: Odata.04, Odata.05, Odata.06, Odata.07}
//{OData2: Odata.08, Odata.09, Odata.10, Odata.11}
//{OData3: Odata.12, Odata.13, Odata.14, Odata.15}
//{Clocks: ClkCR', ClkStart', ClkIAR', WriteHorCont', WriteOddBuf', WriteEvenBuf'}
//{WakeP' : WakeP1', WakeP2', WakeP3'}


//**************************************************************************************
//To define the global variables
static
[
	pass = 0
	BPLevel = 9
	truntime = nil
	starttime = nil
	runtime = nil
	testtime = nil
	looping = false
	cont = false
	testno = 11
	cr=0
]


//**************************************************************************************
//Main program for UTVFC Controller module test
let main() be
[
//Heading
	L1: pass = pass + 1
	DisplayString(FORMATN("*nUTVFC Module Test for H Revision: pass <D>*nOn BREAKPOINT, press any key to continue.",pass))
	DisplayString("*nSET-UP INSTRUCTIONS are Breakpoint Level 9.")
	SetBPLevel()

//Set up instructions
	if pass eq 1 do
	[
		DisplayString("*n")
		DisplayString("*nReplace the oscillator platform @ u7")
		DisplayString("*nby a dummy platform(which grounds crystal output ! ! ! ! ) ! ! ! ")
		DisplayString("*nDuring the test,we  are driving AllowWU")
		DisplayString("*nand this in turn would drive NClk crazy")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*nAttach pull-up resistor clip to S38 at A-18") 
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*nConnect Test Probes as follows:")
		DisplayString("*n Test probe B clips to positions B-16")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe C clips to positions F-15")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe D clips to positions F-12")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe E clips to positions E-6")
		SpaceDisplay(1)
		DisplayString("*n Particularly, the clip marked ECL-ONLY to position u23 -- THIS TEST IS NOT CHECKED ON MULTIWIRE BOARDS")
		Breakpoint(9)
	]
	truntime = 0
	testno = 11
	if cont eq false do
	[
		SelectTest()
	]
	L2: TRun()
	testno = testno + 1
	test testno le 99
	ifso [ goto L2 ]
	ifnot
	[
		DisplayString(FORMATN("*nUTVFC Module Test: <D> passes completed.*nTotal Run time =  <OCT>b miliseconds.", pass, truntime))
		RepeatSelect()
		goto L1
	]
]
//**************************************************************************************
//Subroutines

//Operating Functions
and Breakpoint(level, x, y, z, ch; numargs na) be
unless cont do
[
	DefaultArgs(lv na, -1, 0, 0, 0, 0)
	if level eq BPLevel do
	[
		test na eq 1
		ifso
		[
			DisplayString(FORMATN("  BREAKPOINT <D>!", level))
			while Endofs(keys) do [ ]
			Gets(keys)
		]
		ifnot
		[
			test ch eq 0
			ifso
			[
				DisplayString(FORMATN("*nBREAKPOINT <D> <B> <B> <B>", level, x, y, z))
				while Endofs(keys) do [ ]
				Gets(keys)
			]
			ifnot
			[
				DisplayString(FORMATN("*nBREAKPOINT <D> <B> <B> <B>", level, x, y, z))
				SetBPLevel()
			]
		]
	]
]

and SetBPLevel() be
[
unless cont do
	[
		DisplayString(FORMATN("*nSET BREAKPOINT LEVEL to 0 thru 9; any other key keeps present level.*nPRESENT LEVEL = <D>.", BPLevel))
		while Endofs(keys) do [ ]
		let ch = Gets(keys)
		switchon (ch & #177) into
		[
			case $0: BPLevel = 0; endcase;
			case $1: BPLevel = 1; endcase;
			case $2: BPLevel = 2; endcase;
			case $3: BPLevel = 3; endcase;
			case $4: BPLevel = 4; endcase;
			case $5: BPLevel = 5; endcase;
			case $6: BPLevel = 6; endcase;
			case $7: BPLevel = 7; endcase;
			case $8: BPLevel = 8; endcase;
			case $9: BPLevel = 9; endcase;
		]
	]
]

and SelectTest() be
[
	DisplayString("*nType in desired starting Test Number.")
	DisplayString("*nAny keys other than 1 thru 9 cause start at Test 11")
	SpaceDisplay(3)
	let x = false
	while Endofs(keys) do [ ]
	let ch = Gets(keys)
	switchon (ch & #177) into
	[
		case $1: testno = 10; endcase;
		case $2: testno = 20; endcase;
		case $3: testno = 30; endcase;
		case $4: testno = 40; endcase;
		case $5: testno = 50; endcase;
		case $6: testno = 60; endcase;
		case $7: testno = 70; endcase;
		case $8: testno = 80; endcase;
		case $9: testno = 90; endcase;
		default: x = true; endcase;
	]
	unless x do
	[
		while Endofs(keys) do [ ]
		let ch = Gets(keys)
		switchon (ch & #177) into
		[
			case $1: testno = testno + 1; endcase;
			case $2: testno = testno + 2; endcase;
			case $3: testno = testno + 3; endcase;
			case $4: testno = testno + 4; endcase;
			case $5: testno = testno + 5; endcase;
			case $6: testno = testno + 6; endcase;
			case $7: testno = testno + 7; endcase;
			case $8: testno = testno + 8; endcase;
			case $9: testno = testno + 9; endcase;
			default: x = true; endcase;
		]
	]
	if x do [ testno = 11 ]
	DisplayString(FORMATN("*nStarting Test selected = <D>", testno))
	DisplayString("*nIf looping desired on selected test depress l;  any other key continues to next test.")
	SpaceDisplay(3)
	while Endofs(keys) do [ ]
	let ch = Gets(keys)
	switchon (ch & #177) into
	[
		case $l:
		case $L: looping = true; endcase
	]
	if looping eq true do
	[
		DisplayString(FORMATN("*nTEST <D> LOOPING; depress any key to quit.", testno))
		SpaceDisplay(4)
	]
]
and TRun() be		//Add new tests here
[
	switchon testno into
	[
		case 11: Test11(); endcase;
		case 12: Test12(); endcase;
		case 13: Test13(); endcase;
		case 21: Test21(); endcase;
		case 22: Test22(); endcase;
		case 23: Test23(); endcase;
		case 31: Test31(); endcase;
		case 32: Test32(); endcase;
		case 33: Test33(); endcase;
		case 34: Test34(); endcase;
		case 35: Test35(); endcase;
		case 41: Test41(); endcase;
		case 42: Test42(); endcase;
		case 43: Test43(); endcase;
		case 44: Test44(); endcase;
		case 51: Test51(); endcase;
		case 52: Test52(); endcase;
		case 53: Test53(); endcase;
		case 54: Test54(); endcase;
		case 61: Test61(); endcase;
		case 62: Test62(); endcase;
		case 63: Test63(); endcase;
		case 64: Test64(); endcase;
	]
]
and RepeatSelect() be
[
	test cont
	ifso
	[
		DisplayString("*nIN CONTINOUS*nDepress d to discontinue; q to quit.*n")
		Delay(2)
	]

	ifnot
	[
		DisplayString("*nDepress q to quit;*n          c to run continuously;*n          any other key to repeat.")
		while Endofs(keys) do [ ]
	]

	unless Endofs(keys) do
	[
		let ch = Gets(keys)
		switchon (ch & #177) into
		[
			case $c:
			case $C: cont = true; endcase;
			case $d:
			case $D: cont = false; endcase
			case $q:
			case $Q: finish
		]
	]
]

and Delay(m) be
[
	for j = 0 to m do [ for i = 0 to #77777 do [ ] ]
]
and SpaceDisplay(lines) be
[
	for i = 1 to lines do
	[
		DisplayString("*n")
	]
]

and Start(n; numargs na) be		//if n not entered, UTVFC is reset
[
//Set up the title display
	if looping eq false do
   [ 
      DisplayString(FORMATN("*nTEST <D> RUNNING", testno))
   ]

//Start to calculate the run time
	if not looping do
	[
		testtime = 0
		let tv = vec 2
		Timer(tv)
		starttime = tv!1
	]

//Set up initial conditions
	{RamClockFeed'}=1
	{EdgeClockFeed'}=1
	{Phase1Next'}=1
	{MC2StartXport}=0
	{AdvancePipe'}=1
	{SRClock}=1
	{IValid'}=1
	{OValid'}=1
	{IOStrobe}=0
	if na eq 0 do
	[
		{RUN} = 0
		Clocks()
		Clocks()
	]
	{RUN} = 1
	EClock()
]

//Comparison routine
and Compare(item, is, sb, msg, IDno, index; numargs na) be
[
	DefaultArgs(lv na, -3, "No data.", 0, 0, 0)
	if is eq sb then return
	let tv = vec 2
	Timer(tv)
	runtime = tv!1 - starttime
	truntime = truntime + runtime
	testtime = testtime + runtime
	test looping
	ifso
	[
		unless Endofs(keys) do
		[
			Gets(keys)
			finish
		]
		Restart()
		goto TRun()
	]
	ifnot
	[
		DisplayString(FORMATN("*nFAILURE: SubTest <D>.<D>.<D>; <S> is <B>b; Should be = <B>b.  <S>", testno, IDno, index, item, is, sb, msg))
		SpaceDisplay(2)
		DisplayString("*nDepress q to quit; l to loop from start of test to failure; any other key to continue.")
		Delay(1)
		if cont eq false do [] repeatwhile Endofs(keys) 
		unless Endofs(keys) do
		[
			let com = Gets(keys)
			switchon (com & #177) into
			[
				case $l:
				case $L: looping = not looping; endcase;
				case $q:
				case $Q: finish
			]
		]
		if looping eq true do
		[
			DisplayString(FORMATN("*nLOOPING TEST <D>; depress any key to quit.", testno))
			SpaceDisplay(4)
			Restart()
			goto TRun()
		]
		Restart()
	]
]


and Restart() be
[
//Start to calculate the run time
	let tv = vec 2
	Timer(tv)
	starttime = tv!1
]

and Stop() be			//Stop and total the run time for each test
[
	if looping do
	[
		unless Endofs(keys) do
		[
			Gets(keys)
			finish
		]
		goto TRun()
	]
	let tv = vec 2
	Timer(tv)
	runtime = tv!1 - starttime
	truntime = truntime + runtime
	testtime = testtime + runtime
	DisplayString(FORMATN("*nTEST <D> COMPLETE; Test Run Time = <D> milliseconds", testno, testtime))
	Breakpoint(1)
]