	.TITLE QIOWRP
	.IDENT /01AU85/



;	Version:
;	File:[22,320]QIOWRP.MAC
;	Author: Phil Hannay  (derived from QIOW.MAC)
;	History: 01-Aug-85  -- created.
;
;	Last Edit: 1-AUG-1985 11:19:22 
; 

.REM |

Procedure QIOWRP(LUN:Integer; 
		EFN:Event_flag;
	        Inadr:Address;
                Insiz:Integer;
		Timeout:INTEGER;
		Outadr:Address; 
		Outsiz:Integer; 
	    VAR Iostat:IO_status_block
		);EXTERNAL;

{*USER*
 Pascal-3 Procedure to execute QIO Read with Prompt function.

This procedure is provided since it won't fit into the normal parameters
for the Pascal-3 QIOW procedure.  A read with prompt will be done, outputting
characters specified by OUTADR and OUTSIZ, and inputting the response 
characters into the area specified by INADR and INSIZ.  Note that we order
the input and output buffer parmeters in the same order as the QIO IO.RPR
parameter list, so that we specify the input buffer and size first, and
then later, the output buffer and size.  This may seem inconsistent since
we output first and then input.  But this keeps it consistent with the
order if your used to using the QIO in macro.

No vertical form control will be provided.  This means that there will
be no <CR> after the prompt output.  If you desire different form control,
you must embed the desired form control characters into the output prompt.

LUN is the logical unit number to be assigned to the appropriate device.  

EFN is the event flag to be set when the I/O is completed. f0 may 
not be specified. 

INADR is the starting address of the buffer to be written as the prompt.
Use LOOPHOLE(Address,Ref(string)) to produce this parameter.

INSIZ is the size of the buffer referenced by OUTADR.  This value must
not exceed the size of the buffer referenced by OUTADR to prevent writing
beyond the end of the buffer.  It can be smaller than the buffer, to
terminate the qio on a fixed number of characters.

Timeout is an optional feature.  If used, the number passed should reflect
the number of 10-second intervals that should elapse before processing 
continues.  The 10-second feature is not terribly accurate; specifying an
interval of 10 seconds may give an interval of from 1 to 10 seconds.  

A zero indicates a "zero timeout"
is to be done, a negative value indicates "no timeout" is to be done, and
a positive value indicates "timeout of value*10 seconds" to be done.
Note that this will conform to Version 3.0 of M+, when zero timeouts are
implemented.  Previous QIO procedures did not accomodate zero timeouts.

OUTADR is the starting address of the buffer to be written as the prompt.
Use LOOPHOLE(Address,Ref(string)) to produce this parameter.

OUTSIZ is the size of the buffer referenced by OUTADR.

IOSTAT represents the two words of the IO status block. 

IOSTAT[1] contains the IO status word. For read functions, the high byte 
contains the terminating character and the low byte the 1 for success.
If input terminated on char count, IOSTAT[1] will be just 1, and terminating
character 0 (null).  If input terminated on timeout, IOSTAT[1] will be
2, and terminating character 0 (null).

IOSTAT[2] is the second word of the IO status block, for read functions,
it contains the byte count of characters read in (not counting the <cr>.

Directive status is available in $DSW on return.

} 
|

;
; Assemble with PASMAC.MAC as prefix file.
;
; Adapted from QIOW with thanks to Frank S., Randy B. and Jim B.
;

	
         .MCALL  QIOW$S
	
	PROC QIOWRP
	PARAM LUN, INTEGER
	PARAM EFN, SCALAR
	PARAM INADR, ADDRESS
	PARAM INSIZ, INTEGER
	PARAM TMO, INTEGER
	PARAM OUTADR, ADDRESS
	PARAM OUTSIZ, INTEGER
	PARAM IOSTAT, ADDRESS
	SAVE <R0, R1, R2, R3, R4 >
	BEGIN
	MOV SP,R0			;PRESERVE SP
	MOV #IO.RPR,R1			;RPR FUNCTION CODE IN R1
	MOVB EFN(0),R2			;EFN PARAM IS A BYTE, MUST CLEAN IT UP
	BIC #^C^O377,R2			;MAKE IT AN UNSIGNED WORD
  	BNE 2$				
	MOV #IE.IEF, $DSW		;MUST SUPPLY EVENT FLAG
	BR XT
2$:	CLR R4				;R4 IS TIMEOUT VALUE
	TST TMO(0)			;SEE IF WE ARE TO DO A TIMEOUT
	BLT 3$				;BRANCH IF NEGATIVE (NO TIMEOUT)
	BIS #TF.TMO,R1			;OR IN TF.TMO INTO IO.RPR IN R1
	MOV TMO(0),R4			;PUT TIMEOUT VALUE INTO R4
3$:	MOV IOSTAT(SP),R3		;GET ADDRESS OF IO STATUS BLOCK
        QIOW$S  R1,LUN(0),R2,,R3,,<INADR(0),INSIZ(0),R4,OUTADR(0),OUTSIZ(0),#0>
        TSTB (R3)			; CHECK IO STATUS
	BPL XT				;BR IF NO ERROR
	MOVB #-1, 1(R3)			; EXTEND SIGN
XT:
	ENDPR
	.END

