	.TITLE	PLTEST
	.MCALL	EXIT$S,QIOW$C
;
;
;	SUBROUTINE TO READ THE ADM3A RETROGRAPHICS BOARD AND
;	PLOT THE RESULT ON THE VERSATEC 1200 PRINTER PLOTER
;
;	LUN5	= ADM3A
;	LUN4	= TEMPORARILY ASSIGNED TO THE LP:
;
;	FLAG 1 IS USED FOR UNPUT
;		I/O IS DOUBLE BUFFERED FOR MAX SPEED
;
;	J. CLEMENT	JUNE 1981
;
	.MCALL	QIO$,QIO$S,QIOW$S,QIO$C,QIOW$C,ALUN$C,DSCP$S,ENCP$S
	.MCALL	WTSE$S,CLEF$S,SETF$S,ASTX$S
	.PSECT	SCRAT,D,OVR,GBL
	.PSECT
;
;

PLTEST::CALL	SCOPE				; Test if plotting scope
	BCC	1$				; YES
	RETURN
1$:	JSR	PC,CNVADD			; Format address
	MOV	4(R5),R2			; Output buffer address
	CALL	CNVLIN
	RETURN
;
;	ASYNCHRONOUS ROUTINE FOR OUTPUT BUFFERING
;
;
;	ROUTINE TO CONVERT A LINE OF INPUT TO PLOT LINE
;	R3	= INPUT BUFFER ADDRESS
;	R2	= OUTPUT BUFFER
;	R4	= COUNT
;
CNVLIN: MOV	#INBUF,R3			; Input buffer address
	MOV	#64.,R4				;MAX NUMBER OF BYTES TO INPUT
	MOV	#6,R0				;MAX NUMBER OF CHAR TO SEARCH
1$:	CMPB	(R3)+,#'=			;IS IT CORRECT FIRST CHARACTER
	BEQ	3$				;YES
	SOB	R0,1$				;NO
	BR	12$				;BLANK LINE
3$:	MOVB	(R3)+,R0			;GET CHARACTER
	CMPB	R0,#';				;IS IT END OF BUFF?
	BEQ	12$				;YES
	CMPB	R0,#'#				;IS IT ZERO COUNT?
	BNE	5$				;NO
	MOVB	(R3)+,R0			;GET COUNT
	BIC	#177300,R0			;GET COUNT
	BEQ	3$				;IT IS NFG
	ASL	R0
2$:	CLR	(R2)+
	DEC	R4
	BLE	13$
	SOB	R0,2$
	BR	3$
5$:	CMPB	R0,#'A				;IS CHAR A TO F (HEX INPUT)?
	BGE	6$				;YES
	SUB	#'0,R0				;CONVERT 0 TO 9 TO BINARY
	BR	7$
6$:	SUB	#67,R0				;CONVERT A TO F TO BINARY
7$:	BIC	#177760,R0
	ASL	R0				;NOW IS WORD ADDRESS
	MOV	TABL(R0),(R2)+			;INTO OUTPUT BUFFER
11$:	SOB	R4,3$				;CONTINUE TILL DONE
	BR	13$
12$:	CLR	(R2)+				;CLEAR REST OF BUFF
	SOB	R4,12$
13$:	RETURN

;
;	ROUTINE TO GENERATE HALF LINE ADDRESS
;	THEN START THE OUTPUT
;	R0,R1	ARE USED FOR SCRATCH
;	R4	= THE BUFFER ADDRESS FOR INPUT
;
CNVADD:	MOV	@2(R5),R1			; Get half line address
	CMP	R1,#499.			;ADDRESS TOO BIG?
	BLOS	1$
	TST	(SP)+
	RETURN					;YES
1$:	MOV	R1,R0
	ASH	#-5,R0				;SPLIT INTO 2 5 BIT ADDRESSES
	BIC	#177740,R0
	BIC	#177740,R1
	BIS	#100,R0
	BIS	#100,R1
	MOVB	R0,ADD1
	MOVB	R1,ADD1+1
;		READ A HALF LINE
;		READ NO ECHO (RNE) AFTER BINARY (BIN) PROMPT (RPR)
;
	QIOW$S	#IO.RPR!TF.RNE!TF.BIN,#5,#1,,,,<#INBUF,#70.,#2,#RQBUF,#7>
	QIOW$S	#IO.WAL,#5,#1,,,,<#ADMODE,#3>
	RETURN

;
;	IMPURE DATA TABLE
;
FF:	.BYTE	14,15				;FORM FEED
ADMODE:	.BYTE	37,30,16			;PLOT MODE,ADM MODE,UNLOCK KB:
RQBUF:	.BYTE	17,34,37			;LOCK KB,4010 MOD,4010 CHAR MOD
	.BYTE	33,21				;REQUEST INPUT DATA
ADD1:	.BLKB	2				;LINE NUMBER REQUESTED
INBUF:	.BLKB	150.				; Terminal input buffer
.even
;
;	DATA TABLE OF BITS TO PLOT
;
TABL:	.WORD	     0,  7400,170000,177400
	.WORD	    17,  7417,170017,177417
	.WORD	   360,  7760,170360,177760
	.WORD	   377,  7777,170377,177777
	.END
