	.enabl	lc		; to allow lower case macro listing
;
; FORTRAN call: CALL SENDL (MESAGE,NCHAR)
;
; MESAGE is a logical*1 array containing the NCHAR 
; ascii characters required to be sent to the LaserWriter.
;
; This macro routine is intended as an alternative to the Fortran routine
; of the same name. To distinguish between them, the Fortran routine is
; renamed SENDLF when not in use, and this routine is renamed SENDLM when
; not required to be linked with a program.
;
	.title	sendl
	.globl	sendl		; won't link without this!
	.mcall	.ttyout,.print,.gval
	rcsr =	176510		; serial ch.1  - receive from LaserWriter
;	rbuf =	rcsr+2
;	xcsr =	rcsr+4		; transmit to LaserWriter
;	xbuf =	rcsr+6
	sysgen= 372		; index into RMON for sysgen features
				;
sendl:	tst	(r5)+		; skip the argument count
	mov	(r5)+,	r1	; address of the array MESAGE
	mov	@(r5)+,	r2	; tell counter how many send-characters
	mov	#rcsr,	r5	; into a register to alter the value
	.gval	#mtab,	#sysgen	; get sysgen options word into r0
	tst	r0		; is TSX running ? (Ref. Man. p.160)
	bpl	testr		; branch if running under RT11
	bic	#20000,	r5	; I/O page is 140000-157777 (PAR 6)
				;  to allow Fortran virtual arrays
				;  to use 160000-177777 (calling program
				;  must call IOVIR if under TSX+ to
				;  change the I/O page mapping)
testr:	bit	#200,	(r5)	; is bit 7 set (char. received) ?
	beq	send		; if not, proceed to send a character
read:	mov	2(r5),	r4	; otherwise, read it,
	bic	#177600,r4	; clearing all but the 7 lowest bits
	cmp	#23,	r4	; is the character XOFF ?
	beq	next		; if so, wait until another char. rec'd.
	cmp	#37,	r4	; is it printable ?
	bpl	wait		; if not, ignore it, but wait for another
	.ttyout	r4		; otherwise, display it,
wait:	mov	#100000,r3	; and set the stopwatch.
time:	bit	#200,	(r5)	; has another char. been received ?
	bne	read		; if so, read it
	sob	r3,	time	; otherwise, wait until time's up,
	br	send		; then send another character
next:	bit	#200,	(r5)	; is bit 7 set (next char. received) ?
	beq	next		; wait until it is..
	br	read		; ..then read the character.	
send:	bit	#200,	4(r5)	; is bit 7 set (ready for next char.) ?
	beq	send		; wait until it is before..
;	.ttyout (r1)		; diagnostic display
	movb	(r1)+,	6(r5)	; put a send-character into the buffer
	dec	r2		; ..checking to see if any remain and..
	bne	testr		; ..starting on the next one if any
	rts	pc		; then return to calling program
				;
mtab:	.blkw	2		; EMT argument block for .gval
rt11:	.asciz	/RT-11/
tsxpls:	.asciz	/TSX-Plus/
	.end
