//D1Prin3X.bcpl	Procedures to prettyprint ALUFM and DMux signals in
//the range 20B to 37B.  The signals from ProcH are printed on
//CmdCS1; ProcL on CmdCommentStream.
//	Last edited: 13 July 1979

get "d1.d"
manifest [ get "d1dmux.d" ]

external [
// OS
	Puts

// MIOC
	Wns

// MASM
	Wss; @WssCSS; PutsCSS; WssCS1; PutsCS1 

// MCMD
	CmdCommentStream; CmdCS1; WnsCSS; WnsCS1; WnsCS1D

// MPRINS
	PrinV0; PrinV1; NWss; NWss1

// MPATTERN
	@PATTERN

// D1PRIN2
	PrintWrdByt

// Defined here
	PrintDMXx; PrintALUFM
]


let PrintALUFM(X,DVec,AVec,ExtRadix) be
[	let Val = DVec>>lh & ((DVec!0 & 400B) ne 0 ? 37B,237B)
	WssCSS("Alu function = ")
	WssCSS(selecton Val into
	[
case 0:	case 37B: case 236B: "A"
case 1: "not A"
case 3: "(not A) or (not B)"
case 5: "(not A) or B"
case 6: "2**A"
case 7: "All1's"
case 11B: "(not A) and (not B)"
case 13B: "not B"
case 14B: "A+B"
case 15B: "A xnor B"
case 17B: "A or (not B)"
case 21B: "(not A) and B"
case 22B: "A-B-1"
case 23B: "A xor B"
case 25B: "B"
case 27B: "A or B"
case 31B: "all0's"
case 33B: "A and (not B)"
case 35B: "A and B"
case 36B: "A-1"
case 200B: "A+1"
case 206B: "2**A+1"
case 214B: "A+B+1"
case 222B: "A-B"
default: "undefined arithmetic op"
	] )
]

and PrintDMXx(Addr) be
[   let DV2 = vec 1
    switchon Addr into
    [
case dALUB: WssCSS("Alub"); endcase
case dALUA: WssCSS("Alua"); endcase
case dSHMV: WssCSS("shmv"); endcase
case dMAR:  WssCSS("MAR"); endcase
default:
	WssCSS("ProcL:"); WssCS1("ProcH:")
	switchon Addr into
	[
case dABCON:
	NWssBoth(" MarMuxAEn",100200B)
	NWssBoth(" AmuxEn",40100B)
	PrinBothPHL(" Amux",(PATTERN rshift 4) & 1403B)
	NWssBoth(" IOBout",4010B)
	NWssBoth(" BmuxEn",2004B)
	PrinBothPHL(" Bmux",PATTERN & 1403B); return
case dPERR:
	NWssBoth(" IOPerr",4010B)
	NWssBoth(" MdPerr",2004B)
	NWssBoth(" RmPerr",1002B)
	NWssBoth(" TmPerr",401B)
	NWss1(" EMU",#100000)
	NWss1(" CkMdParity")
	NWss(" StkSela",#200)
	NWss(" StkSelSaved")
	NWss(" IOBoutSaved")
	NWss(" ←MDSaved"); return
case dPRFA:
	NWssBoth(" Last=Curr",100200B)
	NWssBoth(" Curr=Next",40100B)
	NWssBoth(" Shift",20040B)
	NWssBoth(" IOBin",10020B)
	PrintFA(CmdCommentStream,PATTERN & 17B)
	PrintFA(CmdCS1,(PATTERN rshift 8) & 17B)
	return
case dSCCON:
	NWssBoth(" RepeatCurrC",40100B)
	NWssBoth(" Holda",20040B)
	NWss1(" LdTaskSim",#10000)
	NWss(" LdHoldSim",#20)
	NWssBoth(" FFshift",4010B)
	NWssBoth(" ShcWriteEn",2004B)
	NWssBoth(" LoadCnt",1002B)
	NWss1(" PropCnt",#400)
	NWss(" DecCnt",#1); return
case dQPDCON:
	NWssBoth(" QshiftL",100200B)
	NWssBoth(" QshiftR",40100B)
	NWssBoth(" RmaskEn",20040B)
	NWssBoth(" LmaskEn",10020B)
	NWss1(" ShiftBitsEn",#4000)
	NWss(" ALUFWriteEn",#10)
	PrinBothPHL(" Pmux",PATTERN &  3407B); return
case dALUCON:
	DV2!0 = PATTERN lshift 8
	NWss1(" Pdata.00",#100000)
	NWss1(" Pdata.04")
	NWss1(" TIOAWriteEn")
	NWss1(" TIOABypass")
	NWss1(" MBWriteEn")
	NWss1(" MBBypass")
	PrinV1(" MBMux",(PATTERN rshift 8) & 3B)
	NWss(" Pdata.08",#100)
	NWss(" Pdata.12")
	PutsCSS($ )
	PrintALUFM(nil,DV2,nil,8); return
case dNEXTCL:
	PrinBothPHL(" LastNext",(PATTERN rshift 4) & 7417B)
	PrinBothPHL(" CurrLast",PATTERN & 7417B); return
case dRADDR:
	PrinV1(" Task2Bk",PATTERN<<nib0)
	PrinV1(" Task3Bk",PATTERN<<nib1)
	PrinV0(" RbWadr",PATTERN<<rh)
	return
case dSTKRB:
	NWss1(" BCWriteEn",#100000)
	NWss1(" Cnt=Zero")
	NWss1(" IOatta")
	NWss1(" ResEqZero")
	NWss1(" ResLtZero")
	NWss1(" ALUCarry")
	NWss1(" Overflow")
	NWss1(" RmLtZero")
	NWss(" RBaseBypass")
	NWss(" SelRBaseWadr")
	NWss(" RBaseWriteEn")
	NWss(" BumpRBase")
	NWss(" BumpRStk")
	NWss(" StkPMux1")
	NWss(" StkPWriteEn")
	NWss(" RmOdd"); return
case dRTSB:
	NWss1(" ReSchedWrEn",#100000)
	NWss1(" NextMacro")
	NWss(" StkPSaveEn",#200)
	NWss(" StkError")
	NWssBoth(" RbWriteEn",20040B)
	NWssBoth(" RbSelMd",10020B)
	NWssBoth(" RbBypassDly",4010B)
	NWssBoth(" TbWriteEn",2004B)
	NWssBoth(" TbSelMd",1002B)
	NWssBoth(" TbBypass",401B); return
case dPJUNK:
	NWssBoth(" FFok",100200B)
	NWssBoth(" B←Ext",10020B)
	NWssBoth(" RisIFdata",1002B)
	NWssBoth(" TisIFdata",401B)
	NWss1(" NextData",#20000)
	NWss1(" FF.0mem",#4000)
	NWss1(" FF.1mem")
	NWss(" ←MD",#100)
	NWss(" ←MDI")
	PrinV0(" SbTskDly",(PATTERN rshift 2) & 3B)
	return
	]
    ]
    WssCSS(" = "); PrintWrdByt(nil,lv PATTERN,nil,8)
]


and  PrinBothPHL(Str,ValHlf) be
[	PrinV1(Str,ValHlf<<lh)
	PrinV0(Str,ValHlf<<rh)
]


and NWssBoth(Str,ValHlf) be
[	NWss(Str,ValHlf<<rh); NWss1(Str,ValHlf & 177400B)
]


and PrintFA(S,Val) be
[	test Val eq 0
	ifso Wss(S," FA is 0 (no fn)")
	ifnot test (Val & -Val) eq Val	//Just one bit?
	  ifso
	  [ Wss(S," FA=")
	    Wns(S,selecton Val into
	    [
case 1:		3
case 2:		2
case 4:		1
case 8:		0
	    ] ,0,8)
	  ]
	  ifnot
	  [ Wss(S," ?FA is "); Wns(S,Val,0,8); Wss(S,"?")
	  ]
]