	.mcall	.MODULE
	.MODULE	FLUSH,comment=<Flush terminal>,release=V09,version=07

;**************************************************************;
;                                                              ;
;   Copyright (c) 1988            Bob Schor                    ;
;                                 Eye and Ear Hospital         ;
;                                 230 Lothrop St.              ;
;                                 Pittsburgh, PA   15213       ;
;                                                              ;
; All rights reserved.  May not be copied without this notice. ;
;                                                              ;
;**************************************************************;

;**************************************************************;
;                                                              ;
;   Copyright (c) 1989            Bob Schor                    ;
;                                 Eye and Ear Institute        ;
;                                 203 Lothrop St.              ;
;                                 Pittsburgh, PA   15213       ;
;                                                              ;
; All rights reserved.  May not be copied without this notice. ;
;                                                              ;
;**************************************************************;

;Flushes terminal buffer, prevents type-aheads.
;Works with both RT-11 and TSX.

;b schor	october, 1988	

;modifications --
;	jul, 1989	Psects $CODE and $DATA added


;define our .psects before calling SUMAC to force ours low

	.psect	$code	ro,i,lcl,rel,con
	.psect	$data	rw,d,lcl,rel,con

;uses SUMAC for structured macro code

	.library	/lib:sumac/	;use external macro definition file

	.mcall	SUMAC
	SUMAC				;initialization macro

	.dsabl	gbl			;if undefined symbol, force error


HEAD	sysmac, <system macros>
	.mcall	.GVAL			;get value from monitor
	.mcall	.TTINR			;to empty buffer
	.mcall	.EXIT			;to return to monitor

HEAD	offset, <monitor offsets>
	sysgen	=	372		;offset to sysgen features

HEAD	syscom, <system communications>
	jsw	=	44		;job status word
	errbyt	=	52		;EMT error byte
	sysptr	=	54		;start of RMON

	tcbit$	=	100		;terminal inhibit bit

HEAD	tsx, <TSX emt codes>
	do.tsx	=	emt + 375	;general TSX "do" emt

	ttctl.	=	152		;terminal control

	.sbttl	-----------------
	.page
	.sbttl	Macro definitions
	.sbttl	-----------------

HEAD	TTCTL, <terminal control macro>
;	TTCTL	area, code, optarg
;where
;	area	address of 3-word EMT argument block
;	code	function code, 'A .. 'Z
;	optarg	optional argument

	.macro	TTCTL	area, code, optarg

	mov	area, r0		;point to argument area
	clrb	(r0)			;clear channel number
	movb	#ttctl., 1(r0)		;save emt number
	mov	code, 2(r0)		;save code
.if nb	<optarg>
	mov	optarg, 4(r0)		;save optional argument
.endc
	do.tsx				;call on TSX

	.endm	TTCTL

	.sbttl	-----
	.page
	.sbttl	flush
	.sbttl	-----

	.psect	$code

LABEL	flush, <Flush terminal buffer>
	.GVAL	#emtarg, #sysgen	;return sysgen options
	tst	r0			;high bit set if TSX
	IF	mi			;if running TSX,
		TTCTL	#emtarg, #'U	;enable non-wait tt mode
	ENDIF
	bisb	#tcbit$, @#jsw		;set no-wait bit in job status word
	REPEAT
		.TTINR			;discard characters
	UNTIL	cs			;until buffer empty
	.EXIT

	.sbttl	------------------
	.page
	.sbttl	Internal variables
	.sbttl	------------------

	.psect	$data

LABEL	emtarg, <emt argument storage>
	.blkw	10

LABEL	modnam, <module name>
	.NLCSI				;generates .asciz module string
	.even

	ENDEND

	.end	flush
