//**************************************************************************************
//D0CS08.TST
//By B. Rosen and M. Thomson  							February 22, 1979
//Sub Test Program for D0 CS Module
//**************************************************************************************
get "d0cs.d"

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

//{ALUA: ALUA.00,  ALUA.01,ALUA.02,ALUA.03,  ALUA.04,ALUA.05,ALUA.06,  ALUA.07,ALUA.08,ALUA.09,  ALUA.10,ALUA.11,ALUA.12,  ALUA.13,ALUA.14,ALUA.15}

//{CS-A': TrmCS-A.00'a,TrmCS-A.01'a,TrmCS-A.02'a,  TrmCS-A.03'a,TrmCS-A.04'a,TrmCS-A.05'a,  TrmCS-A.06'a,TrmCS-A.07'a,TrmCS-A.08'a,  TrmCS-A.09'a,TrmCS-A.10'a,CS-A.11'}

//{H2: H2.12,  H2.13,H2.14,H2.15}

//{R: R.00,  R.01,R.02,R.03,  R.04,R.05,R.06,  R.07,R.08,R.09,  R.10,R.11,R.12,  R.13,R.14,R.15}

//**************************************************************************************
//Test 13: Test Almost all of Control Store Ram

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

	let v = vec 64
	let str = v

//This test does an address test of almost the entire control store.
//The test writes data into each address, and then partially 
//	verifies the contents by reading the most significant 16 bits.
//When all addresses have been written, another pass is made in which all bits are checked.

	Ws("*nWriting Page")
	let d = #123456 //start random data
	RxCSData()

	for l = 0 to 15 do //16 pages
	[
		Ws(FORMATN(" <B>",l))
		FORMAT(str,"in dual address test write of Page <B>",l)

		for k = (l gr 3? 0,1) to 3 do //64 word quarter pages, don't do first quarter
		[
			let lk = (l lshift 8) % (k lshift 6)  //form address bits [4:9]

			for j = 0 to 1 do //first two passes have extra Checks
			[
				let i = lk % j		//form address
				d = (d<<w.b1 xor d<<w.b4) % (d lshift 1); //up-date random data

				Check("CS-A",{CS-A'} xor #7777,#1402,"before loading CSIN",13000,i)
				Check("Cycle0Feed'",{Cycle0Feed'},0,"before loading CSIN",13001,i)

				{ALUA} = d;		//Data to be loaded
				{H2} = d;		//extra 4 bit data
				TwoClocks()		//CSIn← @1402
				Check("CS-A",{CS-A'} xor #7777,#1403,"before loading APC",13002,i)
				Check("Cycle0Feed'",{Cycle0Feed'},0,"before loading APC",13003,i)

				{ALUA} = i;		//Address to load
				EClock()		//APC← @1403
				Check("Cycle0Feed'",{Cycle0Feed'},1,"when loading APC",13004,i)

				{LoadAPC'xxx} = {LoadAPC'}
				EClock()
				Check("CS-A",{CS-A'} xor #7777,i,"at start of write",13005,i)
				Check("Cycle0Feed'",{Cycle0Feed'},0,"before write",13006,i)

				EClock()
				Check("CS-A",{CS-A'} xor #7777,i,"middle of write",13007,i)

				{LoadAPC'xxx} = {LoadAPC'}
				TwoEClocks()
				Check("CS-A",{CS-A'} xor #7777,#1422,"middle of fetch",13008,i)

				{LoadAPC'xxx} = {LoadAPC'}
				EClock()

				{H2.15} = 0;		//CSData[0:15] ← bits[0:15]
				TwoClocks()		//APC←

				//Test RSEL[4:5]/d logic not completely testable previously:
				Check("RSEL.4/d",{RSEL.4/d},d<<w.b12,str,13010,i)
				Check("RSEL.5/d",{RSEL.5/d},d<<w.b13,str,13011,i)
				Check("RSEL4and5/d",{RSEL4and5/d},d<<w.b12 & d<<w.b13,str,13012,i)

				TwoClocks()		//ReadCS
				Check("Msb Read Data",{R},d,str,13100,i)

				{ALUA} = d;		//Data to be loaded
				TwoClocks()		//Read Fetch

				{ALUA} = i;		//Address to load
				FourClocks()		//APC←; WriteCS1
				TwoClocks()		//Write Fetch

				//there is a branch instruction at the end of the loop
				{J-TestResult'} = (i eq 4095?0,1)
				TwoClocks()		//Branch Loop
			]

			for j = 2 to 63 do //remaining passes omit extra Checks for speed
			[
				let i = lk % j		//form address
				d = (d<<w.b1 xor d<<w.b4) % (d lshift 1); //up-date random data

				{ALUA} = d;		//Data to be loaded
				{H2} = d;		//extra 4 bit data
				TwoClocks()		//CSIn← @1402

				{ALUA} = i;		//Address to load
				TwoClocks()		//APC← @1403
				FourClocks()		//insert note here ******

				{H2.15} = 0;		//CSData[0:15] ← bits[0:15]
				FourClocks()		//APC←; ReadCS
				Check("Msb Read Data",{R},d,str,13200,i)

				{ALUA} = d;		//Data to be loaded
				TwoClocks()		//Read Fetch

				{ALUA} = i;		//Address to load
				FourClocks()		//APC←; WriteCS1
				TwoClocks()		//Write Fetch

				//there is a branch instruction at the end of the loop
				{J-TestResult'} = (i eq 4095?0,1)
				TwoClocks()		//Branch Loop
			]
		]
	]

	EClock()		//Burp
	{J-TestResult'} = 1
	TwoClocks()		//Branch Noop
	Check("CS-A",(not {CS-A'})&#7777,#1412,"between write and read",13300)

	Ws("*nReading Page")
	let d = #123456 //start random data

	for l = 0 to 15 do //16 pages
	[
		Ws(FORMATN(" <B>",l))
		FORMAT(str,"in dual address test read of Page <B>",l)

		for k = (l gr 3? 0,1) to 3 do //64 word quarter pages, don't do first quarter
		[
			let lk = (l lshift 8) % (k lshift 6)  //form address bits [4:9]

			for j = 0 to 63 do
			[
				let i = lk % j		//form address
				d = (d<<w.b1 xor d<<w.b4) % (d lshift 1); //up-date random data

				{ALUA} = i;		//Address to read
				{H2.15} = 0;		//CSData[0:15] ← bits[0:15]
				FourClocks()		//APC←; ReadCS0
				Check("Msb Read Data",{R},d,str,13400,i)

				TwoClocks()		//Read Fetch
				{H2.15} = 1;		//CSData ← LCSD[0:3],,bits[20:31]
				{H2.14} = 0;		//LCSD[0:3] ← bits[16:19]
				FourClocks()		//APC←; ReadCS1
				Check("Middle Read Data",{R},d,str,13401,i)

				TwoClocks()		//Read Fetch
				{H2.14} = 1;		//LCSD[0:3] ← bits[32:35]
				FourClocks()		//APC←; ReadCS2
				Check("Xtra Read Data",{R}&#170000,d lshift 12,str,13402,i)

				TwoClocks()		//Read Fetch
				{J-TestResult'} = (i eq 4095?0,1)
				TwoClocks()		//Branch Loop
			]
		]
	]

	EClock() //Burp
]