	.TITLE LPA.
 
/ .... EDIT #5 .... 28 JAN 70
 
/COPYRIGHT 1969, 1970, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
 
/LPA.---BACKGROUND/FOREGROUND MONITOR SYSTEM.
/LPA.=LINE PRINTER (647) HANDLER.
/CALLING SEQUENCE:
	/CAL+.DAT SLOT (9-17)
	/FUNCTION
	/N ARGUMENTS, WHERE N IS A FUNCTION OF FUNCTION.
	/NORMAL RETURN
LSDF=706501	/SKIP ON DONE FLAG -CONNECTED TO INTERRUPT
LPCB=706502	/CLEAR DONE FLAG, CLEAR PRINTER BUFFER,
		/SET DONE FLAG
LPL1=706566	/LOAD PRINTER BUFFER 1 CHAR (AC 12-17)
LPL2=706526	/LOAD PRINTER BUFFER 2 CHAR (AC 6-11, 12-17)
LPLD=706546	/LOAD PRINTER BUFFER 3 CHAR (AC 0-5,6-11,12-8)
LSEF=706601	/SKIP ON ERROR FLAG -NOT CONNECTED TO
		/INTERRUPT
LPCF=706602	/CLEAR DONE FLAG
LPPB=706606	/CLEAR DONE FLAG, SELECT PRINTER,
		/PRINT BUFFER, CLEAR BUFFER, SET DONE FLAG
LPLS=706626	/LOAD SPACING BUFFER (AC 15-17), SPACE
		/SET DONE FLAG
.MED=3
.SCOM=100
	.GLOBL LPA.
LPA.	JMS	SWAP
	0			/FOREGROUND BUSY REGISTER.
	0			/BACKGROUND BUSY REGISTER
	0			/FOREGROUND .CLOSE REGISTER.
	0			/BACKGROUND .CLOSE REGISTER.
LPSWCH	XX			/ION OR IOF
LPWRD6	XX			/ION OR IOF OR DBR
LPTOUT	XX			/RETURN POINTER
/START OF DATA REGISTERS.
/FOR SINGLE-USER DEVICES.
LPWD10	XX			/JMP FUNCTB
	XX			/CAL OWNER (0=F,1=B)
LV2WC	XX			/.DAT SLOT NUMBER
LPSVAC	XX			/UNIT NUMBER (BITS 0-2) CAL ADDRESS (BITS 3-17)
LPWPC	XX			/W14
LPLBHP	XX			/W15 - LINE BUFFER ADDRESS.
LP8CT	XX			/W16
LPWD17	XX			/W17
/END OF DATA REGISTERS.
/BEGINNING OF FUNCTION DISPATCH TABLE.
	JMP LPIN			/.INIT
	JMP LPIGN			/.OPER - IGNORED.
	JMP LPERR			/.SEEK - ERROR.
	JMP LPIGN			/.ENTER - IGNORED.
	JMP LPIGN			/.CLEAR - IGNORED.
	JMP LPCLOS		/.CLOSE
	JMP LPIGN			/.MTAPE - IGNORED
	JMP LPERR			/.READ (.REALR) - ERROR
LWRITE	JMP LPWRT			/.WRITE (.REALW)
LV2FC	XX			/.WAIT (.WAITR) PROCESSED COMPLETELY BY CAL HANDLER
	JMP LPERR			/.TRAN - ERROR
SCOM35	XX			/STORAGE FOR .SCOM+35
	LPSTP		/FGRD STOP I/O SUBROUTINE
	LPSTP		/BGRD STOP I/O SUBROUTINE
LPZERO	0		/HANDLER ID
LPTMP1	0
/.CLOSE LPT ROUTINE
LPCLOS	DZM LV2WC		/FORM FEED.
	DZM PGECNT	/INITIALIZE #LINES/PAGE COUNTER
	CLA!CMA
	DAC LPIOAC
LPSPCE	LAC (LPLS		/SET UP TO DO I/O DURING
	JMP LPCOMD	/PROTECTED EXIT.
/INIT LPT ROUTINE.
LPIN	CLA!CMA
	DAC LV2WC
	DAC LV2FC		/SET UP FOR FORM FEED ON INTERRUPT FROM LPCB.
	LAC (64		/52 (DECIMAL)---RETURN
	DAC* LPA.+16		/STANDARD LINE BUFFER SIZE TO USER.
LPIN2	LAC* (.SCOM+55		/ - ONCE ONLY CODE.
	DAC LPIN2
LP57T	JMS* LPIN2	/.SETUP - THESE 6 REGISTERS ARE OVERLAYED.
	LSDF
	LPINT
LPWORD	LAC .+2
LPHRTB	DAC LPIN2
LP3CHR	JMP .+1
	LAC (LPCB
LPCOMD	DAC LPIOT
/COMMON EXIT SEQUENCE FOR CAL LEVEL
/AND INTERRUPT LEVEL ENTRIES.
/
/
LPNOR	JMS	LPNRDY		/CHECK IF DEVICE READY.
	LAC*	(.SCOM+54		/ADDRESS
	DAC	LPTMP1		/OF CALL4
LPTIO	JMS	LPRAIS		/RAISE TO API LEVEL 0, TURN PIC OFF.
	LAC	LPWRD6
	SAD	LPDBR
	SKP			/INTERRUPT
	JMP	LPT.6		/CAL
	JMS*	LPTMP1
	LPA.+7			/PC
	SCOM35
LPT.6	LAC	SCOM35		/RESTORE IN INTERRUPT
	DAC*	(.SCOM+35		/HANDLER FLAG.
LPFCLR	NOP			/NOP IF FGRD BUSY FLAG NOT TO BE CLEARED
LPBCLR	NOP			/NOP IF BGRD BUSY FLAG NOT TO BE CLEARED
	LAC	(NOP		/RESET
	DAC	LPFCLR		/SWITCHES.
	DAC	LPBCLR
	LAC	LPIOAC		/AC FOR IOT
LPIOT	XX			/IOF OR IOT
	LAC LPSVAC		/RESTORE AC.
	DBK			/FROM LEVEL 0.
	XCT LPA.+5		/ION OR IOF
	XCT LPA.+6		/ION OR IOF OR DBR
	XCT .+1
	XCT .+1
	JMP*	LPA.+7		/RETURN POINTER
LPNRDY	0
	LSEF
	JMP* LPNRDY		/DEVICE READY.
	LAC LPIOT		/SAVE IOT.
	DAC LPIOTB
	LAC LPIOF		/EFFECTIVELY DEFER IOT.
	DAC LPIOT
	JMS LPMSG		/INITIATE NOT READY REQUEST.
	JMP* LPNRDY
/SUBROUTINE TO CALL A ROUTINE IN THE RESIDENT MONITOR TO
/INITIATE A NOT READY REQUEST.
/CALLING SEQUENCE:
/	JMS LPMSG
/	RETURN WITH LPCTLR NON-0 IF REQUEST
/	HONORED; 0 OTHERWISE.
/
LPMSG	0
	LAC	LPCTLR		/^R FLAG.
	SZA!CMA			/AVOID DUPLICATE CALL.
	JMP*	LPMSG		/.ERR 4 ALREADY REQUESTED.
	DAC	LPCTLR		/SET ^R IN PROGRESS FLAG.
	LAC	LPA.+11		/0=FGRD, 1=BGRD
	DAC	LPARG1
	LAC*	(.SCOM+64		/POINTER TO ^R QUEUER
	DAC	LPTMP1
	JMS	LPRAIS		/TO API LEVEL 0, PIC OFF
	JMS*	LPTMP1		/GO TO ^R QUEUER
LPARG1	XX			/0=FGRD, 1=BGRD
	.ASCII /LP/
	.LOC	.-1
	0			/UNIT NUMBER
	LPFRA+200000		/RETURN ADDRESS AT LEVEL 2
	LPFRA+200000		/SAME FOR BGRD
/
	DZM	LPCTLR		/TERMINAL ERROR. REQUEST NOT HONORED
	JMS	LPLOWR		/PIC ON, DEBREAK FROM LV 0
	JMP*	LPMSG
/
/SUBROUTINE ENTERED AT API LEVEL 2, PIC OFF, WHEN ^R FROM KEYBOARD
/IS ASSOCIATED WITH LINE PRINTER.
/
LPFRA	0
	DZM	LPCTLR		/CLEAR ^R FLAG
	LSEF
	JMP	.+3
	JMS	LPMSG		/NOT READY CONDITION
	JMP	LPIOTB+1		/NOT CORRECTED.
	LAC	LPIOAC		/AC FOR IOT
LPIOTB	XX			/EXECUTE SAVED IOT.
	ION
LPDBR	DBR			/FROM LEVEL 2
	JMP*	LPFRA
/WRITE LPT ROUTINE.
LPWRT	CLA!CMA
	DAC LP5CH		/INIT BEFORE CALL TO .LPCONV
	LAC LPA.+14		/DATA MODE BITS 15-17
	SAD (2
	JMP LPOK		/IOPS ASCII
	LAW 5007		/ILLEGAL DATA MODE.
	JMP	LPER06+1
LPOK	LAC* LPLBHP	/WPC
	AND (377000
	DAC LPWPC
	DZM LV2WC
	ISZ LPLBHP	/MOVE L.B. POINTER (IN USER'S
	ISZ LPLBHP	/AREA) TO 1ST DATA WORD.
	DZM LV2FC		/IOPS ASCII MODE NO FORM CONTROL
	LAW 17770		/INITIALIZE SWITCH AT LPCONV
	DAC LPCONV
LPTSTR	LAW 17775		/3 CHAR. COUNTER FOR
	DAC LP3CHR	/3/6 WORD.
	DZM LPWORD	/CLEAR DATA WORD.
	/THIS ROUTINE GETS THE
	/NEXT 7-BIT ASCII CHAR.
	/FROM THE 5/7 LINE BUFFER (USER'S AREA)
	/IT RETURNS WITH IT RIGHT
	/JUSTIFIED IN AN OTHERWISE
	/CLEAR AC.
	/LP5CH MUST BE SET TO
	/777777 BEFORE THE INITIAL
	/CALL TO LPCONV, LPWPC TO WPC INCLUDING HEADER.
	/LPLBHP TO 1ST DATA WORD IN L.B.(USER'S AREA)
LPCONV	LAW 17770		/INITIALIZATION
	DAC LP8CT		/FOR
	LAC (SAD LPCTAB	/CONTROL CHAR.
	DAC LPVTST		/SCANNING.
	ISZ LP5CH		/MODIFIED FOR HOR. TAB.
	JMP LPGET5	/THIS 5/7 PAIR NOT EXHAUSTED.
	LAW 17000
	TAD LPWPC
	DAC LPWPC		/SKIP ON NON 0.
	SNA!SPA
	JMP LPEND		/WORD PAIRS EXHAUSTED
	LAC* LPLBHP	/PICK UP NEXT
	DAC LP57T		/WORD PAIR
	ISZ LPLBHP
	LAC* LPLBHP
	DAC LP57T+1
	ISZ LPLBHP
	LAW 17773		/RESET CHAR. COUNTER
	DAC LP5CH		/FOR THIS WORD PAIR
LPGET5	LAW 17770
	DAC LP57T+2	/GO THROUGH SHIFT LOOP 7 1/2 TIMES.
LPGET6	LAC LP57T+1
	RAL
	ISZ LP57T+2
	JMP .+3
	AND (177		/GOT CHARACTER.
	JMP LPCON1
	DAC LP57T+1
	LAC LP57T
	RAL
	DAC LP57T
	JMP LPGET6
LPCON1	SAD (177
	JMP LPCONV	/DELETE RUBOUTS.
	TAD LPM40		/-40
	SPA
	JMP LPVTST	/CHAR. <40---CONTROL CHAR.
	TAD (777700	/-100
	SPA
	TAD (40
	TAD (100		/140-176 MAPPED INTO 100-136
LPCON2	AND (77		/6-BIT TRIMMED.
	XOR LPWORD	/CONSTRUCT 3/6 WORD.
	ISZ LP3CHR	/3 CHARACTER COUNTER.
	JMP LPCON3
			/DATA WORD COMPLETE.
	ISZ LV2WC		/INDEX DATA WORD COUNT
	DAC LPIOAC
	LAC (LPLD
	JMP LPCOMD
LPCON3	RTL		/SHIFT CHARS. LEFT
	RTL
	RTL
	AND (777700	/IN CASE LINK WAS ON.
	DAC LPWORD
	JMP LPCONV	/GET NEXT CHAR.
/END OF CHARACTER STRING OR CARR. RETURN (IOPS ASCII)
LPEND	LAC (47
	DAC LV2WC
	JMP LPHT3		/PAD LAST WORD WITH SPACES.
/CONTROL CHARACTER ROUTINE. - CHAR. IN AC.
LPVTST	XX		/SAD LPCTAB-SAD LPCTAB+7
	JMP LPFORM	/VERTICAL FORM CONTROL CHAR.
	ISZ LPVTST	/SAD LPCTAB+N-SAD LPCTAB+N+1
	ISZ LP8CT
	JMP LPVTST
	SAD LPCTAB+10
	JMP LPEND		/CARRIAGE RETURN.
	SAD LPCTAB+11
	JMP LPHT		/HORIZONTAL TAB.
	JMP LPCONV	/DELETE MEANINGLESS CHAR.
/COMPUTE FORM CONTROL CODE AND PLACE
/IN LV2FC
LPFORM	LAC LP8CT
	DAC LV2FC		/L.B.H. IN D.B.
	JMP LPCONV
/CONVERT HOR. TAB TO N SPACES, WHERE N IS THE NUMBER
/NECESSARY TO HAVE THE NEXT CHAR. IN COLUMN 9,17,25,33,41...,113.
LPHT	LAC LV2WC		/DATA WORD COUNT
	CLL!RAL		/X2
	TAD LV2WC		/X3
	TAD (4
	TAD LP3CHR	/CURRENT WORD CHAR. COUNTER.
	TAD LPMIN8	/-8 (DECIMAL)
	SMA!SZA
	JMP .-2
	TAD LPOVRP
LPHT3	DAC LPHRTB
	LAC (JMP LPHT2
	DAC LPCONV
LPHT2	LAW 40
	ISZ LPHRTB
	JMP LPCON2
LPMIN8	LAW 17770
	DAC LPCONV
	JMP LPCONV
/INTERRUPT HANDLER.
LPPIC	DAC LPSVAC	/SAVE AC
	LAC* LPZERO
	DAC LPTOUT	/SAVE PC, L, EM, MP
	LAC LPION
	JMP LPSTON
LPINT	JMP LPPIC		/PIC ENTRY.
	DAC LPSVAC	/API ENTRY, SAVE AC.
	LAC LPINT		/PC, L, EM, MP
	DAC LPTOUT
	DZM	LPINT	/0=API ENTRY
	IORS		/READ I/O STATUS
	SMA!CLA
LPM40	LAW 17740		/PIC OFF -- BUILD IOF
	TAD LPION		/PIC ON -- ION
LPSTON	DAC LPSWCH
	LAC* (.SCOM+35
	DAC SCOM35
	CLA!CMA
	DAC* (.SCOM+35
	LAC	LPINT
	SZA
	DZM*	LPZERO	/PIC ENTRY
	LPCF		/CLEAR LPT DONE FLAG
LPION	ION		/ENABLE PIC
	LAC LPDBR
	DAC LPWRD6
	DZM	LPSTPS		/CLEAR STOP I/O SWITCH
	LAC	LPA.+1
	TAD	LPA.+2
	SNA			/DO NOT CONTINUE I/O IF 
	JMP	LPEMPT		/BOTH BUSY FLAGS ARE  0
/INITIATE MORE OUTPUT IF APPROPRIATE.
LPTOK	LAC LV2WC
	SNA
	JMP LPEMPT
	SPA
	JMP LPCLSE
	SAD (50		/BUFFER FULL.
	JMP LPSPPR
	JMP LPTSTR
LPCLSE	DZM LV2WC
LPSPPR	LAW 17706		/IS PAGE FULL?
	TAD PGECNT
	SZA!CMA		/YES - FORM FEED
	LAC LV2FC
	SAD LPOVRP
	JMP LPOVER	/OVERPRINT.
	AND (7
	SAD (7
	DZM PGECNT	/INIT #LINES/PAGE CNT
LPVMOV	DAC LPIOAC	/VERT. SPACING BEFORE PRINTING
LPOVRP	LAW 17776
	DAC LV2FC
	JMP LPSPCE
/WORD COUNT EXHAUSTED.
LPOVER	DZM LV2WC
	ISZ PGECNT	/INCREMENT #LINES/PAGE CNT
	LAC (LPPB		/PRINT BUFFER.
	JMP LPCOMD
PGECNT	0	/INITIALIZED TO 0 WHEN AT TOP OF FORM
		/INCREMENTED BY 1 UNTIL 58(10) LINES
		/  HAVE BEEN OUTPUT OR FORM FEED IS ENCOUNTERED
LPIOAC	0
	/TABLE OF ASCII CONTROL CHAR'S SCANNED BY LPT IN IOPS ASCII MODE
LPCTAB	777752	/LF-EVERY LINE 0	---12
	777761	/DC1-EVERY 2ND LINE 1	---21
	777762	/DC2-EVERY 3RD LINE 2 	---22
	777753	/VT-EVERY 6TH LINE 3	---13
	777763	/DC3-EVERY 10TH LINE 4	---23
	777764	/DC4-EVERY 20TH LINE 5	---24
	777760	/DLE-OVER PRINT 6	---20
	777754	/FF-TOP ON NEXT FORM 7	---14
	777755	/CR		---15
	777751	/HT		---11
LP5CH	0		/5/7 COUNTER
/SET UP SWITCH IN EXIT ROUTINE TO
/CLEAR FOREGROUND OR BACKGROUND BUSY REGISTER AS
/A FUNCTION OF WORD11, AND PLACE IOF IN LPT
/IOT REGISTER SO THAT NO NEW I/O WILL BE STARTED.
LPEMPT	JMS	CLFLAG
/IS THIS DEVICE INVOLVED IN I/O BUSY SITUATION.
LPT31	LAC*	(.SCOM+52		/ADDRESS OF
	DAC	LPTMP1		/I/O BUSY TESTER
	JMS	LPRAIS		/RAISE TO LEVEL 0 AND TURN OFF PIC
	LAC	(LPA.
	JMS*	LPTMP1
	JMS	LPLOWR
/
/ROUTINE TO DETERMINE IF THIS I/O
/WAS A REAL TIME REQUEST OR NOT.
	LAC	LPWD17		/NOW 0 IF REAL TIME.
	SNA
	JMP	LPNOR		/NOT .REALW
	LAC	(JMP LWRITE
	SAD	LPWD10		/JMP FUNCTION
	SKP			/.REALW
	JMP	LPNOR		/NOT REAL TIME REQUEST.
	LAC*	(.SCOM+51		/ADDR. OF
	DAC	LPTMP1		/REAL TIME PROCESSOR
	JMS	LPRAIS
	LAC	LPWD17
	JMS*	LPTMP1
	JMS	LPLOWR
	JMP	LPNOR
/SUBROUTINE TO SET UP CLEARING OF THE
/APPROPRIATE BUSY FLAG (AT PROTECTED EXIT TIME)
/AND NULL (IOF) LINE PRINTER IOT
/REGISTER.
CLFLAG	0
	LAC	LPIOF		/IOF
	DAC	LPIOT
	LAC	LPA.+11		/WORD 11 OF LIVE REGS.
	SZA			/0=FGRD, 1=BGRD
	JMP	.+4
	LAC	LPFBSY		/FOREGROUND
	DAC	LPFCLR
	JMP*	CLFLAG
	LAC	LPBBSY		/BACKGROUND
	DAC	LPBCLR
	JMP*	CLFLAG
/
LPERR=.
LPER06	LAW	5006		/ILLEGAL FUNCTIONS
	DAC	LPTMP1
	LAC	LPSVAC
	DAC	LPTAUX
	LAC	LPA.+11
	SZA
	LAC	(3000		/BGRD
	XOR	LPTMP1
	JMS	LPTERR
/
LPIGN	JMS	CLFLAG		/CLEAR BUSY FLAG
	JMP	LPNOR
/THIS SUBROUTINE IS EXECUTED BY THE
/CAL HANDLER VIA WORD 0 OF THIS I/O
/HANDLER JUST PRIOR TO GIVING CONTROL
/TO THE HANDLER AT THE APPROPRIATE
/ENTRY IN THE FUNCTION DISPATCH TABLE.
SWAP	0
	XCT	LPA.+5		/ION OR IOF
	DBK			/FROM LEVEL 0
	JMP*	SWAP
/STOP I/O SUBROUTINE
LPSTP	0
	JMS	LPRAIS		/PROTECT
	LAC	LPCTLR		/DO NOT HANG IF
	SZA!CLA			/^R IN PROGRESS.
	JMP	LPCLER
	LAC	LPA.+1		/IF I/O IS UNDER WAY SET
	TAD	LPA.+2		/STOP SWITCH.
	SZA!CLA
	CMA
LPCLER	DAC	LPSTPS
LPFBSY	DZM	LPA.+1		/CLEAR I/O BUSY SWITCHES.
LPBBSY	DZM	LPA.+2
	DZM	LPA.+3		/CLEAR CLOSE SWITCHES.
	DZM	LPA.+4
	DZM	LPCTLR		/^R FLAG
	JMS	LPLOWR		/ALLOW INTERRUPTS.
	LAC	LPSTPS		/WAIT UNTILL I/O IS DONE.
	SZA
	JMP	.-2
	JMP*	LPSTP
LPSTPS	0			/STOP I/O SWITCH.
LPCTLR	0			/^R IN PROGRESS IF NON-0.
/
/
/SUBROUTINE TO CAUSE OUTPUTTING OF ERROR MESSAGE.
LPTERR	0
	DAC	LPTLAW		/LAW CODE
	LAC*	(.SCOM+66
	DAC	LPTMP1
	JMS	LPRAIS		/RAISE TO API LEVEL 0 AND TURN OF PIC.
LPTLAW	XX			/LAW CODE
	JMS*	LPTMP1
LPTAUX	XX
	JMS	LPLOWR
	JMP*	LPTERR
/
/SUBROUTINE TO RAISE TO API LEVEL 0
/AND TURN OFF PIC.
LPRAIS	0
	LAC	(400200
	ISA
LPIOF	IOF
	JMP*	LPRAIS
/SUBROUTINE TO DEBREAK FROM API LEVEL 0
/AND TURN ON PIC.
LPLOWR	0
	DBK
	ION
	JMP*	LPLOWR
	.END
