;************************************************************************
;
; SEND25.M68
; send message to TeleVideo 925 status line
; David F. Pallmann;  07-Jun-84
;
;************************************************************************
;
; .SEND25 <job> <message>  sends <message> to <job>
; .SEND25 ALL <message>    sends to all jobs using the following drivers:
;				TVI925   TEL925   TEL950   T925   T950
;
; Complimentary command CLR25 clears the status line
;
;************************************************************************

;UNIVERSALS

	SEARCH	SYS
	SEARCH	SYSSYM
	SEARCH	TRM

;IMPURE AREA

	.OFINI
	.OFDEF	JOB,4			;JOB NAME RAD50
	.OFDEF	TRM,D.DDB		;DDB FOR TERMINAL OUTPUT
	.OFSIZ	MEMSIZ

;ASCII CHARACTERS

	BEL=7
	LF=12
	ESC=33

;MACROS

DEFINE	SEND	CHAR
	MOVB	CHAR,D1
	FILOTB	TRM(A5)
	ENDM

DEFINE	DEPACK	ADDR
	IF	NB,ADDR,LEA A1,ADDR
	SUB	#4,SP
	MOV	SP,A2
	UNPACK
	CLRB	@A2
	TTYL	@SP
	ADD	#4,SP
	ENDM

;INITIALIZATION

START:	PHDR	-1,0,PH$REE!PH$REU	;PROGRAM HEADER
	GETIMP	MEMSIZ,A5		;ALLOCATE IMPURE AREA

;GET JOB NAME OR GIVE HELP

GETJOB:	BYP
	ALF
	BEQ	10$
	TTYL	HELP
	JMP	EXIT
10$:	LEA	A1,JOB(A5)
	PACK
	PACK
	CMM	JOB(A5),#[ALL]_16.
	BEQ	ALL

;LOOK-UP JOB NAME

LOOKUP:	MOV	JOBTBL,A0
10$:	MOV	(A0)+,D0
	BEQ	10$
	BMI	20$
	MOV	D0,A1
	CMM	JOBNAM(A1),JOB(A5)
	BNE	10$
	CALL	XMIT
	BR	30$
20$:	TTYL	BADJOB
30$:	JMP	EXIT

;SEND TO ALL JOBS WITH TELEVIDEO 925/950 TERMINALS

ALL:	MOV	JOBTBL,A4		;A4 indexes job table
10$:	MOV	(A4)+,D0		;get next job
	BEQ	10$			;branch if de-allocated
	BMI	30$			;branch if end of job table
	MOV	D0,A1			;A1 points to current job
	MOV	JOBTRM(A1),D0		;get terminal
	BEQ	10$			;branch if detached
	MOV	D0,A3			;A3 contains terminal index
	MOV	T.TDV(A3),A3		;A3 points to terminal driver
	SUB	#4,A3			;A3 point to terminal driver name
	LEA	A0,TDVTBL		;A0 indexed TDV table
20$:	TST	@A0			;end of table?
	BEQ	10$			; yes - bypass this job
	CMM	(A0)+,@A3		;TDV match?
	BNE	20$			; no - continue scanning table
	SAVE	A1,A2
	DEPACK	JOBNAM(A1)		;print job name
	DEPACK
	REST	A1,A2
	CRLF				;newline
	CALL	XMIT			;send message
	BR	10$			;continue
30$:

;EXIT

EXIT:	CRLF
	EXIT

;XMIT
;SEND MESSAGE TO TERMINAL

XMIT:

;OPEN TERMINAL AS AN OUTPUT DEVICE

OPEN:	MOVW	#[TRM],TRM+D.DEV(A5)
	CLRW	TRM+D.DRV(A5)
	CLRW	TRM+D.EXT(A5)
	CLRW	TRM+D.PPN(A5)
	MOV	JOBTRM(A1),A1
	MOV	-4(A1),TRM+D.FIL(A5)
	INIT	TRM(A5)
	OPENO	TRM(A5)

;SEND CONTROL CHARACTERS TO REMOTE TERMINAL

BELLS:	SEND	#BEL			;send <BEL>
	CLOSE	TRM(A5)			;send it
	SLEEP	#8000.			;sleep 0.8 seconds
	OPENO	TRM(A5)			;re-open
	SEND	#BEL			;send another <BEL>

CONTRL:	SEND	#ESC			;enable
	SEND	#'g			; status line
	SEND	#ESC			;program
	SEND	#'f			; status line

SEND:	BYP
	MOV	A2,A3
10$:	MOVB	(A3)+,D1
	CMPB	D1,#LF
	BEQ	20$
	FILOTB	TRM(A5)
	BR	10$
20$:

;CLOSE OUTPUT TERMINAL

CLOSE:	CLOSE	TRM(A5)
	RTN

;TEXT CONSTANTS

HELP:	ASCIZ	/? usage: .SEND25 <job> <message>/
BADJOB:	ASCIZ	/? invalid job name/

;TELEVIDEO TERMINAL DRIVER TABLE

TDVTBL:	RAD50	/TVI925/
	RAD50	/TVI950/
	RAD50	/TEL925/
	RAD50	/TEL950/
	RAD50	/T925  /
	RAD50	/T950  /
	0

	END