-- File: PressNetSendFile.mesa: Sends a Press.bits file to a printing server.
-- Last Edited: February 8, 1982 11:38 AM By: GWilliams
--Can now address Platemaker.
DIRECTORY
IODefs USING[CR, ReadChar, ReadLine, ReadOctal, WriteChar, WriteLine, WriteString],
PressDefs USING [PressPassword],
PressNetDefs USING [PageAttributes,
--PressNetErr,
Printer,
PrinterAttributes,
CloseConnection,
GetPrinterAttributes,
PrinterReady,
SendPageAttributes,
SetRetries,
SendLine
],
SegmentDefs USING[DataSegmentHandle, DefaultBase, DeleteDataSegment, NewDataSegment, Read, SegmentAddress],
StreamDefs USING[NewWordStream, DiskHandle, ReadBlock, SetPosition, StreamPosition],
StringDefs USING [UpperCase];
PressNetSendFile: PROGRAM
IMPORTS IODefs, PressNetDefs, SegmentDefs, StreamDefs, StringDefs
=
BEGIN OPEN IODefs, PressDefs, PressNetDefs, SegmentDefs, StreamDefs, StringDefs;
IllegalPressFile: ERROR = CODE;
NoImageInFile: ERROR = CODE;
FileTooShort: ERROR = CODE;
--Pack Variables
--Procs
SendImage: PROC[]=
--Raises no signals or errors
BEGIN
attr: PageAttributes;
bandWidth: CARDINAL = 16;
bitPage: LONG CARDINAL;
ch: CHARACTER;
pa: PrinterAttributes;
bufferWordLen: CARDINAL = 1024;
bufferByteLen: CARDINAL = 2*bufferWordLen;
h: DiskHandle;
bufferSeg: DataSegmentHandle;
wordsRead: CARDINAL;
filename: STRING ← [200];
inCoreAddress: POINTER TO ARRAY [0..bufferWordLen) OF CARDINAL;
streamPosition: StreamPosition;
scratch: CARDINAL;
firstBand, lastBand, bitMargin, bitWordCt, frstScan, lstScan: CARDINAL;
scanNum: CARDINAL;
totalBands: LONG CARDINAL;
bandNum: LONG CARDINAL;
roundedBytesPerBand: LONG CARDINAL;
device: CARDINAL ← 0;
UNTIL (device=1 OR device = 2) DO
WriteString["Where to send. Enter 1 for Stinger, 2 for PlateMaker: "];
device ← ReadOctal[]; PutCR[]; ENDLOOP;
WriteString["Filename to read: "];
ReadLine[filename]; PutCR[];
pa ← GetPrinterAttributes[(IF device=1 THEN Stinger ELSE DLP1)];
--first see that there is a file on the disk
[h] ← NewWordStream[filename, Read];--open file for testing.
bufferSeg ← NewDataSegment[DefaultBase, (bufferWordLen+255)/256];
inCoreAddress ← SegmentAddress[bufferSeg];
streamPosition ← 3*2;--address by bytes, not words
SetPosition[h, streamPosition];
scratch ← h.get[h];
IF scratch # PressPassword THEN ERROR IllegalPressFile;
bandNum ← firstBand ← h.get[h];
lastBand ← h.get[h];
bitMargin ← h.get[h];
bitWordCt ← h.get[h];
IF ~(lastBand > firstBand) THEN ERROR NoImageInFile;
IF ~(bitWordCt>0) THEN ERROR NoImageInFile;
FOR i: CARDINAL IN [1..3] DO scratch ← h.get[h]; ENDLOOP; --get bitPage
bitPage ← scratch;
totalBands ← lastBand-firstBand+1;--calculate figures for scan line transfers
roundedBytesPerBand ← ((bitWordCt * bandWidth + 1023)/1024) * 1024 * 2;--i.e., # of bytes in band, rounded up to 1K bound
--set up this record before calling the printer (this sequence useful for debugging)
frstScan ← firstBand*bandWidth; lstScan ← (lastBand*bandWidth) + bandWidth-1;
attr ← [scanDirection: pa.scanDirection, filler: 0, firstScan: frstScan, lastScan: lstScan, margin: bitMargin, bitWc: bitWordCt];
--OK, we think the file is fine, try to get the printer.
ch ← ’Y;
WHILE ch=’Y DO
IF PrinterReady[(IF device=1 THEN Stinger ELSE DLP1), 2] THEN EXIT;
ch ← ’r;
WHILE ~(ch=’Y OR ch=’N) DO
WriteString["Stinger not available, retry? (Y/N): "L];
ch ← UpperCase[ReadChar[]]; WriteChar[ch]; WriteChar[CR];
ENDLOOP;
ENDLOOP;
IF ch#’Y THEN GOTO exit;
WriteLine["Sending file"];
SendPageAttributes[@attr];--send the attributes of this page
--transfer the file.
SetRetries[60000];--for debugging on remote end
FOR bandNum IN [0..totalBands)
DO
streamPosition ← bandNum*roundedBytesPerBand+(2048 * bitPage);--i.e., in TfsPages, bandNum*tfsPagesPerBand + 1
SetPosition[h, streamPosition];--now positioned to first word of band.
FOR scanNum IN [0..bandWidth)
DO
IF h.endof[h] THEN ERROR FileTooShort;
wordsRead ← ReadBlock[h, inCoreAddress, bitWordCt];
SendLine[inCoreAddress];
ENDLOOP;
ENDLOOP;
DeleteDataSegment[bufferSeg];
h.destroy[h];
CloseConnection[];
WriteLine["All ok"L];
EXITS
exit=>NULL;
END;--of SendImage
--def these locally for debugging and to avoid the net
SendImage[];--debugging.
END. -- PressNetSendFile.mesa
-- Last Edited: November 20, 1981 7:17 PM By: GWilliams
-- Last Edited: December 10, 1981 6:52 PM By: GWilliams
--fixed stream addressing bug.