	.title	vprint
	.mcall	fdbdf$
	.mcall	dir$, qiow$

ttlun	= 5
esc	= 33
	.psect	user$d,d
ttxy:	qiow$	IO.WVB,ttlun,2,,iostat,,<xy,8.,0>	; no cr,lfs
tt:	qiow$	IO.WVB,ttlun,3,,iostat,,<,,0>		; no cr,lfs
iostat:	.blkw	2				; iostat area
xy:	.asciz	<esc>/[00;00H/
	.even

	.psect	user$i
;
; NB we don't use terminal independent positioning as
;    we want to allow things like call vprint( 12, 20, 0 )
;    and i'm not sure how this is handled by RSX
;
vprint::
	tst	(r5)+				; skip nargs
	mov	@(r5),r0			; line no
	mov	#xy+2,r1
	call	numasc

	mov	@2(r5),r0			; column no
	mov	#xy+5,r1
	call	numasc

	dir$	#ttxy				; position cursor
	mov	4(r5),r3			; message address
	call	print1				; do it twice
	return

print::	tst	(r5)+				; skip nargs
	mov	@r5,r3				; message address

print1:	mov	#tt,r0
	mov	r3,q.iopl(r0)			; save address

	mov	r3,-(sp)			; address of message
10$:	tstb	(r3)+				; null ??
	bne	10$
	sub	(sp)+,r3			; length of message
	dec	r3
	ble	20$
	mov	r3,q.iopl+2(r0)
	clr	q.iopl+4(r0)			; make no cr, lf
	dir$	r0				; and print it
20$:	return

;
; numasc converts number <100 to ASCII, ie 2 digit only
; r0 = number to convert
; r1=>string area
;
;
numasc:	cmp	r0,#10.
	bge	10$
	movb	#'0,(r1)+
	br	30$

10$:	swab	r0

20$:	add	#173001,r0
	bpl	20$
	add	#5057,r0
	movb	r0,(r1)+
	swab	r0

30$:	add	#60,r0
	movb	r0,(r1)+
	return

	.end
