	.TITLE QIORTT
	.IDENT /081086/



;	Version:
;	File:[22,320]QIORTT.MAC
;	Author: Peter Stadick (Third Author)
;	History: 20-Nov-83 -- convert to Pascal-3
;                13-Feb-85 -- Randy Baldwin
;                             fix iosb address pass in call,
;                             change DETACH function to DETCH to
;                             remove conflict with PASCALS DETACH
;                             function call.
;		 08-AUG-86 -- Derived from Jim Bostwick 
;			      (from Pascal-1 by Frank Stevens)
;                             Peter Stadick converted to read with
;			      terminator table.
;	Last Edit: 10-AUG-1986 18:26:03 
; 

.REM |

Procedure QIORTT(LUN:Integer; 
		EFN:Event_flag;
		Stadd:Address; 
		Size:Integer; 
		Timeout:INTEGER;
		Ttable:Address;
		VAR Iosb:IO_status_block
		);EXTERNAL;

{*USER*
 Pascal-3 Procedure to execute QIO RTT function.

This procedure will use Executive Queue I/O Request and Wait (QIOW$S) Call.  

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. 

STADD is the starting address of the buffer to be read or written.  
Use LOOPHOLE(Address,Ref(string)) to produce this parameter.

SIZE is the size of the buffer referenced by STADD.

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.  If
timeout is not needed, specify timeout of zero.
NOTE: Check your system! Some systems have been patched to take timeout
value in seconds (not 10-seconds), and to keep much more accurate time. 

TTABLE this is the address of a 16 word terminator table that must be set
up before the procedure can be used.

IOSB and IOSB2 represent the two words of the IO status block. 
IOSB contains the IO status word. For read functions, the high byte 
contains the terminating character. 
IOSB2 is the second word of the IO status block, for read functions,
it contains the byte count read in.

Directive status is available in $DSW on return.

} 
|

;
; Assemble with PASMAC.MAC as prefix file.
;
; Thanks to Frank S. for the idea and the Pascal-1 version, which I 
; brazenly plagiarized. Same here - P. Stadick.
;

         .MCALL  QIOW$S
	
	PROC QIORTT
	PARAM LUN, INTEGER
	PARAM EFN, SCALAR
	PARAM STADD, ADDRESS
	PARAM SIZE, INTEGER
	PARAM TMO, INTEGER
	PARAM TTABLE, ADDRESS
	PARAM ISB1, ADDRESS
	SAVE <R0, R1, R2, R3, R4 >
	BEGIN
	MOV SP,R0			;PRESERVE SP
        MOV #IO.RTT,R1			;RTT FUNCTION CODE IN R1
	BIS #TF.RNE,R1			;OR IN TF.RNE INTO IO.RTT IN R1
	BIS #TF.RAL,R1			;OR IN TF.RAL INTO IO.RTT 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				;BRANCH IF ERROR
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.RTT IN R1
	MOV TMO(0),R4			;PUT TIMEOUT VALUE IN R4
3$:	MOV ISB1(SP),R3			;GET ADDRESS OF IO STATUS BLOCK
        QIOW$S  R1,LUN(0),R2,,R3,,<STADD(0),SIZE(0),,TTABLE(0)>
	TSTB (R3)			; CHECK IO STATUS
	BPL XT				;BR IF NO ERROR
	MOVB #-1, 1(R3)			; EXTEND SIGN
XT:
	ENDPR
	.END

