//**************************************************************************************
//ECLutvfc.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 "ECLutvfc.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 (ECL part)for H Revision: pass <D>*nOn BREAKPOINT, press any key to continue.",pass))
	DisplayString("*nSET-UP INSTRUCTIONS are Breakpoint Level 9.")
	SetBPLevel()
	SpaceDisplay(1)

//Set up instructions
	if pass eq 1 do
	[
		DisplayString("*nReplace the oscillator platform @ u7")
		DisplayString("*nby a dummy platform(everything but crystal)")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*nDuring the test,we  are driving AllowWU")
		DisplayString("*nThis in turn would drive NClk crazy")
		DisplayString("*n")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*nAttach pull-up resistor clip to S38 a-18") 
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*nConnect Test Probes as follows:")
		DisplayString("*n Test probe B TO B-16")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe C  TO F-15")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe D TO F-12")
		SpaceDisplay(1)
		Breakpoint(9)
		DisplayString("*n Test probe E TO E-6")
		SpaceDisplay(1)
		DisplayString("*n  The clip marked ECL-ONLY to position F-1 and the other end to b-2")
		Breakpoint(9)
	]
	truntime = 0
	testno = 71
	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 71")
	SpaceDisplay(3)
	let x = false
	while Endofs(keys) do [ ]
	let ch = Gets(keys)
	switchon (ch & #177) into
	[
		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;
			default: x = true; endcase;
		]
	]
	if x do [ testno = 71 ]
	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 71: Test71(); endcase;
		case 72: Test72(); 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
	 SetPinValue(8,1)
	 SetPinValue(7,1)
	 SetPinValue(64,1)
	 SetPinValue(41,0)
	 SetPinValue(16,1)
	 SetPinValue(96,1)
	 SetPinValue(140,1)
	 SetPinValue(231,1)
	 SetPinValue(105,0)
	if na eq 0 do
	[
		 SetPinValue(153,0)
		Clocks()
		Clocks()
	]
	 SetPinValue(153,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)
]


//UNKNOWN SIGNALS REQUIRED: