	.TITLE PPA.
 
/ .... EDIT #4 .... 2 DEC 69
 
/COPYRIGHT 1969, 1970, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
 
/PPA. --- BACKGROUND/FOREGROUND MONITOR SYSTEM.
/IOPS PAPER TAPE PUNCH HANDLER
/DAVE LENEY
/9-29-69	NEW ^R PROCESSING.
/CALLING SEQUENCE:
	/CAL+.DAT SLOT (9-17)
	/FUNCTION (12-17)
	/N ARGUMENTS WHERE N IS A FUNCTION OF FUNCTION
	/(NORMAL RETURN)
.MED=3
.SCOM=100
PSF=700201
PCF=700202
PSA=700204
PLS=700206
PSB=700244
	.GLOBL PPA.
PPA.	JMS	SWAP
	0			/FGD BUSY REG
	0			/BGD BUDY REG
	0			/FGD CLOSE REG
	0			/BGD CLOSE REG
PPSWCH	XX			/ION OR IOF
PPWRD6	XX		/ION OR IOF OR DBR
PPOUT	XX			/RETURN POINTER
/START OF DATA REGS (BOTH BACKUP AND LIVE
PPWD10	XX			/JMP TO FUNCTION
	XX			/WHOSE CAL(0=FGD,1=BGD)
	XX			/DAT SLOT#
PPSTPS	XX			/UNIT # AND CAL ADDR.- STOP SWITCH
PPDMOD	XX			/WD 14 - DATA MODE
TPLBH	XX			/WD 15 - LINE BUFFER ADDR
PPWPC	XX			/-WC OR BUFFER SIZE POINTER
PPWD17	XX			/WD 17 - REAL TIME REQUEST
/END OF DATA REGS
/START OF FUNCTION TABLE
	JMP	PPINIT		/1=,INIT
	JMP	PPIGN		/2=.OPER - IGNORED
	JMP	PPER06		/3=.SEEK - ERROR
	JMP	PPIGN		/4=.ENTER - IGNORED
	JMP	PPIGN		/5=.CLEAR - IGNORED
	JMP	PPCLOS		/6=.CLOSE
	JMP	PPIGN		/7=.MTAPE - IGNORED
	JMP	PPER06		/10=.READ,.REALP - ERROR
PWRITE	JMP	PPWRT		/11=.WRITE,.REALW
PPBHLD	0			/12=.WAIT,.WAITR - BY CAL HANDLER
	JMP	PPER06		/13=.TRAN - ERROR
PPSC35	0			/.SCOM+35 STORAGE (CAL HANDLER NEEDS THIS HERE)
	PPSTOP		/STOP FGD I/O
	PPSTOP		/STOP BGD I/O
	0		/HANDLER ID = 0
/INIT, WAIT, AND CLOSE PTP ROUTINE
PPINIT	LAC (64
	DAC* PPA.+16		/STANDARD BUFFER SIZE
PPNIT	LAC* (.SCOM+55
PPFST	DAC PPCHAR		/FIRST CHAR SWITCH
PPIOTA	JMS* PPCHAR	/.SETUP-IOT AC
PPLBP	PSF		/FIRST DATA WORD
TPTEMP	PTPINT		/TEMP STORAGE
TPWC	LAC PPEOFJ		/-WC
PTPAC	DAC PPNIT		/INTERRUPT AC
PP5CH	JMP PPEOF		/CHAR COUNT
PPCLOS	LAW -1
	DAC PP5CH
	DAC PPWPC
	DAC TPWC
	LAC PPDMOD		/LAST DATA MODE
	SZA
PPEOFJ	JMP PPEOF		/TRAILER ONLY
	LAC PPEOFL		/EOF BUFFER
	DAC TPLBH
LAW0	LAW		/PUNCH TRAILER
	DAC TPEOF
	JMP TPSIOB+3
TPDMS	JMP TPSIOB		/IOPS BINARY
	JMP TPSIMB		/IMAGE BINARY
	JMP TPSIOA		/IOPS ASCII
	JMP TPSIMA		/IMAGE ASCII
	JMP TPSDMP		/DUMP
LAW177	LAW 177		/ILLEGAL DATA MODE
LAW13	LAW 13		/ILLEGAL DATA MODE
PPER07	LAW 7		/ILLEGAL DATA MODE
	SKP
PPER06	LAW 6		/ILLEGAL FUNCTION
PPERNN	DAC PP5CH	
	LAC	PPSTPS
	DAC	PPEROR+2		/PRINT CAL ADDR
	LAC	PP5CH
	XOR	(4000		/SET TERMINAL ERROR BIT
	JMS	PPERRQ
	JMP	PPIGN		/GO CLEAR FLAGS
PPTMP1	0
PPEOFL	PPEOFB
PPTPDJ	JMP TPDMS
PPGETJ	JMP* PPGETD
/WRITE PTP ROUTINE
PPWRT	LAW -1
	DAC PP5CH
	LAC PPDMOD		/DATA MODE
	TAD PPTPDJ		/SETUP FOR MODE DISMISS
	DAC TPDMSJ
	LAC PPDMOD
	TAD PPGETJ
	DAC PPGET
/GET ARGUMENTS AND SET UP FOR PUNCHING
	LAC TPLBH
	TAD (2
	DAC PPLBP	/FIRST DATA WORD
	LAC PPWPC	/WORD PAIR COUNT
	TAD	(1
	DAC	PPWPC
	DAC TPWC
TPDMSJ	XX	/JMP TO PROPER SETUP
PPCHK	TAD* PPLBP	/COMPUTE CHECKSUM
	ISZ PPLBP
	JMP PPBCK
TPSIOB	777000		/ZERO DATA MODE
	AND* TPLBH
	DAC* TPLBH
TPSIOZ	LAW	-2
	TAD	PPWPC
	DAC	PPWPC
PP7S	LAW -1
PPBCK	ISZ TPWC
	JMP PPCHK
	TAD* TPLBH		/HEADER
	CMA
	ISZ TPLBH
	DAC* TPLBH		/CHECKSUM INTO HEADER
	LAC TPLBH	/OUTPUT HEADER
	TAD PP7S
	DAC PPLBP	/FIRST DATA WORD
PPIOBG	JMS PPNTP
	JMS PPBIN	/BINARY
	JMS PPARCT	/ODD PARITY
	SZL
	XOR (100	/PARITY BIT 7
	XOR (200	/BIT 8
	JMP PPSA	/PUNCH ALPHA
TPSDMP	TAD	TPSIOZ
	DAC	PPWPC
	LAC	TPLBH
	DAC PPLBP	/DUMP BEGIN LOCATION
TPSIMB	JMS PPNTP	/IMAGE BINARY
	JMS PPBIN
PPSB	DAC PPIOTA		/SET IOT AC
	LAC (PSB			/SET IOT TO BINARY
	DAC PPIOT		/SET IOT TO BINARY
	LAC PPGET
	DAC PTPFLY	/INTERRUPT EXIT
/
/COMMON EXIT SEQUENCE FOR CAL LEVEL.
/AND INTERRUPT LEVEL ENTRIES.
/
/
PPNOR	JMS	PPNRDY		/OUT OF TAPE TEST.
	LAC*	(.SCOM+54		/ADDRESS OF
	DAC	PPTMP1		/CALL4
	LAC	(400200		/RAISE TO API LEVEL 0.
	ISA
PPIOF	IOF			/TURN PIC OFF.
	LAC	PPWRD6
	SAD	(DBR
	SKP			/INTERRUPT.
	JMP	PPT.6		/CAL.
	JMS*	PPTMP1
	PPA.+7			/PC
	PPSC35			/SAVED .SCOM+35
PPT.6	LAC	PPSC35		/RESTORE IN INTERRUPT
	DAC*	(.SCOM+35	/HANDLER FLAG.
PPFCLR	SKP			/NOP IF FLAG TO BE CLEARED
	DZM	PPA.+1		/FOREGROUND BUSY FLAG.
PPBCLR	SKP			/NOP IF FLAG TO BE CLEARED
	DZM	PPA.+2		/BACKGROUND BUSY FLAG.
	LAC	(SKP		/RESET
	DAC	PPFCLR		/SWITCHES.
	DAC	PPBCLR
	LAC	PPIOTA		/AC FOR IOT
PPIOT	XX			/IOF OR IOT
	LAC PTPAC		/RESTORE AC.
	DBK			/FROM LEVEL 0.
	XCT PPA.+5		/ION OR IOF
	XCT PPA.+6		/ION OR IOF OR DBR
	XCT .+1
	JMP* PPA.+7		/RETURN POINTER.
/
/
TPSIMA	JMS PPNTP	/IMAGE ASCII
	JMS PPCNT	/WD COUNT + FETCH
PPSA	DAC PPIOTA		
	LAC (PSA		/SET IOT TO ALPHA
	JMP PPSB+2
PPNTP	0
	LAW -7
	DAC PPBITC		/INIT BIT COUNTER
	JMP* PPNTP
PPGETD	PPIOBG
	TPSIMB
	PPIOAG
	TPSIMA
	TPSIMB
/BINARY CHARACTER UNPACKING ROUTINE
PPBIN	0	/BINARY UNPACKING
	LAC PPBHLD	/REST OF LAST WORD
	ISZ PP5CH
	JMP PPBINA	/WORD BEGUN
	LAW -3	/CHAR COUNT
	DAC PP5CH
	JMS PPCNT	/WORD COUNT+FETCH
PPBINA	RTL
	RTL
	RTL
	DAC PPBHLD	/SAVE REST OF WORD
	RAL
	AND (77	/MASK OUT CHAR
	JMP* PPBIN
PPCNT	0	/WORD COUNT+FETCH
	LAC* PPLBP	/GET WORD
	ISZ PPLBP		/NEXT WORD
	ISZ PPWPC
	JMP* PPCNT
	JMP TPBLK
TPBLKA	SAD (15			/CR OR ESC
	LAW 215
	JMS PPUNCH
TPBLK	LAC PPDMOD		/GET DATA MODE
	CLA!CMA!SNA
	JMS PPNULL		/IOPS BIN
TPEOF	JMP PPEMPT
PPEOF	LAC PPEMJ
	DAC TPEOF
	LAW -334
	JMS PPNULL
PPEMJ	JMP PPEMPT
/INTERRUPT HANDLER
PTPINT	DAC PTPAC
	LAC* (0	/PIC RETURN
	DAC PPOUT
	LAC PPIONC
	DAC PPSWCH
	LAC* (.SCOM+35
	DAC PPSC35
	CLA!CMA
	DAC* (.SCOM+35
	DZM* (0
	PCF		/CLEAR PUNCH FLAG
PPIONC	ION
	LAC (DBR
	DAC PPWRD6
	DZM PPSTPS		/CLEAR STOP SWITCH
	LAC PPA.+1
	TAD PPA.+2
	SNA		/HAS STOP BEEN ISSUED
	JMP PPIGN		/YES
PTPFLY	XX	/JMP TO LAST PUNCH
/COUNT PARITY BITS (ODD OR EVEN IN LINK ON RETURN)
PPARCT	0
	DAC PPSAVA	/SAVE C(AC)
	DZM PPONEB
PPARCN	RAR		/NEXT BIT
	SZL
	ISZ PPONEB		/NO. OF ONE BITS
	ISZ PPBITC
	JMP PPARCN
	LAC PPONEB
	RAR	/PUT IN LINK
	LAC PPSAVA	/ORIGINAL CHAR
	JMP* PPARCT
/PROCESS IOPS ASCII
TPSIOA	DZM PPFST		/FIRST CHAR SWITCH
PPIOAG	JMS PPNTP
	ISZ PP5CH	/5/7 ASCII UNPACK
	JMP PPGET5	/THIS PAIR BEGUN
	JMS PPCNT	/WORD COUNT+FETCH
	DAC PP57T	/FIRST PART
	JMS PPCNT
	DAC PP57B	/LAST PART
	LAW -5	/RESET CHAR CCOUNT
	DAC PP5CH
PPGET5	LAW -10
	DAC PP57C	/SHIFT LOOP 7+1/2 TIMES
PPGET6	LAC PP57B
	RAL
	ISZ PP57C
	JMP PPGET7
	AND (177	/GOT CHAR
	SAD (15	/CARRIAGE RETURN
	JMP TPBLKA
	SAD (175			/ALTMODE(ESC)
	JMP TPBLKA
	JMP PPGET8
PPGET7	DAC PP57B
	LAC PP57T
	RAL
	DAC PP57T
	JMP PPGET6
PPGET8	XOR LAW0
/IOPS ASCII SPECIAL SCAN
	DAC PPCHAR	/SAVE CHARACTER
	SAD LAW0
	JMP PPGET	/NULL
	SAD LAW177
	JMP PPGET	/DELETE
	SAD LAW11
	JMP PPHT	/HORIZONTAL TAB
	SAD LAW12
	JMP PPLF	/LINE FEED
	SAD LAW13
	JMP PPVT	/VERTICAL TAB
	SAD LAW14
	JMP PPFF	/FORM FEED
	LAC PPFST
	SNA	/FIRST CHAR SWITCH
	JMS PPLINE	/FIRST
	LAC PPCHAR	/RESTORE CHARACTER
	JMS PPARCT	/EVEN PARITY
	SZL
	XOR (200	/SET BIT 8
	JMP PPSA
PPTSTF	0
	LAC PPFST	/FIRST CHAR SWITCH
	SNA
	JMP* PPTSTF
	JMP PPGET
PPHT	LAC PPFST
	SNA
	JMS PPLINE	/NEW LINE
LAW11	LAW 11		/HORIZONTAL TAB
	JMS PPUNCH
	LAW 377		/DELETE
	JMS PPUNCH
	JMP PPNFST
PPLF	JMS PPTSTF
	JMS PPLINE	/LINE FEED
	JMP PPNFST
PPVT	JMS PPTSTF
	LAW 213		/VERTICAL TAB
	JMS PPUNCH
	LAW -4
	DAC PPCOUN
	LAW 377		/DELETES
	JMS PPUNCH
	ISZ PPCOUN
	JMP .-3
PPNFST	DAC PPFST
PPGET	JMP* PPGETD		/MODIFIED JMP* PPGETD
PPFF	JMS PPTSTF
LAW14	LAW 14	/FORM FEED
	JMS PPUNCH
	LAW -40
	JMS PPNULL
	JMP PPNFST
/PUNCH NULL CHARACTERS
PPNULL	0
	DAC PPCOUN	/SAVE COUNT
	CLA		/NULL
	JMS PPUNCH
	ISZ PPCOUN
	JMP .-3
	JMP* PPNULL
/PUNCH LINE FEED (LEGAL OR DEFAULT)
PPLINE	0
LAW12	LAW 12		/LINE FEED
	DAC PPFST	/NOT FIRST
	JMS PPUNCH
	JMP* PPLINE
/HANDLER INITIATED PUNCH ROUTINE
PPUNCH	0
	DAC PPIOTA
	LAC (PSA
	DAC PPIOT
	LAC (JMP* PPUNCH
	JMP PPNOR-1
/SET UP SWITCH IN EXIT ROUTINE TO
/CLEAR FOREGROUND OR BACKGROUND BUSY REGISTER AS
/A FUNCTION OF WORD11, AND PLACE IOF IN PUNCH
/IOT REGISTER SO THAT NO NEW I/O WILL BE STARTED.
PPEMPT	JMS	CLFLAG
/IS THIS DEVICE INVOLVED IN I/O BUSY SITUATION.
PPT31	LAC*	(.SCOM+52		/ADDRESS OF
	DAC	PPTMP1		/I/O BUSY TESTER.
	LAC	(400200		/PROTECT
	ISA
	IOF
	LAC	(PPA.
	JMS*	PPTMP1
	DBK			/UNPROTECT.
	ION
	JMS	PPREAL		/CHECK FOR REAL TIME REQUEST.
	JMP	PPNOR		/NOT REAL TIME REQUEST.
	LAC*	(.SCOM+51		/ADDR. OF
	DAC	PPTMP1		/REAL TIME
	LAC	(400200		/PROCESSOR.
	ISA			/PROTECT.
	IOF
	LAC	PPWD17
	JMS*	PPTMP1
	DBK			/UNPROTECT.
	ION
	JMP	PPNOR
/
/SUBROUTINE TO DETERMINE IF THIS I/O
/WAS A REAL TIME REQUEST OR NOT.
/CALLING SEQUENCE:	JMS	PPREAL
/		(NOT REAL)
/		(REAL)
PPREAL	0
	LAC	PPWD17		/NON 0 IF REAL TIME.
	SNA
	JMP*	PPREAL		/NOT .REALW
	LAC	(JMP PWRITE
	SAD	PPWD10		/JMP FUNCTION
	ISZ	PPREAL		/.REALW
	JMP*	PPREAL
/SUBROUTINE TO SET UP CLEARING OF THE
/APPROPRIATE BUSY FLAG (AT PROTECTED EXIT TIME)
/AND NULL (IOF) PAPER TAPE PUNCH IOT
/REGISTER.
CLFLAG	0
	LAC	PPIOF		/IOF
	DAC	PPIOT
	LAC	PPA.+11		/WORD 11 OF LIVE REGS.
	SZA			/0=FGRD, 1=BGRD
	JMP	.+4
	LAC	(NOP		/FOREGROUND
	DAC	PPFCLR
	JMP*	CLFLAG
	LAC	(NOP		/BACKGROUND
	DAC	PPBCLR
	JMP*	CLFLAG
/
PPIGN	JMS	CLFLAG		/CLEAR BUSY FLAG
	JMP	PPNOR
/THIS SUBROUTINE IS EXECUTED (XCT) 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	PPA.+5		/ION OR IOF
	DBK			/FROM LEVEL 0
	JMP*	SWAP
/
PPERRQ	0		/ENTER ERROR INTO QUEUE WITH B/F BITS SET
	DAC	PPEROR
	LAC	PPWD10+1		/WHOSE CAL
	RAR
	LAC	PPEROR
	XOR	(2000		/BGD
	SNL		/IS IT FGD?
	XOR	(3000		/YES
	DAC	PPEROR
	LAC*	(.SCOM+66
	DAC	PPTMP1
	LAC	(400200
	ISA
	IOF
PPEROR	XX		/ERROR #
	JMS*	PPTMP1
	XX		/ERROR INFO
	DBK
	ION
	JMP*	PPERRQ
/
PPSTOP	0		/STOP I/O ROUTINE
	LAC	(400200
	ISA
	IOF
	LAC	PPCTLR		/DO NOT HANG IF
	SZA!CLA			/^R IN PROGRESS.
	JMP	PPCLER
	LAC	PPA.+1
	TAD	PPA.+2		/TEST I/O UNDERWAY
	SZA!CLA
	CMA
PPCLER	DAC	PPSTPS	/SET STOP SWITCH ACCORDINGTO I/O SWITCHES
	DZM	PPA.+1		/CLEAR I/O SWITCHES
	DZM	PPA.+2
	DZM	PPA.+3		/CLEAR CLOSE SWITCHES
	DZM	PPA.+4
	DZM	PPCTLR		/^R FLAG
	DBK
	ION
	LAC	PPSTPS		/CHECK FOR I/O COMPLETE
	SZA
	JMP	.-2		/WAIT HERE UNTIL DONE
	JMP*	PPSTOP
/
/SUBROUTINE TO CALL A ROUTINE IN THE RESIDENT MONITOR
/TO INITIATE A NOT READY REQUEST.
/CALLING SEQUENCE:
/	JMS	PPMSG
/	(RETURN)		/WITH PPCTLR NON-0 IF
/			/REQUEST HONORED; 0
/			/OTHERWISE.
/
PPMSG	0
	LAC	PPCTLR		/^R FLAG.
	SZA!CMA			/AVOID DUPLICATE CALL.
	JMP*	PPMSG		/.ERR 004 ALREADY REQUESTED.
	DAC	PPCTLR		/SET ^R IN PROGRESS FLAG.
	LAC	PPA.+11		/0=FGD; 1=BGD.
	DAC	PPARG1
	LAC*	(.SCOM+64	/POINTER TO ^R QUEUER.
	DAC	PPTMP1
	LAC	(400200		/RAISE TO LEVEL 0.
	ISA
	IOF			/PIC OFF.
	JMS*	PPTMP1		/GO TO ^R QUEUER.
PPARG1	XX			/0=FGD; 1=BGD.
	.ASCII	/PP/
	.LOC	.-1		/2-LETTER DEVICE NAME.
	0			/UNIT NUMBER.
	PPFRA+300000		/RETURN ADDRESS AT LEVEL 3.
	PPFRA+300000		/SAME FOR BGD.
	DZM	PPCTLR		/TERM. ERROR; REQUEST NOT HONORED.
	ION			/REQUEST O.K.
	DBK			/FROM LEVEL 0.
	JMP*	PPMSG
/
/SUBROUTINE ENTERED AT API LEVEL 3, PIC OFF, WHEN ^R FROM KEYBOARD
/IS ASSOCIATED WITH THE PUNCH.
/
PPFRA	0
	DZM	PPCTLR		/CLEAR ^R FLAG.
	IORS
	AND	(400
	SNA
	JMP	.+3
	JMS	PPMSG		/NOT READY CONDITION
	JMP	PPIOTB+1		/NOT CORRECTED.
	LAC	PPIOTA		/AC FOR IOT.
PPIOTB	XX			/EXECUTE SAVED IOT.
	ION
	DBR			/FROM LEVEL 3.
	JMP*	PPFRA
/
/TEST FOR OUT OF TAPE CONDITION.
/
PPNRDY	0
	IORS
	AND	(400
	SNA
	JMP*	PPNRDY		/TAPE O.K.
	LAC	PPIOT		/SAVE IOT.
	DAC	PPIOTB
	LAC	PPIOF		/DEFER IOT.
	DAC	PPIOT
	JMS	PPMSG		/INITIATE NOT READY REQUEST.
	JMP*	PPNRDY
PPCTLR	0			/^R IN PROGRESS IF NON-0.
/
/VARIABLES
/
PPEOFB	001505	/EOF HEADER
PPCHAR	0	/CHARACTER STORAGE FOR SCAN
PPSAVA=TPWC		/AC CONTENTS
PPBITC=TPLBH		/BIT COUNTER
PPONEB=TPTEMP		/ONE BIT STORAGE
PP57C=TPWC		/5/7 COUNT
PP57T=PPBHLD		/5/7FIRST PART
PP57B	0		/5/7 LAST PART
PPCOUN	0		/NUMBER OF PUNCHES
	.END
