SUBTTL Pack a unique device descriptor
; Routine - PCKPDD
;
; Function - To pack the PORT, LINE, DEVICE-TYPE and UNIT numbers into a single
; word to use as a unique descriptor of that device. This is useful so
; that when searching tables we will only have to do single word compares.
;
; Parameters -
;
; S1/ dev-type#,,unit#
; S2/ port#,,line#
;
; Returns -
;
; S1/ port,line,dev,unit each in 9 bits
PCKPDD: $SAVE <T1,T2> ; Save a couple registers
HLL T1,S2 ; Get port number into LH
HLR T1,S1 ; Get device type number into RH
LSH T1,^d9 ; Shift them up to where they need be
TLZ T1,777 ; Clear out where line # will be
HRL T2,S2 ; Get line number into LH
HRR T2,S1 ; Get unit number into RH
AND T2,[777,,777] ; Clear out where port and device go
IOR T1,T2 ; Put them all together
MOVE S1,T1 ; and it's magic. (all packed into A)
$RETT ; Only a true return

SUBTTL Release front end for any device
; Routine - RLSFE
;
; Function - To release the remote device association with the front end.
; What this actually does is close the TOPS20 front end JFN
; if it is determined that there are no more devices in this
; process that are using the FE JFN.
RLSFE:
TOPS20 <SKIPN FEJFN ; check if any jfn to release
$RET ; no - nothing to do
; jfn implies RSX20F protocol
$SAVE <TF,S1> ; Save last error flag and return code
$CALL LFIRST ; Position to first entry
JUMPT .POPJ ; If entry found then return
SKIPN S1,FEJFN ; Last entry in list is destroyed
$RET ; return if no jfn
IORX S1,CZ%ABT ; Don't try to clean up any FE buffers
CLOSF ; Close the front end
JFCL ; Ignore errors
SETZM FEJFN ; Clear the front end JFN
SETZM LSTDTE ; and the last port with it.
>; End if TOPS20
$RET ; Return saying that it is done.

SUBTTL Select a DTE on the open FEn device
TOPS20 <
; Routine - SELDTE
;
; Function - To select which DTE is currently attached to the FEn: device
; that was previously opened. This routine assumes that the caller
; has already enq'd the port.
;
; Parameters -
;
; S1/ DTE # to be selected
;
; Returns -
;
; True was successful
; False MTOPR Jsys failed and the error code is in S1
;
; Note - It has been verified by looking at the monitor listings that this
; routine does not need the port ENQ'd before selecting the DTE.
SELDTE: MOVX S2,.MODTE ; Select the appropriate DTE
HRROI T1,-10(S1) ; Get the port number
CAMN T1,LSTDTE ; Was it the same as the last one used?
$RETT ; Yes so assume he is still set up.
HRRZ T1,T1 ; Make it only the DTE number
MOVE S1,FEJFN ; Use the FE JFN already opened
MTOPR ; Do the select
ERJMP DSLERR ; Didn't work, bad DTE
HRROM T1,LSTDTE ; Save the last DTE to be selected
$RETT ; It is now selected on the DTE
DSLERR: SETZM LSTDTE ; Clear the last DTE selected (none)
MOVX S1,.FHSLF ; Get the last error that occurred
GETER ; in this process
HRRZ S1,S2 ; Set the error value
$RETF ; and return flaging failure.
>; End if TOPS20