//**************************************************************************************
//D0CS01.TST
//By B. Rosen and M. Thomson  							December 18, 1978
//Sub Test Program for D0 CS Module
//**************************************************************************************
get "d0cs.d"

//Edge pin and test connector signal busses available to this sub-test: (none)

//**************************************************************************************
//Test 1: Test Clock Generator

let Test1() be
[
	SpeakTest(1) //set initial conditions (see notes at end of D0CS.TST)

	for i = 0 to 20 do TwoEClocks()	//get clock to steady state

	let i = 0
	[
		ExtClock()
		if {RamClockFeed'} eq 0 then break;	//wait for RamClock to go down
		i=i+1
	] repeatuntil i eq 25				//(but don't wait too long)

	ClockCheck(i ls 25,"*nRamClockFeed' will not go low")

	i = 0
	[
		ExtClock()
		if {RamClockFeed'} eq 1 then break;	//wait for it to come up again
		i=i+1
	] repeatuntil i eq 4				//(should come right back up)

	ClockCheck(i ls 4,"*nRamClockFeed' will not go high")

//should now be sitting at first part of a cycle

	ClockCheck({EdgeClockFeed'} eq 1,"*nEdgeClockFeed' is not high when RamClockFeed is high")
	ClockCheck({EomClockFeed'} eq 1,"*nEomClockFeed' is not high when RamClockFeed is high")

	i = 0
	[
		let c0 = {Cycle0Feed'};	//save current cycle
		ExtClock()		//run through the cycle
		ClockCheck({RamClockFeed'} eq 1,"*nRamClockFeed' not high in 2nd click")
		ClockCheck({EdgeClockFeed'} eq 1,"*nEdgeClockFeed' not high in 2nd click")
		ClockCheck({EomClockFeed'} eq 0,"*nEomClockFeed' not low in 2nd click")
		ClockCheck({Cycle0Feed'} eq c0,"*nCycle0Feed' changed in 2nd click")

		ExtClock()
		ClockCheck({RamClockFeed'} eq 0,"*nRamClockFeed' not low in 3rd click")
		ClockCheck({EdgeClockFeed'} eq 1,"*nEdgeClockFeed' not high in 3rd cycle")
		ClockCheck({EomClockFeed'} eq 1,"*nEomClockFeed' not high in 3rd cycle")
		ClockCheck({Cycle0Feed'} eq c0,"*nCycle0Feed' changed in 3rd click")

		ExtClock()
		ClockCheck({RamClockFeed'} eq 0,"*nRamClockFeed' not low in 4th click")
		ClockCheck({EdgeClockFeed'} eq 0,"*nEdgeClockFeed' not low in 4th click")
		ClockCheck({EomClockFeed'} eq 0,"*nEomClockFeed' not low in 4th click")
		ClockCheck({Cycle0Feed'} eq c0,"*nCycle0Feed' changed in 4th click")

		ExtClock()
		ClockCheck({RamClockFeed'} eq 1,"*nRamClockFeed' not high in 1st click")
		ClockCheck({EdgeClockFeed'} eq 1,"*nEdgeClockFeed' not high in 1st click")
		ClockCheck({EomClockFeed'} eq 1,"*nEomClockFeed' not high in 1st click")
		ClockCheck({Cycle0Feed'} ne c0,"*nCycle0Feed' did not change in 1st click")
		i=i+1
	] repeatuntil i eq 100	//try a lot of cycles

//Waveforms look ok, try Cycle0/Cycle1 stuff

	if {Cycle0Feed'} eq 1 then 
	[
		EClock()	//get to cycle 0
		ClockCheck({Cycle0Feed'} eq 0,"*nCycle0Feed' would not go low after Cycle1")
	]

	for i = 1 to 100 do
	[
		EClock()	//get to cycle 1
		ClockCheck({Cycle0Feed'} eq 1,"*nCycle0Feed' would not go high after Cycle0")
		EClock()	//get back to cycle 0
		ClockCheck({Cycle0Feed'} eq 0,"*nCycle0Feed' would not go back low after cycle1")
	]

//Make sure Suspend stops cycling

	{Suspend-a} = 1;	//set suspend

	for i = 1 to 80 do
	[
		ExtClock()	//cycle0 should not change at all
		ClockCheck({Cycle0Feed'} eq 0,"*nSuspend doesn't prevent Cycle0Feed' going to high")
	]

	{Suspend-a} = 0;	//release suspension
	EClock()		//advance to cycle 1
	{Suspend-a} = 1;	//restore suspend
	ClockCheck({Cycle0Feed'} eq 1,"*nFirst cycle after a suspend, Cycle0Feed' wouldn't go high")

	for i = 1 to 80 do
	[
		ExtClock()	//make sure it stays in cycle1 
		ClockCheck({Cycle0Feed'} eq 1,"*nSuspend doesn't prevent Cycle0Feed' going to low")
	]

	{Suspend-a} = 0
	EClock()
	ClockCheck({Cycle0Feed'} eq 0,"*nFirst Cycle after a suspend, Cycle0Feed' wouldn't go low")

//test Phase1Next follows Cycle0Feed (opposite polarity)

	for i = 0 to 100 do
	[
		EClock()
		ClockCheck({Phase1Next'} eq {Cycle0Feed'},"*nPhase1Next' not following Cycle0")

		//Phase1Next is gated with Suspend' at b4

		if {Phase1Next'} eq 0 then
		[
			{Suspend-a} = 1
			ClockCheck({Phase1Next'} eq 1,"*nSuspend does not make Phase1Next' go high")
			{Suspend-a} = 0
		]
	]
]

	 
and ClockCheck(tst,msg) be
[
	if tst then return
	Ws(msg)

	Ws("*nCheck the Waveforms on page 12 of the Logic Diagrams")
	Ws("  Clicking... (any key will go on)")

	while Endofs(keys) do 
	[
		ExtClock()
	]

	Gets(keys)
	Ws("*nRunning...")
]