//D0prin0.bcpl	Procedures to prettyprint various registers and memories
//	Last edited: 20 October 1981

get "d0.d"
manifest [ get "d0regmem.d" ]

external
[
// MASM
	@WssCSS; PutsCSS; WssCS1; GetField

// MPATTERN
	@PATTERN

// MIOC
	Wns; DWns

// MSYM
	SearchBlocks

// MRGN
	CharInputRoutine

// MTXTBUF
	ClearInText

// MCMD
	WnsCSS; WnsCSSD; WnsCS1; WnsCS1D; CmdCommentStream

// MPRINS
	NWss

// D0ASM
	stNotInVM

// D0GO
	PrCCV

// D0VM
	LookUpAA; @VirtualP

// D0PRIN0ASM
	SALUFtab

//Defined here

	PrinCYCLECONTROL; PrinParity; PrinBootReason; PrinTask
	PrinALUResult; PrinSALUF; PrinAATOVA
	PrinMNBR; PrinIMAddr; PrintWrdByt; PrintMADDR; PrintMAP

]

let PrinIMAddr(X,DVec,AVec,ExtRadix) be
[	let Val = DVec!0 rshift 4
//Prevent crashing in PrCCV routine due to attempting to prettyprint a
//value in virtual mode which is not in VM.
	if Val eq #7777 then Val = -1
	PrCCV((lv Val)-1,VirtualP ? IMx,IMXx)
	for N = 4 to 13 by 3 do CharInputRoutine(GetField(N,3,lv Val)+60B)
	ClearInText()
]


and PrinAATOVA(X,DVec,AVec,ExtRadix) be
[	test DVec!0 ge 0
	ifso
	[ let AVec1 = vec 1; AVec1!0 = 0; AVec1!1 = DVec!0 & #7777
	  SearchBlocks(CmdCommentStream,IMx,AVec1,-1,0)
	  WssCSS(" = abs. "); WnsCSS(LookUpAA(AVec1!1))
	]
	ifnot WssCSS(stNotInVM)
]


and PrinCYCLECONTROL(X,DVec,AVec,ExtRadix) be
[	let MaskT1 =
		table [ #1; #3; #7; #17; #37; #77; #177; #377;
		#777; #1777; #3777; #7777; #17777; #37777; #77777; #177777 ]
	let DBX,MWX = DVec!0 rshift 12,(DVec!0 rshift 8) & #17
	let Mask0 = MaskT1!MWX
	let Mask1 = MaskT1!(#17-DBX) & not MaskT1!((#17-DBX-MWX) & #17)
	WssCSS("DBX[2:5]="); WnsCSS(DBX)
	WssCSS(", MWX[0:3]="); WnsCSS(MWX)

	WssCSS(".  On RF: A←LCy[R,"); WnsCSS((DBX+MWX+1) & #17)
	WssCSS("] and "); WnsCSS(Mask0)

	WssCS1("On WFA: A←LCy[R,"); WnsCS1((#17-DBX-MWX) & #17)
	WssCS1("] and "); WnsCS1(Mask1)

	WssCS1(".  On WFB: A←R and not "); WnsCS1(Mask1)
]


//***Should define a TaskN memory and print task numbers symbolically.
and PrinTask(X,DVec,AVec,ExtRadix) be
[	Wns(CmdCommentStream,DVec!0 rshift 12,0,ExtRadix)
]


and PrinParity(X,DVec,AVec,ExtRadix) be 
[	PATTERN = DVec!0
	NWss("StackOverflow ",#100000)
	NWss("ControlStore PE ")
	NWss("R Bus PE ")
	NWss("Memory Error ")
]


and PrinBootReason(X,DVec,AVec,ExtRadix) be 
[	PATTERN = DVec!0
	NWss("Tester Boot ",#20000)
	NWss("Maintenance Panel Boot ")
	NWss("WatchDogTimer Boot ")
	NWss("Boot F ")
	NWss("Power Restore Boot ")
	NWss("Parity Error Boot ")
]


and PrinALUResult(X,DVec,AVec,ExtRadix) be 
[	PATTERN = DVec!0
	NWss("ALU>=0 ",#100000)
	NWss("CARRY' ")
	NWss("ALU=0 ")
	NWss("OVERFLOW ")
	PATTERN = DVec!0 xor #177777
	NWss("ALU<0 ",#100000)
	NWss("Carry ")
	NWss("ALU#0 ")
	NWss("OVERFLOW' ")
]


and PrinSALUF(X,DVec,AVec,ExtRadix) be
[	let Str = SALUFtab+((DVec!0 rshift 8) & #77)
	Str = Str + Str!0
	WssCSS(Str)
]

and PrinMNBR(X,DVec,AVec,ExtRadix) be
[	PrintWrdByt(X,DVec,AVec,ExtRadix)
	WssCSS(" = "); PutsCSS($-); WnsCSS(-(DVec!0))
]


and PrintWrdByt(X,DVec,AVec,ExtRadix) be
[	Wns(CmdCommentStream,DVec!0,0,ExtRadix); WssCSS(" = ")
	Wns(CmdCommentStream,DVec!0 rshift 8,0,ExtRadix); WssCSS(",,")
	Wns(CmdCommentStream,DVec!0 & #377,0,ExtRadix)
]


and PrintMADDR(X,DVec,AVec,ExtRadix) be
[	switchon AVec!1 into
	[
case 2B:	WssCSS("No. test iterations="); endcase
case 6B:	WssCSS("address bits always 1 on failures="); endcase
case 7B:	WssCSS("Union of address bits that were 1 on failures=")
		endcase
case 11B:	DblCntPrint(DVec,
			"D0 hung in recvbyte ",
			"D0 hung at onset of sendbyte "); return
case 12B:	DblCntPrint(DVec,
			"D0 failed to ack sendbyte ",
			"D0 never removed ack "); return
case 13B:	DblCntPrint(DVec,
			"CheckStopped glitched ",
			"STACK0 to 3 inconsistent "); return
case 14B:	test DVec!1 eq 0
		ifso WssCSS("KERNEL was transmitted OK")
		ifnot
		[ if DVec!1 ne 0 do
		  [ WssCSS("Last boot failure error at word ")
		    WnsCSS(DVec!0)
		    WssCSS(" of KERNEL transmission; retried because:")
		  ]
		  let T0,T1 = DVec!1 rshift 12,(DVec!1 rshift 8) & #17
		  let T2,T3 = (DVec!1 rshift 4) & #17,DVec!1 & #17
		  if T0 ne 0 do
		  [ WssCS1("Direction incorrect "); PrinOccurrence(T0)
		  ]
		  if T1 ne 0 do
		  [ WssCS1("Write ack not 0 initially "); PrinOccurrence(T1)
		  ]
		  if T2 ne 0 do
		  [ WssCS1("Write ack not received "); PrinOccurrence(T2)
		  ]
		  if T3 ne 0 do
		  [ WssCS1("Write ack did not drop "); PrinOccurrence(T3)
		  ]
		]
		return
default:	endcase
	]
	DWns(CmdCommentStream,DVec,32,0,ExtRadix)
]


and DblCntPrint(DVec,S1,S2) be
[	WssCSS(S1); WnsCSSD(DVec!0); WssCSS(" times")
	WssCS1(S2); WnsCS1D(DVec!1); WssCS1(" times")
]


and PrinOccurrence(N) be
[	switchon N into
	[
case 1:	  WssCS1("once"); return
case 2:	  WssCS1("twice"); return
default:  WnsCS1D(N); WssCS1(" times"); return
	]
]


and PrintMAP(X,DVec,AVec,ExtRadix) be
[	PATTERN = DVec!0
	NWss("LogSE ",#100000)
	NWss("WP ")
	NWss("Dirty ")
	NWss("Ref ")
	WssCSS("Real page = "); WnsCSS(PATTERN & #7777)
]