// hccom.sr

// Bcpl/f hccom.sr

// last modified
// PCL  -- April 3 1978  added Envelope mode
// RML April 12, 1978  5:03 PM single page color Press file

// Last modified November 30, 1979  2:07 PM by Taft

get "BRAVO1.DF"
get "ST.DF"
get "ALTOFILESYS.D"
get "DIR.DF"
get "COM.DF"
get "RN1.DF"
get "HARDCOPY.DF"
get "DISPLAY.DF"

// Incoming Procedures

external	[
	AbHcParams
	HcDefaultPrintingServer
	deactivateomseq
	augmentomseq
	DiabloTranslate
//	translate
//	EarsDir
	EarsTransmit
	invalidatewindow
	stsize
	SetRegionSys
	SetRegionW
	max
	move
	stnum
	ReadDiskKd;
	WriteDiskKd;
	PressTranslate;
	]


// Incoming Statics

external	[
	selarg			//**PCL
	freee
	vdcb
	vdcblink
	rgmaccp
	mpWwWwd
	vfDiablomode
	vrlwsys
	dcpendofdoc
	EnvelopeFlag
	EnvelopeCpLast
	vsbPressNetAddress
	vsbAltPressNetAddress
	]


// Outgoing Procedures

external	[
	hccom
	]


// Outgoing Statics

external	[
	pgnFirst
	]


// Local Statics

static	[
	pgnFirst
	]


// Local Manifests

// manifest


// H C C O M
// cf>>CF.w0 = nmd
// cf>>CF.w1 = cpFirst
// cf>>CF.w2 = fNoTrunc

let hccom(cf) = valof
[
let sel = cf>>CF.sel
let ww = (mpWwWwd ! (sel>>SEL.ww))>>WWD.wwgroup + 1
let wwd = mpWwWwd ! ww
let doc = wwd>>WWD.doc

// check for empty window
if (rgmaccp ! doc - dcpendofdoc) eq 0 then
	[
	SetRegionSys(risyspast, 45, 13, 50)	// #45 = window empty
	resultis abmsg
	]
let nmd = vec lnmdMax
cf>>CF.w0 = nmd
let ho = vec lnho

let ab = AbHcParams(cf, ho)
deactivateomseq("↑", "↑")

if ab eq abnil then
	[
	let cpFirst = cf>>CF.w1
	let fNoTrunc = cf>>CF.w2
	let piStartPrint = ho>>HO.pgnStartPrint - ho>>HO.pgnFirst
	test (vfDiablomode  & EnvelopeFlag)  ifso		//PCL
			[
			let cpFirst = selarg>>SEL.cpfirst
			EnvelopeCpLast = selarg>>SEL.cplast
			augmentomseq("WJQT")
			ab = DiabloTranslate(ww, cpFirst, piStartPrint, ho)
			deactivateomseq("WJQT", "WJQT")
			EnvelopeFlag = false	//reset flag
			]
	ifnot 
	[
	test vfDiablomode ifso
		[
		augmentomseq("WJQT")
		ab = DiabloTranslate(ww, cpFirst, piStartPrint, ho)
		deactivateomseq("WJQT", "WJQT")
		]
	ifnot 
		[
		//blackout
		let dcb = (mpWwWwd ! (wwsys+1))>>WWD.dcbFirst
		let dcbLink = dcb>>DCB.next
		vdcb = dcb
		vdcblink = dcbLink
		dcb>>DCB.next = 0
	
//		test ho>>HO.fEars ifso
//			[
//			augmentomseq("KEXQ")
//			ReadDiskKd();
//			ab = translate(ww, cpFirst, piStartPrint,
//				lv nmd>>NMD.afptr, ho, fNoTrunc)
//			WriteDiskKd();
//			deactivateomseq("KEXQ", "KEXQ")
//			if ab eq abnil & not ho>>HO.fFile then
//				[
//				augmentomseq("←QT")
//				let savefreee = freee
//				unless EarsDir(lv nmd>>NMD.afptr, pgnFirst, ho) do
//					ab = abmsg
//				deactivateomseq("←QT", "←QT")
//				freee = savefreee
//				]
//			]
//		ifnot
			[	// PRESS
			augmentomseq("KdeQ")
			ReadDiskKd();
			ab = PressTranslate(ww, cpFirst, piStartPrint,
				lv nmd>>NMD.afptr, ho, fNoTrunc)
			WriteDiskKd();
			deactivateomseq("KdeQ", "KdeQ")
			
			unless ab ne abnil % ho>>HO.fNetAddress % ho>>HO.fFile do
				[
				augmentomseq("↑")
				ab = HcDefaultPrintingServer(ho)
				deactivateomseq("↑", "↑")
				]
			]

		if ab eq abnil & not ho>>HO.fFile then
			[
			augmentomseq("FT")
			unless EarsTransmit(lv nmd>>NMD.afptr, pgnFirst, ho) do
				ab = abmsg
			deactivateomseq("FT", "FT")
			]
		dcb>>DCB.next = dcbLink
		vdcb = vdcbnil
		invalidatewindow(wwsys+1)	
		]
	 ]
	]

if ab eq abBadPage then
	[
	let tsb = vec 5
	stnum(tsb, ho>>HO.pgnStartPrint)
	SetRegionW(vrlwsys, 0, tsb)
	let ridPgn = nil
	ridPgn<<RID.nrl = 1
	ridPgn<<RID.ri = 0
	SetRegionSys(risyspast, 165, ridPgn, 166, 50)
	resultis abmsg
	]
if ab ne abnil then resultis ab
unless ho>>HO.fPgn do resultis abnil
let sbPgn = lv ho>>HO.asbPgn
test stsize(sbPgn) eq 0 ifso
	SetRegionSys(risyspast, 158)
ifnot
	[
	SetRegionW(vrlwsys, 0, sbPgn)
	let ridPgn = nil
	ridPgn<<RID.nrl = 1
	ridPgn<<RID.ri = 0
	SetRegionSys(risyspast, 159, ridPgn)
	]
resultis abmsg
]