;
;       NAME:  BRDCST
;
;       FUNCTION:  This program is used to "broadcast" a message to every
;       terminal on the system.  The restraints is uses in terminal
;       selection are:  1) the terminal must be attached to a job, and
;       2) it must not be a PSEUDO terminal.  The actual sending is done
;       by opening the terminal as a file using the TRM: driver.
;
;       AUTHOR:  Tom Dahlquist
;
;       HISTORY:
;         DATE   WHO SUBSTANCE
;       09/19/83 TAD Written.
;       07/16/84 TAD Was moving a blank into low memory, causing random
;                       failures.
;       06/85   John Baima
;               Eisenbrauns
;               PO Box 275
;               Winona Lake, IN 46590
;               Don't send messages to jobs running LPTSPL--they are printers.
;
;[1.1]  05/05/86 - Added check for AlphaBase Flip terminals.  D. Eichbauer

       SEARCH  SYS
       SEARCH  SYSSYM

       VMAJOR=1
       VMINOR=1

BRDCST: PHDR    -2,PV$RSM,PH$REU

       LIN                             ; anything to send?
       JEQ     EXIT                    ; leave if not...

       LEA     A4,DDB                  ; let A4 -> to DDB throughout...
       CLEAR   @A4,CLRLEN              ; clear it,
       MOVW    #[TRM],D.DEV(A4)        ; move in device name,
       INIT    @A4                     ; and initialize.

       JOBIDX  A0                      ; A0 -> out JCB...
       LEA     A1,JOBNAM(A0)           ; A1 -> job name field...
       PUSH    A2                      ; save A2...
       LEA     A2,JOB                  ; A2 -> job name work area...
       UNPACK                          ; unpack name into work area...
       UNPACK
       MOVB    #' ,@A2
       POP     A2

       MOV     JOBTBL,A0               ; -> first JCB pointer...
LOOP:   MOV     (A0)+,D7                ; -> JCB...
       BEQ     LOOP                    ; if not allocated...
       CMP     D7,#-1                  ; test for end of table...
       JEQ     EXIT                    ; leave if so...
       MOV     D7,A1
       CMM     JOBPRG(A1),#[LPT]_16.+[SPL]     ; JKB-Running Spooler
       BEQ     LOOP                    ; br if this is a printer
       MOV     JOBTRM(A1),D7           ; D7 -> TCB...
       BEQ     LOOP                    ; br if no terminal...
       MOV     D7,A5                   ; A5 -> TCB...
       MOV     2(A5),A3                ; A3 -> interface driver...
       SUB     #4,A3                   ; A3 -> I.D. name...
       CMM     @A3,#[PSE]_16.+[UDO]    ; PSEUDO?               [1.1]
       BEQ     LOOP                    ; br if so...
       CMM     @A3,#[FLP]_16.+[IDV]    ; Is it a FLIP terminal   [1.1]
       BEQ     LOOP                    ; If so, ignore it also.  [1.1]
       MOV     -4(A5),D.FIL(A4)        ; move in terminal name...
       OPENO   @A4                     ; open for output

       MOVB    #';,D1                  ; make it look like SEND...
       FILOTB  @A4

       LEA     A1,JOB                  ; A1 -> job name work area...
NLOOP:  MOVB    (A1)+,D1
       FILOTB  @A4
       CMPB    D1,#'
       BNE     NLOOP
       MOVB    #'-,D1
       FILOTB  @A4
       MOVB    #' ,D1
       FILOTB  @A4

       PUSH    A2                      ; save -> text line...
OLOOP:  MOVB    (A2)+,D1                ; get next byte of text and
       FILOTB  @A4                     ; output...
       LIN                             ; end of input line?
       BNE     OLOOP                   ; br if not, else
       POP     A2                      ; restore A2 and
       MOVB    #7,D1
       FILOTB  @A4                     ; give him a BELL and
       MOVB    #15,D1                  ; a CR and a LF.
       FILOTB  @A4
       MOVB    #12,D1
       FILOTB  @A4
       CLOSE   @A4                     ; close output file.
       JMP     LOOP                    ; and back.

EXIT:   EXIT

;
;       Workarea and Constants
;
DDB:    BLKB    D.DDB
JOB:    BLKB    8.
CLRLEN  =.-DDB
       END