	.TITLE type - SCLI String output routine
	.IDENT /16/

.REM |
*+	type - SCLI String output routine

	File:type.mac
	Version: 16
	Author:
	Last Edit: 15-MAY-1985 14:05:04 
	Last Update: 15-May-1985 14:07:39 
		     pass pointer to bufadr, rather than bufadr


*-
|

	.nlist meb
	.LIBRARY /LB:[1,1]GLMAC.MLB/
	.MCALL CALL, RETURN, PUSH, POP
	.mcall	astx$s,qio$,mrkt$,wtse$,astx$s,cmkt$
	.mcall	dir$, alun$, qiow$

	.SBTTL LOCAL DATA

	.psect ldat,d,lcl,con
;
; use this psect for scratch storage - it is not guaranteed to be saved
; across calls to the module
;

	.psect data,d,gbl,con
;
; use this psect for module-specific data which must be retained across
; calls to the module
;
	.even
iosb:	.blkw	2	; io status block for qio
lun:	.word   0	; holds lun in use

;@MARK@
	.psect dpbs, d
;
; this psect contains the static dpbs
;
qio:	qio$ io.wvb,1,1,,iosb,qast,<,,40>
kill:	qiow$ io.kil,1,2
mrkt:	mrkt$ 1,5,2,mtast		; 5 second wait
canmt:	cmkt$ 1				; cancel efn 1 mrkt
wtse:	wtse$ 1				; wait for efn 1
alun:	alun$ 1				; assign lun

	.PSECT
; code goes in the blank psect

	.SBTTL TYPE

.REM |
	TYPE outputs a message to one of two terminals: the CLI command
	input terminal, or the task ti:. The latter is assumed pointed
	to by LUN 5. For the former, the terminal is in the GCCI buffer
	pointed to by r0, and LUN 1 is assigned to that terminal.

	TYPE uses QIO (no-wait), with MRKT, in order to provide positive
	timeout action. In the event the qio times-out (user hit no-scroll
	for example, or hung up), the QIO is killed. No other error
	reporting is done, to prevent an infinite error loop!

	NOTE WELL: TYPE accepts the address of a pointer to the output
	buffer. The buf parameter is NOT the address of the buffer,
	but the address of a cell containing the address of the buffer.
	Got that?

	CALL
		CALL TYPE,r5,buf,flag

	INPUT
		r0 -> GCCI return buffer (if cli command term is output)
	on r5 parameter list -
		buf = address of pointer to ASCIZ buffer to output
		flag = 0 --> use cli command term
		     = 1 --> output to TI:

	OUTPUT
		message sent, errors ignored (!)
		if flag = 0, LUN 1 set to comand input terminal

	REGS
		preserved

|

TYPE::
	push	<r1,r2>
	mov	@(r5)+, r1	; point to output buffer
	mov	#5, lun		; assume lun 5 (task ti:)
	tst	(r5)+		; check output device
	; note: r5 stack clean now
	bne	100$		; lun 5 - br
	mov	#1, lun		; set task ti: output
	; pull lun info out of GCCI buffer pointed to by r0
	mov	#alun, r2	; point to alun dpb
	mov	g.ccdv(r0), a.luna(r2)	; stuff device name
	movb	g.ccun(r0), a.lunu(r2)	; stuff unit number
	clrb	a.lunu+1(r2)		; make it integer
	dir$	#alun		; assign lun (1)
	bcs	1000$		; quit on error

100$:	; set up qio dpb
	mov	#qio, r2	; point to qio dpb
	mov	lun, q.iolu(r2)	; set lun
	mov	r1, q.iopl(r2)	; save buffer address
200$:	tstb	(r1)+		; locate buffer end
	bne	200$		; ... it's asciz
	sub	q.iopl(r2),r1	; calculate length
	dec 	r1		
	beq	1000$		; empty buffer - quit
	mov	r1, q.iopl+2(r2) ; put length in dpb
	dir$	#qio		; execute qio
	bcs	1000$		; quit on directive error
	dir$	#mrkt		; set timeout
	bcc	300$		; better not fail!
	mov	$dsw, r0	; crash and burn
	mov	#2, r1
	iot
300$:	dir$	#wtse		; wait for efn - ignore errors

1000$:	pop	<r2,r1>
	return	r5

	.SBTTL qast

.REM |
	AST service routine for QIO completion. 
	When this one fires, cancel the mark-time.
	
|

qast:
	tst	(sp)+	; clean stack
	dir$	#canmt	; cancel mark-time
	astx$s

	.SBTTL mtast

.REM |
	This is the mark-time AST service routine.
	When it fires, the output qio has timed-out.
	Kill the qio, then exit. 
	
|

mtast:
	tst	(sp)+			; clean stack
	mov	lun, kill+q.iolu	; set lun to kill
	dir$	#kill			; kill outstanding IO
	astx$s

	.end

