-- PDInterpOutputRavenImpl.mesa
-- Copyright (C) 1984, Xerox Corporation.  All rights reserved.
-- Michael Plass, 20-Sep-84 12:34:40
	-- 
DIRECTORY Environment, PDFileFormat, PDInterpBasic, PDInterpOutput, PDInterpBitmap, RavenSlotDriver, PDInterpSysCalls, PDQueue, Process;
	
PDInterpOutputRavenImpl: PROGRAM
	IMPORTS PDInterpBitmap, RavenSlotDriver, PDInterpSysCalls, PDQueue, Process
	EXPORTS PDInterpOutput
= BEGIN
	
bitsPerWord: NAT = Environment.bitsPerWord;
currentHerald: PDFileFormat.Herald;
currentStartImage: PDFileFormat.StartImage;
currentBandNumber: NAT ← 0;
bandWords: INT ← 0;
band: PDInterpBitmap.BitmapDesc ← [sOrigin: 0, fOrigin: 0, sMin: 0, fMin: 0, sSize: 0, fSize: 0, pointer: NIL, rast: 0, lines: 0];
bandWordsAllocated: INT ← 0;
	
CurrentBandDesc: PROC RETURNS [PDInterpBitmap.BitmapDesc] = {
	band.sOrigin ← currentHerald.bandSSize*(currentBandNumber+currentStartImage.passBands);
	PDInterpBitmap.Clear[band];
	RETURN [band]
	};
	
StartImage: PUBLIC PROC [herald: PDFileFormat.Herald, startImage: PDFileFormat.StartImage, request: PDQueue.Request]
	RETURNS [PDInterpBitmap.BitmapDesc] = {
	rast: NAT = (startImage.fSizePage+bitsPerWord-1)/bitsPerWord;
	lines: INT = herald.bandSSize;
	words: INT = rast*lines;
	currentHerald ← herald;
	currentStartImage ← startImage;
	currentBandNumber ← 0;
	IF words > bandWordsAllocated THEN {
		IF band.pointer # NIL THEN PDInterpSysCalls.FreeSpace[band.pointer];
		band.pointer ← PDInterpSysCalls.AllocateSpace[words];
		bandWordsAllocated ← words;
		};
	band.sOrigin ← 0;
	band.fOrigin ← startImage.fMinPage;
	band.sMin ← 0;
	band.fMin ← 0;
	band.sSize ← herald.bandSSize;
	band.fSize ← rast*bitsPerWord;
	band.rast ← rast;
	band.lines ← herald.bandSSize;
	bandWords ← words;
	RETURN [CurrentBandDesc[]]
	};
	-- 
EndBand: PUBLIC PROC RETURNS [PDInterpBitmap.BitmapDesc] = {
	RavenSlotDriver.HyperStore[
		sourcePtr: band.pointer,
		destOffset: bandWords*currentBandNumber,
		wordCount: bandWords
		];
	currentBandNumber ← currentBandNumber + 1;
	RETURN [CurrentBandDesc[]]
	};
	
EndImage: PUBLIC PROC [request: PDQueue.Request] = {
	PrintPage[];
	};
	
PrintPage: PROC = {
	successCode: RavenSlotDriver.SuccessCode;
	slowMargin: CARDINAL ← currentHerald.bandSSize*currentStartImage.passBands;
	fastMargin: CARDINAL ← band.fOrigin;
	numberOfLines: CARDINAL ← currentHerald.bandSSize*currentStartImage.nBands;
	scanLineLength: CARDINAL ← band.fSize;
	FOR copyNum: CARDINAL IN [0..currentHerald.copies) DO
		DO 
			s:RavenSlotDriver.PrinterStatus;
			successCode ← RavenSlotDriver.PrintPage[
				slowMargin: slowMargin,
				fastMargin: fastMargin,
				numberOfLines: numberOfLines,
				scanLineLength: scanLineLength,
				paperSource: top,
				paperStacking: aligned
				];
			SELECT successCode FROM
				warning => EXIT;
				error => {
					WHILE (s←RavenSlotDriver.GetStatus[])#standBy DO
						IF s = warming THEN 
						    Process.Pause[Process.MsecToTicks[10000]];
						ENDLOOP
					};
				ENDCASE => EXIT; -- ok
			ENDLOOP;
		ENDLOOP;
	};

ReprintLastPage: PUBLIC PROC [copies: CARDINAL] = {
	IF currentHerald.password # PDFileFormat.passwordValue THEN RETURN;
	currentHerald.copies ← copies;
	PrintPage[];
	};
	
currentHerald.password ← 0;
	
END.