//D1Prin1A.bcpl--Subroutines used by D1Prin1.bcpl
//	Last edited: 26 November 1979

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

external [
// MIDAS
	MidasSwat

// MASM
	SelfRel

// MSYM
	SearchBlocks

// MCMD
	CmdCommentStream; @WssCSS; WnsCSS; PutsCSS

// D1VM
	LookUpVA

// D1PRIN1
	ClausePrinted

// D1PRINASM
	BCtab

// Defined here
	PrinBMux; PrinAMux; CPrint; PrinC; PrinVA; PrinBC; PrinCRAddr
]


let PrinBMux(BDest1,BDest2,BSrc,BSEL,BC2,RAKnown) be
[	CPrint(BDest1,"←")
	if BDest2 ne 0 do	//Only can be a rd/wrt im/tpc
	[ WssCSS(BDest2)
	  if BC2 ge 0 do	//Show the (illegal) b.c., if any
	  [ PutsCSS($[)
	    WssCSS(SelfRel(BCtab+BC2))
	    PutsCSS($])
	  ]
	  PutsCSS($←)
	]
	test BSEL < 4
	ifso PrinCRAddr(BSrc,RAKnown,false)
	ifnot
	[ WnsCSS(BSrc); PutsCSS($C)
	]
]


and PrinAMux(ADest,ASrc0,ASrc1,ASrc2,AShs1,AShs2,AShsLast,
	AShccnt,AShsize,AShpos,RAKnown) be
[	CPrint(ADest)
	if ADest ne 0 then PutsCSS($←)
	CPrint(ASrc0)
	if ASrc1 ne 0 then PrinCRAddr(ASrc1,RAKnown,false)
	if ASrc2 ne 0 then PrinCRAddr(ASrc2,RAKnown,false)
	if AShs1 ne 0 do
	[ PrinCRAddr(AShs1,RAKnown,false); PutsCSS($,)
	  PrinCRAddr(AShs2,RAKnown,false); PutsCSS($,)
	  test AShccnt ge 0
	  ifso WnsCSS(AShccnt)
	  ifnot
	  [ WnsCSS(AShsize); PutsCSS($,); WnsCSS(AShpos)
	  ]
	  if AShsLast ne 0 do
	  [ PutsCSS($,); WssCSS(AShsLast)
	  ]
	  PutsCSS($])
	]
]


and CPrint(Str1,Str2; numargs NA) be
[	if Str1 eq 0 then return
	WssCSS(Str1); if NA > 1 then WssCSS(Str2)
]


and PrinC(Str1,Str2; numargs NA) be
[	if Str1 eq 0 then return
	if ClausePrinted then WssCSS(", ")
	WssCSS(Str1); if NA > 1 then WssCSS(Str2)
	ClausePrinted = true
]


and PrinVA(BA,Point) be
[	let AVec = vec 1; AVec!0 = 0; AVec!1 = LookUpVA(BA)
	test AVec!1 ge 0
	ifso SearchBlocks(CmdCommentStream,IMx,AVec,Point)
	ifnot WnsCSS(BA)
]


and PrinBC(BC) be
[	if BC > 7 then MidasSwat(BadBCarg)
	if BC < 0 then return
	PutsCSS($,); WssCSS(SelfRel(BCtab+BC))
]


//RAddrP1 is either a string or an RM address+1; RAKnown is true if
//RAddrP1 is a complete RM address, false if RBase relative; First is
//true if ", " should be conditionally printed ahead of the string, else
//false
and PrinCRAddr(RAddrP1,RAKnown,First) be
[	test ClausePrinted
	ifso if First then WssCSS(", ")
	ifnot ClausePrinted = true
	test (RAddrP1 & #177000) eq 0
	ifso			//RM source
	[ test RAKnown
	  ifso
	  [ let AVec = vec 1; AVec!0 = 0; AVec!1 = RAddrP1-1
	    SearchBlocks(CmdCommentStream,RMx,AVec)
	  ]
	  ifnot
	  [ PutsCSS($R); WnsCSS(RAddrP1-1)
	  ]
	]
	ifnot WssCSS(RAddrP1)	//Another string source
]