Google
 

Trailing-Edge - PDP-10 Archives - BB-JR93N-BB_1990 - 10,7/mon/dzint.mac
There are 6 other files named dzint.mac in the archive. Click here to see a list.
TITLE	DZINT	-- INTERRUPT SERVICE FOR DZ11 - V022
SUBTTL	Dave McClure/DMcC/DBD/TL 17 APR 90

	SEARCH	F,S
	$RELOC
	$HIGH

;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED
;  OR COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (c) DIGITAL EQUIPMENT CORPORATION
;1978,1979,1980,1982,1984,1986,1988,1990.
;ALL RIGHTS RESERVED.

.CPYRT<1978,1990>


XP VDZINT,022

	ENTRY	DZINT		;LOAD DZINT IF LIBRARY SEARCH
DZINT:
	SUBTTL	DISPATCH TABLE

DZDSP::	JRST	SCNTYP		;DATA OUT
	JRST	DSCTYP		;DATA SET CONTROL

	JRST	DZSEC		;CALLED ONCE A SECOND
				; CHECK INTERRUPT ENABLES
				; AND DO DATASET TIMING
	JRST	DZINI		;INIT
	JRST	DZCHP		;CHANGE HARDWARE PARAMETERS
	JRST	DZLPC		;SET LINE PARAM CTRL MSG
	POPJ	P,		;SET ELEMENT
	POPJ	P,		;REMOTE STATION STUFF
	JRST	DZOFL		;OFF LINE TEST
IFE 1,<
DSCOFS==DSCOF'N##		;OFFSET INTO DSCTAB
DLSMXD==DL'N'MXD##		;MAX LINE NUMBER
DLSMXL==DL'N'MXL##		;MAXIMUM DATASET NUMBER
DLSOFS==DL'N'OFS##		;OFFSET FROM HARDWARE TO LINTAB
>;IFE 1
	SUBTTL	DZ11 HARDWARE DEFINITIONS

;DZ11 OFFSETS INTO DEVICE DEFINITIONS

DZCSR==0			;CONTROL AND STATUS
DZRBUF==2			;RECEIVER BUFFER
DZLPR==2			;LINE PARAMETER REGISTER
DZTCR==4			;TRANSMIT CONTROL
DZDTR==5			;DATA TERM READY FLAGS (HIGH BYTE OF TCR)
DZRNG==6			;RING INDICATOR
DZMSR==6			;COMBINATION OF RING AND CARRIER
DZCAR==7			;CARRIER
DZTBUF==6			;TRANSMITTER BUFFER
DZBRK==7			;BREAK (HIGH OF TBUF)

;CSR BIT DEFINITIONS

DZTRDY==1B20			;TRANSMIT READY
DZTIEN==1B21			;TRANSMIT INTERRUPT ENABLE
DZSILO==1B22			;SILO ALARM
DZSIEN==1B23			;SILO ALARM ENABLE
DZTXLN==7B27			;TRANSMIT LINE NUMBER
DZRRDY==1B28			;RECEIVE READY
DZRIEN==1B29			;RECIEVE INTERRUPT ENABLE
DZMSCN==1B30			;MASTER SCAN ENABLE
DZCLR==1B31			;CLEAR (RESET)

;RECEIVER BUFFER DEFINITIONS

DZRDVL==1B20			;DATA VALID
DZROVR==1B21			;OVER RUN
DZRFRM==1B22			;FRAME ERROR
DZRPAR==1B23			;PARITY ERROR
DZRLIN==7B27			;LINE NUMBER

;LINE PARAMETER DEFINITIONS

DZ1RXO==1B23			;RECEIVE ON
DZ1FRQ==17B27			;LINE FREQUENCY
	;0B27			;50 BAUD
	;1B27			;75 BAUD
	;2B27			;110 BAUD
	;3B27			;NOT USED (134.5 BAUD)
	;4B27			;150 BAUD
	;5B27			;300 BAUD
	;6B27			;600 BAUD
	;7B27			;1200 BAUD
	;10B27			;1800 BAUD
	;11B27			;2000 BAUD
	;12B27			;2400 BAUD
	;13B27			;3600 BAUD
	;14B27			;4800 BAUD
	;15B27			;7200 BAUD
	;16B27			;9600 BAUD
	;17B27			;NOT USED (19200 BAUD)
DZ1OPA==1B28			;ODD PARITY
DZ1PEN==1B29			;PARITY ENABLE
DZ1STP==0B30			;STOPCODE 1 BIT
DZ2STP==1B30			;STOPCODE 2 BITS
DZ1CHL==3B32			;CHARACTER LENGTH
	;0B32			;5 LEVEL
	;1B32			;6 LEVEL
	;2B32			;7 LEVEL
   DZ8BIT==3B32			;8BIT CHARACTER DEFINITION
DZ1LNO==7B35			;LINE NUMBER
	SUBTTL	INITIALIZATION CODE

;DEVICE-DEPENDENT PORTION OF INITIALIZATION CODE
; CALLED BY SYSINI WITH LINE NUMBER IN RH(J) & LDB ADDR IN U

DZINI:	HRRZI	T1,1-M.DZNL##(J) ;GET LINE NUMBER FROM TTYINI
	JUMPN	T1,CPOPJ##	;SKIP OVERHEAD OF REDUNDANT CALLS
	PUSHJ	P,SAVE3##	;SAVE P1 - P3
	MOVE	P1,[DZ11BA-10]	;BASE ADDRESS FOR DZ11'S
	MOVEI	T1,DZ11BA_-^D18	;GET UNIBUS ADAPTER NUMBER
	MOVEI	T2,DZ11IV	;GET INTERRUPT VECTOR INDEX
	PUSHJ	P,AUTVIA##	;COMPUTE ADDRESS OF INTERRUPT INSTRUCTION
	MOVE	P2,T1		;SAVE IT AWAY HERE
	HRLI	P2,DZ0VA##	;FIRST DZ11 INTERRUPT ROUTINE
	SETZM	P3		;WILL BE DZMAXL
DZINI2:	TRNE	P3,7		;FIRST LINE ON THIS DZ11 ?
	JRST	DZINI4		;NO SO HAVE ALREADY CLEARED IT
	ADDI	P1,10		;NEXT DZ11 ADDRESS
	MOVE	T1,P1		;FOR CALL TO UBGOOD
	PUSHJ 	P,UBGOOD##	;SEE IF THAT DZ11 EXISTS
	  JRST	DZINI8		;HAVE DONE ALL LEGAL ONES
	LDB	T1,[POINT 6,P3,32] ;GET DZ11 UNIT NUMBER
	SETZM	DZDSTB##(T1)	;INITIALIZE THE DATASET TABLE
	MOVEI	T1,DZCLR	;TO MASTER CLEAR THE DZ11
	WRIO	T1,DZCSR(P1)	;CLEAR THE DZ11
	MOVSI	T2,1		;STALL COUNTER
	TIOE	T1,DZCSR(P1)	;DID INITIALIZE CLEAR YET ?
	SOJG	T2,.-1
	JUMPLE	T2,DZINI8	;DZ11 IS BAD
	MOVSI	T1,(XPCW)	;BUILD JSR DZ#VA
	MOVE	T2,T1		;BUILD JSR DZ#VB
	HLR	T1,P2		;ADD DZ#VA
	HRRI	T2,DZ0VB##-DZ0VA##(T1) ;ADD DZ#VB
	DMOVEM	T1,(P2)		;ADD JSR'S TO INTERRUPT TABLE
	ADD	P2,[2*<DZ0VB##-DZ0VA##>,,2] ;SO NEXT SET OF JSR'S ARE RIGHT
	MOVEI	T1,DZTIEN!DZRIEN!DZMSCN ;TRANS & RECV INT ENABLE
	WRIO	T1,DZCSR(P1)	; AND MASTER SCAN ENABLE
DZINI4:	SETZM	DZCHTB##(P3)	;CLEAR OUTPUT WORD FOR LINE
	MOVSI	T1,DZMABL	;AUTOBAUD LINE FLAG
	ANDM	T1,DZMSTS##(P3)	;REINITIALIZE DATASET QUEUE WORD
	MOVEI	T1,1		;BIT FOR DATA TERMINAL READY
	MOVE	T2,P3		;COPY LINE NUMBER
	ANDI	T2,7		;LEAVE ONLY RELATIVE LINE NUMBER
	LSH	T1,(T2)		;MAKES RIGHT BIT FOR DTR
	MOVE	T3,LINTAB##(P3)	;GET LDB ADDRESS
	MOVE	T3,LDBDCH##(T3)	;GET CHAR BITS
	TRNE	T3,LDRDSD##	;DATASET LINE?
	JRST	[BCIOB	T1,DZDTR(P1) ;YES--PREVENT DATASET FROM ANSWERING
		 MOVSI	T1,DZMABL ;MAKE ALL DATASET LINES
		 IORM	T1,DZMSTS##(P3) ;BE AUTOBAUD LINES
		 JRST	DZINI5]	;DONE WITH DATASET CASE
	BSIOB	T1,DZDTR(P1)	;LOCAL LINE--SET DTR NOW
	SKIPL	DZMSTS##(P3)	;SKIP IF AUTOBAUD LINE
	TROA	T2,DZ1RXO!5B27!DZ8BIT ;NO--RECEIVER ON, 300 BAUD,
DZINI5:	IOR	T2,SPD240	;YES--SETUP HIGH-SPEED AUTOBAUD VALUES
	WRIO	T2,DZLPR(P1)	; 1 STOP BIT, 8BIT CHARS
	AOS	P3		;HAVE SETUP NEXT LINE
	CAIE	P3,M.DZNL##	;HAVE WE DONE ALL LINES WE SHOULD ?
	JRST	DZINI2		;DO NEXT LINE
DZINI8:	MOVEM	P3,DZMAXL	;SAVE NUMBER OF DZ11 LINES
	SETZM	DZLIEN		;INITALIZE ERROR COUNTER
	POPJ	P,0		;RETURN FROM DZINI
	SUBTTL	CHECK TO SEE IF DZ11 IS OFFLINE

;HERE TO SEE IF DZ11 IS "OFFLINE" = NO DZ11 FOR LINE
; CALLED WITH U POINTING TO LDB
DZOFL:	LDB	T1,LDPLNO##	;GET LINE NUMBER
	CAMGE	T1,DZMAXL	;IN RANGE ?
	AOS	(P)		;YES SO IS "ONLINE"
	POPJ	P,0
	SUBTTL	ONCE A TICK ROUTINE

;HERE ONCE A TICK TO START OUTPUT
DZSTO::	PUSH	P,T1		;SAVE QUEUE POINTER ADDRESS
DZST1:	PUSHJ	P,TOTAKE##	;ANYTHING TO TYPE?
	  JRST	DZQTIC		;NO--TIME DATASETS
	MOVEI	T1,L1RCHP##
	TDNE	T1,LDBBYT##(U)	;IS CHP SET?
	PUSHJ	P,DZCHP		;YES--GO SET SPEED
	LDB	T1,LDPLNO##	;GET LINE NUMBER
	MOVE	T1,DZMSTS##(T1)	;AND CORRESPONDING BITS
	TLNE	T1,DZMABW!DZMCRW ;IN CARRIER OR AUTOBAUD WAIT?
	JRST	DZST2		;YES--IGNORE THIS FOR OUTPUT
	SKIPGE	LDBDCH##(U)	;DON'T START AN ACTIVE LINE
	PUSHJ	P,XMTCHR##	;ANY CHARS FOR THIS LINE?
	  JRST	DZST2		;NO--GO TO NEXT
	PUSHJ	P,SCNTYP	;START LINE
	PUSHJ	P,CLRIRM##	;CLEAR IRMA
DZST2:	MOVE	T1,(P)		;RESTORE QUEUE POINTER ADDRESS
	JRST	DZST1		;GO SEE IF MORE TO DO

	;HERE ONCE A TIC TO TIME DATASETS

DZQTIC:	POP	P,T1		;RESTORE T1
	SKIPG	DZTTQN##	;ANY LINES IN OUR QUEUE?
	POPJ	P,		;NO, DONE
	PUSHJ	P,SAVE4##	;SAVE A REGISTER
	PUSHJ	P,SAVT##
	SETZ	P1,		;START AT BEGINNING
DZQTC1:	CAML	P1,DZMAXL	;DONE (DON'T PAGEFAIL ON NX DZ!)
	POPJ	P,		;YES, DONE WITH TIC PROCESSING
	SCNOFF			;STOP WORLD
	LDB	T1,DZQPTM	;GET TIME TO GO
	SOSL	T1		;COUNT DOWN
	 DPB	T1,DZQPTM	; MORE TO GO, PUT TIME LEFT BACK
	JUMPN	T1,[SCNON	;EXIT IF NOTHING TO DO YET
		    JRST  DZQTC2] ;NEXT LINE...
	HRRZ	T1,DZMSTS##(P1)	;TIME'S UP, GET ROUTINE TO CALL
	HLLZS	DZMSTS##(P1)	;CLEAR ROUTINE, SAVE STATUS
	SOS	DZTTQN##	;REMOVED 1 ENTRY
	SCNON			;QUEUE IS FREE
	SKIPN	T1		;IS ROUTINE LEGAL?
	 STOPCD	DZQTC2,DEBUG,DQR,	;++ILLEGAL QUEUE ROUTINE
	MOVE	U,LINTAB##(P1)	;FIND LDB FOR THIS LINE
	PUSHJ	P,(T1)		;CALL ROUTINE
DZQTC2:	SKIPE	DZTTQN##	;MORE TO DO?
	 AOJA	P1,DZQTC1	;YES, DO NEXT LINE
	POPJ	P,		;NO, EXIT
	SUBTTL	ONCE A SECOND SERVICE FOR DZ11'S

;HERE ONCE A SECOND
; CHECK DZ11 FOR INTERRUPT ENABLES
; CHECK DZ11 FOR DATASET LINES
DZSEC:	PUSHJ	P,SAVE3##	;SAVE P1, P2, AND P3
	SETZ	P1,		;LINE NUMBER
	MOVE	P2,[DZ11BA-10]	;ADDRESS OF FIRST DZ11
	MOVEI	P3,DZDSTB##-1	;DATASET TABLE FOR DZ11
SCNCK1:	CAML	P1,DZMAXL	;DONE ALL LINES YET ?
	POPJ	P,0		;RETURN TO CLOCK
	TRNE	P1,7		;FIRST LINE IN GROUP ?
	  JRST	SCNCK3
	ADDI	P2,10		;NEXT DZ11 ADR
	AOS	P3		;NEXT DATASET WORD
	RDIO	T1,DZMSR(P2)	;GET MODEM STATUS REGISTER
	HRL	T1,(P3)		;GET OLD DATASET STATUS
	TLC	T1,(T1)		;LH IS NEW.XOR.OLD
	MOVEM	T1,(P3)		;SAVE IT
	RDIO	T1,DZCSR(P2)	;GET CONTROL AND STATUS REGISTER
	TRNE	T1,DZTIEN	;STILL HAVE TRANSMIT ENABLE ?
	TRNN	T1,DZRIEN	;AND RECEIVE ENABLE ?
	  JRST [MOVEI T1,DZTIEN!DZRIEN!DZMSCN ;ALL ENABLES
		BSIO T1,DZCSR(P2) ;RESET ENABLES
		AOS DZLIEN	;COUNT TIMES THEY DROP
		JRST SCNCK3 ]
SCNCK3:	MOVE	U,LINTAB##(P1)	;GET LDB FOR LINE
	MOVE	T1,LDBDCH##(U)	;GET DEVICE BITS
	TRNN	T1,LDRDSD##	;IS THIS A DATASET LINE ?
	  JRST	SCNCK8		;NOT DATASET SO DONE WITH LINE
	MOVE	T1,P1		;COPY LINE NUMBER
	ANDI	T1,7		;LEAVE RELATIVE LINE NUMBER
	MOVE	T2,[401,,401]	;BITS FOR MASK
	LSH	T2,(T1)		;MAKE MASK FOR CARRIER ETC.
	AND	T2,(P3)		;LEAVE ONLY BITS FOR THIS LINE
	TLNN	T2,-1		;DID ANYTHING CHANGE FOR THIS LINE ?
	  JRST	SCNCK8		;NO
	TLNE	T2,377		;DID RING CHANGE?
	  TRNN	T2,377		;YES, IS IT NOW ASSERTED?
	CAIA			;NO, CONTINUE (IN CASE CARRIER CHANGED TOO)
	  JRST	SCNCKR		;RING CHANGED TO ASSERTED, PROCESS NEW CALL
	TLNN	T2,377*400	;DID CARRIER CHANGE?
	  JRST	SCNCK8		;NO, ON TO NEXT LINE
	TRNE	T2,377*400	;DID CARRIER GO AWAY ?
	  JRST	SCNCKO		;NO, CARRIER ON
	JRST	SCNCKF		;YES, CARRIER OFF

SCNCK8:	AOJA	P1,SCNCK1	;ON FOR NEXT LINE
	SUBTTL	ROUTINES FOR DATASET CONTROL

;THIS CODE CREATES A SMALL FRONT END FOR THE KS, AND ONLY TELLS
;SCNSER ABOUT RING, CARRIER AFTER THE ACTION IS OVER.
;
;WE ARE CALLED AT CLOCK LEVEL BY THE ONCE/SECOND DATASET POLL,
;AND BY THE ONCE/TIC EVENT TIMER IN DZQTIC

;OUR IDEA OF LINE STATUS IS KEPT IN THE LH OF DZMSTS

	;BITS IN THE LH OF DZMSTS
	DZMABL==(1B0)	;AUTOBAUD LINE
	DZMCRW==(1B1)	;IN CARRIER WAIT
	DZMABW==(1B2)	;IN AUTOBAUD WAIT
	DZMABF==(1B3)	;AUTOBAUD IGNORE NEXT CHAR
	DZMCON==(1B4)	;CARRIER IS ON
	DZMLSP==(1B5)	;AUTOBAUDING AT LOW "LOOK" SPEED
	DZMLIB==(1B6)	;LAST INPUT WAS BREAK (FRAMING ERROR)
	;BITS 7-17 ARE TIME FIELD (MAX = 2047 TICS, OR APPROX 34 SEC @ 60HZ)

DZQPTM:	POINT	11,DZMSTS##(P1),17	;POINTER TO TIME FIELD

;HERE ON A RING TRANSITION

SCNCKR:	MOVSI	T2,DZMCON	;WAS CARRIER ON?
	TDNE	T2,DZMSTS##(P1)	;...
	 JRST	[MOVEI	T2,1	;YES, START WITH LINE ZERO
		 LSH	T2,(T1)	;POSITION TO CORRECT LINE
		 ANDCAM	T2,(P3)	;ENSURE RING IS SEEN AGAIN ON NEXT POLL
		 PUSHJ	P,REPCOF ;BETTER TELL SCNSER
		 JRST	SCNCK8]	;...
	MOVEI	T2,1		;START WITH LINE 0
	LSH	T2,(T1)		;POSITION TO CORRECT LINE
	MOVEI	T1,ST.NRL	;ALLOWED TO ANSWER?
	TDNE	T1,STATES##	;...
	 JRST	SCNCK8		;NO, IGNORE RING
	BSIOB	T2,DZDTR(P2)	;ANSWER THE PHONE
	MOVSI	T1,DZMCRW	;IN CARRIER WAIT
	IORM	T1,DZMSTS##(P1)	;FOR NOW
	MOVE	T1,[CRWTMO,,^D<20K>] ;WAIT 20 SECONDS FOR CARRIER
	PUSH	P,T2		;SAVE LINE BIT
	PUSHJ	P,DZQADD	;ADD TO QUEUE
	POP	P,T2		;GET LINE BIT BACK
	LSH	T2,^D8		;SHIFT OVER TO CARRIER REGISTER
	TDNE	T2,(P3)		;IS CARRIER UP NOW TOO?
	 JRST	SCNCKO		;YES, DO CARRIER UP PROCESSING AS WELL
	JRST	SCNCK8		;DONE WITH THIS LINE

;HERE IF CARRIER DOESN'T APPEAR, OR AUTOBAUD FAILS

CRWTMO:	PUSHJ	P,DZUADR	;GET UNIBUS ADDRESS
	MOVE	T4,LDBDCH##(U)	;GET SOME BITS
	TRNN	T4,LDRDSD##	;IS THIS A DATASET?
	JRST	ABRTMO		;NO--HANDLE AUTOBAUD TIMEOUT
	BCIOB	T1,DZDTR(T2)	;YES--HANG UP
REPCOF:	MOVSI	T1,DZMCON!DZMCRW!DZMABW!DZMABF ;GET STATUS BITS
	ANDCAM	T1,DZMSTS##(P1)	;CAN'T BE PROCESSING A CALL
	MOVE	U,P1		;SET UP U
	MOVEI	T3,DSTOFF##	;CODE FOR CARRIER WENT AWAY
	PJRST	DSCREC##	;BETTER TELL SCNSER
;HERE WHEN CARRIER COMES ON

SCNCKO:	MOVSI	T2,DZMCON	;CARRIER ON BIT
	IORB	T2,DZMSTS##(P1)	;SET IT
	TLNN	T2,DZMCRW	;IN CARRIER WAIT?
	JRST	[MOVEI	T3,DSTON## ;NO, BETTER TELL SCNSER
		 JRST	SCNDST]
	.CREF	DZMABL
	SKIPL	T2,DZMSTS##(P1)	;AUTOBAUD LINE?
	 JRST	[MOVE	T1,[DZCXUP,,^D<2K>] ;NO, WAIT 2 SEC FOR CARRIER
		 PUSHJ	P,DZQADD	;TO BECOME SOLID
		 JRST	SCNCK8]		;THEN TELL SCNSER
	MOVE	T1,P1		;COPY LINE NUMBER
	ANDI	T1,7		;ONLY WITHIN DZ
	TLNE	T2,DZMLSP	;LOOKING AT LOW SPEED?
	 TDOA	T1,SPD300	;YES, TURN ON AT 300 BAUD
	IOR	T1,SPD240	;TURN ON RECEIVER AT 2400 BAUD
	WRIO	T1,DZLPR(P2)	;...
	MOVE	T1,[DZABCS,,^D<2K>] ;WAIT 2 SEC FOR CARRIER TO SETTLE
	PUSHJ	P,DZQADD	;...
	JRST	SCNCK8		;DONE WITH THIS LINE

;HERE 2 SEC AFTER LAST CARRIER ON TRANSITION FOR A NON-AUTOBAUD DATASET
;OR AT END OF AUTOBAUD SEQUENCE

DZCXUP:	PUSHJ	P,DZUADR	;FIND DZ ON UNIBUS
	MOVE	T4,LDBDCH##(U)	;GET SOME BITS
	TRNN	T4,LDRDSD##	;IS THIS A DATASET?
	JRST	ABRFIN		;NO--HANDLE AUTOBAUD TERMINATION
	TIONB	T1,DZCAR(T2)	;YES--IS CARRIER STILL THERE?
	 JRST	REPCOF		;NO, IT DIED
	MOVSI	T3,DZMCRW	;CARRIER WAIT BIT
	TDNN	T3,DZMSTS##(P1)	;WERE WE IN CARRIER/AUTOBAUD SEQUENCE?
	JRST	ABRFIN		;NO--IT WAS .TOEAB.  DON'T SIGNAL RING AGAIN.
	MOVSI	T3,DZMCRW!DZMABW!DZMLIB ;CAN'T BE IN THESE STATES ANYMORE
	ANDCAM	T3,DZMSTS##(P1)	;SO GET OUT
	MOVE	U,P1		;SET UP U FOR SCNSER
	MOVEI	T3,DSTRNG##	;RING
	PUSHJ	P,DSCREC##	;SCNSER
	MOVEI	T3,DSTON##	;CARRIER UP
	PJRST	DSCREC##	;SCNSER

;HERE 2 SEC AFTER AUTOBAUD DATASET HAS SETTLED DOWN

DZABCS:	PUSHJ	P,DZUADR	;FIND DZ ON UNIBUS
	TIONB	T1,DZCAR(T2)	;IS CARRIER STILL UP?
	 JRST	REPCOF		;NO, IT DIED
	MOVSI	T3,DZMABF	;FLUSH BIT
	SCNOFF			;PREVENT FUNNY RACES
	ANDCAM	T3,DZMSTS##(P1)	;MAKE SURE NOT FLUSHING
	MOVSI	T3,DZMABW!DZMCRW;AND AUTOBAUD WAIT
	IORM	T3,DZMSTS##(P1)	;HAS BEGUN
	SCNON			;OK NOW
	MOVE	T1,[CRWTMO,,^D<30K>] ;ALLOW 30 SEC FOR AUTOBAUD SEQUENCE
	PJRST	DZQADD		;...
;HERE WHEN CARRIER DROPS

SCNCKF:	MOVSI	T2,DZMCON	;REMEMBER DROP
	ANDCAB	T2,DZMSTS##(P1)	;...
	TLNN	T2,DZMABW	;IF AWAITING AUTOBAUD,
	TLNN	T2,DZMCRW	;OR NOT IN CARRIER WAIT,
	TRNA			;THEN TELL SCNSER
	JRST	SCNCK8		;NO--IGNORE CARRIER DROP
	MOVEI	T3,DSTOFF##	;OTHERWISE LET SCNSER WORRY
SCNDST:	MOVE	U,P1		;SET UP U FOR SCNSER
	PUSHJ	P,DSCREC##	;TELL SCNSER WHAT HAPPENED
	JRST	SCNCK8		;AND CONTINUE SCAN

;ROUTINE TO ADD AN ENTRY TO THE DATASET TIMER QUEUE
;
;CALL:	T1/ROUTINE TO CALL,,TIME IN MS
;	PUSHJ	P,DZQADD
;
;ROUTINE WILL BE CALLED WITH P1 = LINE # AND U = LINTAB(P1) BY DZQTIC

DZQADD:	MOVEI	T2,-1		;MASK FOR ROUTINE ADDRESS
	SCNOFF			;NO RACES
	TDNN	T2,DZMSTS##(P1)	;REPLACING ENTRY IN Q?
	 AOS	DZTTQN##	;NO, NEW ENTRY
	HLRM	T1,DZMSTS##(P1)	;SET UP ROUTINE ADDRESS
	HRRZS	T1		;GET TIME IN MS
	IMUL	T1,TICSEC##	;CONVERT TO K TICS
	HRRZ	T2,STOPAT##	;GET # TICS BETWEEN CALLS - 1
	IDIVI	T1,1(T2)	;AND ADJUST FOR M.STOF
	IDIVI	T1,^D1000	;TICS
	SKIPE	T1
	SKIPE	T2
	 AOS	T1
	DPB	T1,DZQPTM	;STORE TICS TO GO
	SCNON			;Q ALL SET
	POPJ	P,
	SUBTTL	ROUTINE TO CONVERT A LINE NUMBER TO A UBA ADDRESS

;CALL:	P1/LINE NUMBER
;	PUSHJ	P,DZUADR
;	T1/BIT CORRESPONDING TO LINE NUMBER
;	T2/UNIBUS ADDRESS

DZUADR:	MOVE	T2,P1		;COPY LINE NUMBER
	ANDI	T2,7		;MAKE DZ-RELATIVE
	MOVEI	T1,1		;START WITH LINE 0
	LSH	T1,(T2)		;SHIFT TO THIS LINE NUMBER
	MOVE	T2,P1		;GET LINE NUMBER
	ANDI	T2,770		;ONLY DZ PART
	ADD	T2,[DZ11BA]	;CONVERT TO UNIBUS ADDRESS
	POPJ	P,
	SUBTTL	INTERRUPT -- RECEIVER

;HERE ON AN A VECTOR INTERRUPT ... RECEIVER
DZVCAF:	MOVEM	T1,DZMSTS##(U)	;UPDATE SOFTWARE STATUS
DZVECA::RDIO	T3,DZRBUF(P1)	;GET RECEIVED CHARACTER
	TRNN	T3,DZRDVL	;IS DATA VALID ?
	  POPJ	P,		;DISMISS INTERRUPT
	TRNE	T3,DZROVR	;OVERRUN ?
	  AOS	DZOVRC		;COUNT TIMES THAT HAPPENS
	LDB	U,[POINT 3,T3,27] ;GET RELATIVE LINE NUMBER
	ADDI	U,-<777777&DZ11BA>(P1) ;MAKE LINE NUMBER
	CAML	U,DZMAXL	;IS LINE NUMBER IN RANGE
	  JRST	DZVECA		;NO SO IGNORE IT
	MOVE	T1,DZMSTS##(U)	;GET SOFTWARE STATUS
	TLZE	T1,DZMABF	;IF FLUSHING AB JUNK, TRASH CHAR
	 JRST	DZVCAF		;IGNORE JUST ONE
	MOVE	T2,LINTAB##(U)	;GET LDB ADDRESS
	MOVE	T2,LDBDCH##(T2)	;GET CHAR BITS
	TLNN	T1,DZMABW	;ASSUME ABW CLEARED BY REPCOF
	TRNN	T2,LDRDSD##	;DATASET LINE?
	 JRST	DZVCA2		;NO, SKIP DATASET CODE
	TLNN	T1,DZMCRW	;IF WAITING FOR CARRIER, IGNORE THIS CHAR
	TLNN	T1,DZMCON	;IS CARRIER ON?
	 JRST	DZVECA		;NO, TRASH CHARACTER
DZVCA2:	TLNN	T1,DZMABW	;IN AUTOBAUD WAIT?
	 JRST	DZVCA1		;NO, PROCESS NORMALLY
	;THE FOLLOWING AUTOBAUD ALGORITHM COMES FROM DNTTY.P11, THE ANF-10 CODE

	ANDI	T3,377		;REDUCE TO DATA BITS
	TLNN	T1,DZMLSP	;LOOKING AT LOW SPEED?
	 SKIPA	T2,[POINT 18,ATOHSP] ;NO, USE HIGH SPEED TABLE
	SKIPA	T2,[POINT 18,ATOLSP] ;YES, USE LOW SPEED TABLE
	 ANDI	T3,376		;IN HIGH SPEED MODE, KEEP ONLY THESE BITS
	ILDB	T1,T2		;GET SWITCH CHARACTER
	CAMN	T1,T3		;MATCH?
	 JRST	DZVCAC		;YES, SWITCH NOW
DZVCA0:	ILDB	T1,T2		;GET CODE FOR NEXT SPEED
	JUMPE	T1,DZVCAC	;IF NO MATCH, CHANGE SPEEDS
	XOR	T1,T3		;SEE IF CHARACTER MATCHES
	TRNE	T1,377		;DOES IT?
	 JRST	DZVCA0		;NOPE, TRY NEXT
	MOVSI	T2,DZMABF	;BIT TO FLUSH NEXT CHARACTER
	TRZE	T1,400K		;SHOULD WE?
	 IORM	T2,DZMSTS##(U)	;YES
	LSH	T1,-^D9		;GET SPEED CODE (9 BITS = READABLE TBL CREF)
	MOVE	T2,SPDXTB(T1)	;TURN INTO DZ BITS
	DPB	T1,[POINT 4,T1,35-4] ;COPY SPEED CODE
	MOVE	T3,LINTAB##(U)	;FIND LDB
	EXCH	U,T3		;SET UP U
	DPB	T1,LDPSPD##	;STORE SPEED FOR PROGRAM
	MOVE	U,T3		;RESTORE U
	ANDI	T3,7		;MAKE DZ LINE
	IORI	T2,(T3)		;SET FOR LPR
	WRIO	T2,DZLPR(P1)	;SET SPEED, STOP BITS, RCV ENABLE, 8 BIT CHARS
	EXCH	P1,U		;SET UP P1
	MOVE	T1,[DZCXUP,,^D<1>] ;TELL SCNSER LINE IS UP -- SOON
	PUSHJ	P,DZQADD	;QUEUE THE TRANSACTION
	EXCH	P1,U		;RESTORE P1
	JRST	DZVECA		;PROCESS NEXT CHAR IN SILO

	;HERE TO SWITCH TO THE OTHER AB SPEED
DZVCAC:	MOVSI	T1,DZMLSP	;GET THE LOW SPEED LOOK BIT
	XORB	T1,DZMSTS##(U)	;LOOK AT THE OTHER SPEED
	TLNE	T1,DZMLSP	;WHAT SPEED ARE WE LOOKING AT NOW?
	 SKIPA	T2,SPD300	;LOW, USE 300
	SKIPA	T2,SPD240	;HIGH, USE 2400
	 TLO	T1,DZMABF	;LOW MUST FLUSH NEXT CHAR
	MOVE	T3,U		;GET LINE NUMBER
	ANDI	T3,7		;MAKE DZ LINE
	IORI	T2,(T3)		;SET FOR LPR
	WRIO	T2,DZLPR(P1)	;SET SPEED, STOP BITS, RCV ENABLE, 8 BIT CHARS
	JRST	DZVCAF		;STORE STATUS AND CHECK NEXT SILO CHAR
	;AUTOBAUD DETECT TABLES

	DEFINE	CH(CHR,SPD,FLG<0>),< <<SPD_9>+CHR+FLG> >
	;400K MEANS IGNORE NEXT CHAR.  SPD IS INDEX INTO SPDXTB

	;NOTE THAT LOW BIT MASKED OFF BEFORE COMPARE
ATOHSP:	XWD	000		,CH(200,7,400K)	;LOW-SPD SWITCH, 300 CR/^C O/E
	XWD	CH(036,11,400K)	,CH(346,11,400K);1200 ^C O/E, 1200 CR O/E
	XWD	CH(006,12)	,CH(072,12)	;1800 ^C O/E, 1800 CR O/E
	XWD	CH(002,13)	,CH(202,13)	;2400 ^C EVN, 2400 ^C ODD
	XWD	CH(214,13)	,CH(014,13)	;2400 CR EVN, 2400 CR ODD
	XWD	CH(370,14)	,CH(360,14)	;4800 ^C ODD, 4800 ^C EVN
	XWD	CH(374,14)	,CH(376,15)	;4800 ^C EVN, 9600 ^C OR CR O/E
	EXP	0				;TERMINATOR

ATOLSP:	XWD	377		,CH(174,3)	;HS-SWITCH, 110 ^C O/E
	XWD	CH(214,3,400K)	,CH(234,3,400K)	;110 CR    , 110 CR    
	XWD	CH(346,5,400K)	,CH(036,5)	;150 CR    , 150 CR
	XWD	CH(215,7)	,CH(015,7)	;300 CR EVN, 300 CR ODD
	XWD	CH(003,7)	,CH(203,7)	;300 ^C EVN, 300 ^C ODD
	XWD	CH(376,11)	,0		;1200 ^C EVN, TERMINATOR



	;NORMAL RECEIVED CHARACTER PROCESSING

DZVCA1:	TRNE	T3,DZRFRM	;CHECK FOR FRAME ERROR
	  JRST	RCVFER		;HANDLE FRAMING ERROR
	TLZE	T1,DZMLIB	;CLEAR LAST-INPUT-BREAK FLAG
	MOVEM	T1,DZMSTS##(U)	;UPDATE STATUS BITS
	ANDI	T3,CK.CHR	;KEEP ONLY CHARACTER
	PUSHJ	P,RECINT##	;CALL SCNSER
	JRST	DZVECA		;CHECK FOR MORE DATA IN SILO

	;HERE WHEN RECEIVED CHAR HAS A FRAMING ERROR

RCVFER:	TLON	T1,DZMLIB	;SET LAST-INPUT-BREAK FLAG
	JRST	DZVCAF		;UPDATE AND PITCH ON FIRST BREAK IN SEQUENCE
	TLZ	T1,DZMLIB!DZMLSP!DZMABF ;CLEAR SOME JUNK BITS
		.CREF	DZMABL
	JUMPGE	T1,DZVCAF	;SKIP THIS IF NOT AN AUTOBAUD LINE
	TLO	T1,DZMABW	;AND SET ANOTHER
	MOVEM	T1,DZMSTS##(U)	;UPDATE IN STATUS TABLE
	EXCH	P1,U		;SETUP LINE FOR DZQADD
	MOVE	T1,[CRWTMO,,^D30K] ;GIVE AUTOBAUD 30 SECONDS TO COMPLETE
	PUSHJ	P,DZQADD	;START THE TIMER
	EXCH	P1,U		;RESTORE VALUES
	MOVE	T1,U		;COPY LINE NUMBER
	ANDI	T1,7		;DZ-RELATIVE
	IOR	T1,SPD240	;HIGH-SPEED AUTOBAUD SETTINGS
	WRIO	T1,DZLPR(P1)	;SET IT UP
	JRST	DZVECA		;CHECK FOR MORE DATA IN SILO
	SUBTTL	INTERRUPT -- TRANSMITTER

;HERE ON AN B VECTOR INTERRUPT ... TRANSMITTER
; HERE WITH DZ11 HDW ADR IN P1
DZVECB::RDIO	T1,DZCSR(P1)	;GET STATUS
	TRNN	T1,DZTRDY	;IS TRANSMITTER READY ?
	  POPJ	P,		;DONE
	LDB	U,[POINT 3,T1,27] ;GET RELATIVE LINE NUMBER
	ADDI	U,-<777777&DZ11BA>(P1) ;MAKE LINE NUMBER
	SKIPL	T3,DZCHTB##(U)	;GET CHAR WE SAVED TO TYPE
	  JRST	DZVCB4		;DONE WITH LINE FOR NOW
	SETZM	DZCHTB##(U)	;CLEAN OUT TABLE
	WRIOB	T3,DZTBUF(P1)	;GIVE DATA TO DZ11
	PUSHJ	P,XMTINT##	;LET SCNSER KNOW WE NEED MORE DATA
	JRST	DZVECB		;LOOK FOR MORE LINES TO SERVICE

;HERE IF LINE DONE
DZVCB4:	LDB	T1,[POINT 3,U,35] ;GET RELATIVE LINE NUMBER
	MOVEI	T2,1		;MASK
	LSH	T2,(T1)	;POSITION MASK
	BCIOB	T2,DZTCR(P1)	;CLEAR WANT TO TRANSMIT FLAG
	JRST	DZVECB		;LOOK FOR MORE LINES TO SERVICE
	SUBTTL	SETUP HARDWARE PARAMETERS

;SUBROUTINE TO SETUP EVERYTHING (I.E. SPEED) ACCORDING TO THE LDB
; CALL WITH:
;	MOVEI	U,<LDB ADR>
;	PUSHJ	P,DZCHP
;	RETURN
DZCHP:	ANDCAM	T1,LDBBYT##(U)	;CLEAR CHP BIT
	LDB	T1,LDPLNO##	;GET LINE NUMBER
	CAML	T1,DZMAXL	;IS THIS POSSIBLE
	  POPJ	P,
	MOVE	T2,DZMSTS##(T1)	;GET STATUS BITS
	TLNE	T2,DZMABW	;IF IN AUTOBAUD WAIT,
	POPJ	P,		;CAN'T DO IT
	LDB	T2,LDPSPD##	;GET LINE SPEED
	MOVE	T3,T1		;COPY LINE NUMBER
	ANDI	T3,770		;STRIP RELATIVE LINE NUMBER
	ADD	T3,[DZ11BA]	;MAKES ADR OF DZ11
	ANDI	T1,7		;LEAVE ONLY RELATIVE LINE NUMBER
	ANDI	T2,17		;ONLY LOOK AT HALF OF SPEED
	IOR	T1,SPDXTB(T2)	;GET DZ11 SPEED INDEX
	JUMPL	T1,CPOPJ##	;CAN'T DO IT
	WRIO	T1,DZLPR(T3)	;SET SPEED ETC
	POPJ	P,

;TABLE TO TRANSLATE DH11 INDEXES TO DZ11 INDEXES

SPDXTB:	EXP	DZ8BIT				; 0 BAUD
	EXP	DZ1RXO!<0*400>!DZ8BIT		; 50 BAUD
	EXP	DZ1RXO!<1*400>!DZ8BIT		; 75 BAUD
	EXP	DZ1RXO!<2*400>!DZ2STP!DZ8BIT	; 110 BAUD
	EXP	-1				; 134.5 BAUD
	EXP	DZ1RXO!<4*400>!DZ8BIT		; 150 BAUD
	EXP	-1				; 200 BAUD
SPD300:	EXP	DZ1RXO!<5*400>!DZ8BIT		; 300 BAUD
	EXP	DZ1RXO!<6*400>!DZ8BIT		; 600 BAUD
	EXP	DZ1RXO!<7*400>!DZ8BIT		; 1200 BAUD
	EXP	DZ1RXO!<10*400>!DZ8BIT		; 1800 BAUD
SPD240:	EXP	DZ1RXO!<12*400>!DZ8BIT		; 2400 BAUD
	EXP	DZ1RXO!<14*400>!DZ8BIT		; 4800 BAUD
	EXP	DZ1RXO!<16*400>!DZ8BIT		; 9600 BAUD
	EXP	-1				; EXTERNAL INPUT A BAUD
	EXP	-1				; EXTERNAL INPUT B BAUD
	SUBTTL	LINE PARAMETER CONTROL

;CALLED FROM LDBISR DISPATCH WITH LPC TRANSACTION IN T3
; AND LDB ADDRESS IN U.

DZLPC:	MOVE	T1,T3		;COPY TRANSACTION CODE
	LSH	T1,-8		;ISOLATE SUB-FUNCTION
	CAIE	T1,LPCABR	;IS IT AUTOBAUD REQUEST?
	POPJ	P,		;NO--WE HANDLE NO OTHERS
	LDB	T1,LDPLNO##	;YES--GET LINE NUMBER
	CAML	T1,DZMAXL	;IS IT IN RANGE?
	POPJ	P,		;NO--IGNORE IT
	PUSHJ	P,SAVE1##	;YES--PRESERVE A REGISTER
	MOVE	P1,T1		;SAVE LINE NUMBER
	PUSHJ	P,DZUADR	;GET DZ BASE ADDRESS IN T2
	MOVE	T1,P1		;COPY LINE NUMBER
	ANDI	T1,7		;MAKE DZ-RELATIVE
	MOVSI	T3,DZMABL	;AUTOBAUD LINE BIT
	IORB	T3,DZMSTS##(P1)	;SET AND FETCH STATUS
	MOVE	T4,LDBDCH##(U)	;GET SOME BITS
	TRNN	T4,LDRDSD##	;IS THIS A DATASET?
	JRST	DZLPC1		;NO--SKIP DATASET CODE
	TLNN	T3,DZMCRW	;IF IN CARRIER WAIT,
	TLNN	T3,DZMCON	;OR NO CARRIER,
	POPJ	P,		;PUNT THIS
DZLPC1:	TLOE	T3,DZMABW	;IF ALREADY WAITING,
	POPJ	P,		;IGNORE THIS REQUEST
	SCNOFF			;FIGHT RACES
	MOVSI	T3,DZMABW	;AUTOBAUD WAIT
	IORM	T3,DZMSTS##(P1)	;START IT
	IOR	T1,SPD240	;HIGH-SPEED AUTOBAUD
	WRIO	T1,DZLPR(T2)	;SET ITS VALUES
	MOVSI	T3,DZMABF!DZMLSP ;BITS TO CLEAR
	ANDCAM	T3,DZMSTS##(P1)	;DO IT
	SCNON			;DONE WITH THIS RACE PROBLEM
	MOVE	T1,[CRWTMO,,^D30K] ;GIVE AUTOBAUD 30 SECONDS TO COMPLETE
	PJRST	DZQADD		;START THE TIMER & RETURN

ABRTMO:!
ABRFIN:	MOVSI	T1,DZMABW!DZMLIB!DZMLSP ;BITS TO CLEAR
	ANDCAM	T1,DZMSTS##(P1)	;DO IT
IFN FTNET,<
	SKIPGE	LDBREM##(U)	;IF A VTM,
	PUSHJ	P,VTMSPD##	;TELL NETVTM ABOUT THE SPEED CHANGE
>
	PJRST	SETCHP##	;MAKE SURE THE SPEED GETS SET
	SUBTTL	CONTROL OVER DATASET

;HERE TO EXERCISE CONTROL OVER A DATASET.
; CALLED WITH TRANSACTION CODE IN T3, DSCTAB INDEX IN U.
; ENTERED FROM SCNSER ONLY.

DSCTYP:	CAML	U,DZMAXL	;IS LINE NUMBER IN RANGE
	POPJ	P,		;NO JUST SAY ITS OFF
	LDB	T2,[POINT 3,U,35] ;GET LINE NUMBER MODULO 8
	MOVEI	T1,1		;BIT FOR CARRIER ETC
	LSH	T1,(T2)		;PRESTO MASK
	MOVE	T2,U		;COPY LINE NUMBER
	ANDI	T2,770		;MAKES DZ11 # * 10
	ADD	T2,[DZ11BA]	;MAKES ADR OF DZ11 FOR LINE
	CAIN	T3,DSTON##	;IS CODE FOR ON?
	JRST	DSDON		;YES. DRIVEN ON FLAG
	CAIN	T3,DSTOFF##	;NO. FOR OFF?
	JRST	DSDOFF		;YES. DISPATCH.
	CAIE	T3,DSTREQ##	;REQUEST SATATUS?
	POPJ	P,0		;NO. ERRONEOUS CODE. DISMISS.

;HERE TO REQUEST STATUS OF A LINE, ONLY DURING TTYINI. THUS
; IT IS OK TO GO INTO A WAIT-LOOP TO ACCOMPLISH THIS, AND TO IGNORE 
; ANY OTHER ACTIVITY.
	TIOEB	T1,DZCAR(T2)	;IS CARRIER ON ?
	SKIPA	T1,[EXP DSTON##] ;YES
	MOVEI	T1,DSTOFF##	;NOT ON
	POPJ	P,

;HERE TO DRIVE A DATASET ON.
DSDON:	BSIOB	T1,DZDTR(T2)	;TURN IT ON
	POPJ	P,

;HERE TO DRIVE A DATASET OFF.
DSDOFF:	BCIOB	T1,DZDTR(T2)	;CLEAR DATA TERMINAL READY
	MOVSI	T1,DZMCON!DZMCRW!DZMABW!DZMABF
	ANDCAM	T1,DZMSTS##(U)	;CLEAR OUR STATUS BITS
	POPJ	P,
	SUBTTL	TYPE A CHARACTER

;ROUTINE TO OUTPUT A CHARACTER TO A LINE
;CALLED FROM TYPE IN SCNSER
;WITH 8-BITS OF CHARACTER IN T3

SCNTYP:	LDB	T1,LDPLNO##	;PICK UP LINE NUMBER
	CAML	T1,DZMAXL	;IS LINE NUMBER IN RANGE ?
	  POPJ	P,		;NO SO DISMISS
	WRPI	PI.OFF		;DISABLE INTERRUPTS
	HRROM	T3,DZCHTB##(T1)	;SAVE CHAR TO TYPE LATER
	MOVEI	T3,1		;MASK FOR LINE
	MOVE	T2,T1		;COPY LINE NUMBER
	ANDI	T1,770		;LEAVE ONLY DZ11 UNIT * 10
	ADD	T1,[DZ11BA]	;MAKE ADR OF DZ11
	ANDI	T2,7		;LEAVE ONLY RELATIVE LINE NUMBER
	LSH	T3,(T2)		;POSITION MASK
	BSIOB	T3,DZTCR(T1)	;LET DZ11 KNOW WE WANT TO TYPE
	WRPI	PI.ON		;REENABLE INTERRUPTS
	POPJ	P,0		;AND RETURN
	$LOW
DZLIEN:	0			;COUNT OF LOST INTERRUPT ENABLES
DZOVRC:	Z			;COUNT OF TIMES RECEIVER GETS OVERRUN
DZMAXL:	0			;NUMBER OF DZ11 LINES
				; I.E. HIGHEST DZ11 LINE #+1

	$LIT

DZEND:	END