	.title	WRTRTR
	.IDENT	/1.2/
;.begin.doc ************************** begin.doc
;  
; .c ;MODULE
; .c ;^&WRTRTR\&
; .nf
; .x WRTRTR>Defined
; Source:WRTRTR.MAC
; TO BECOME PART OF LIBRARY:QUEUE.OLB
; Designer           :EARL LAKIA
; Author             :DAVE LUECK
;             Inland Steel
;             Process Automation Department
;             3210 Watling St.  MS 2-465
;             East Chicago, IN  46312
;  
; Date of last update:18-MAY-1987
; Revision level     :1.2
;  
; .C ;Formal Parameter List
; Receives:
;  
;    LUN                        INTEGER*2
;                               LOGICAL UNIT NUMBER ASSIGNED TO ZQ0:
;   
;    EFN                        INTEGER*2
;                               EVENT FLAG TO BE USED FOR I/O SYNC
;   
;    MSGID                      CHARACTER*16	(BYTE(16))
;                               MESSAGE ID OF MESSAGE TO BE WRITTEN
;   
;    MSGREC                     BYTE(ISIZE)
;                               MESSAGE BUFFER TO BE WRITTEN TO QUEUE           
;                               NOTE: DIMENSIONED TO SIZE ISIZE
;   
;    ISIZE                      INTEGER*2
;                               SIZE OF MESSAGE BUFFER
;   
;    TYPE                       INTEGER*2
;                               RECOVERY IF QUEUE IS FULL, (0= DELETE 
;                                OLDEST, 1= RETURN STATUS)
;  
; Returns:
;  
;    WRTRTR                     INTEGER*2 
;                               FUNCTION VALUE RETURN STATUS OF THE 
;                               WRITE.
;  
; Accesses common(s):
;  
; Accesses file(s):
;  
; Other modules referenced:
; .SK
; .fill
; .SK
; Description:
; .sk    
; 	This subroutine allows the caller to place a message into
; the Manufactoring Automation Queue.  The only difference between this
; routine and the WRITEQ routine is that the header does not get added
; to the front of the text when this routine is called.  The MAQ router
; uses this routine to bypass adding the header since it already precedes
; the data.
; The return status is returned as the value of the function subroutine.  
; The calling sequence is:
; .sk
; .tp 40
; .nofill
; 	PARAMETER (BUFSIZ=512)
; 	INTEGER*2 LUN	     ! LUN ASSIGNED TO ZQ0:
; 	INTEGER*2 IEFN	     ! EVENT FLAG
; 	CHARACTER*16 MSGID   ! MESSAGE ID
; 	BYTE BUFFER(BUFSIZ)  ! OUTPUT BUFFER
; 	INTEGER*2 ITYPE      ! TYPE OF MESSAGE
; 	INTEGER*2 STATUS     ! RETURN STATUS
; 	BYTE STATB(2)
; 	EQUIVALENCE(STATUS,STATB) ! BYTE ADDRESSABLE STATUS
; 	INTEGER*2 QUESUC     ! SUCESSFUL QUE STATUS
; C
; 	DATA QUESUC/"401/    
; 	DATA LUN/1/	     ! LOGICAL UNIT NUMBER
; 	DATA IEFN/1/	     ! EVENT FLAG FOR I/O SYNC
; C
; 	ITYPE=0		  ! DELETE OLDEST IF FULL
; 	MSGID='DUMMY ID'  ! OUR MESSAGE ID
; C
; C ASSIGN A LUN TO THE PSEUDO DEVICE FOR THE QUEUE
; C
; 	CALL ASSIGN(LUN,'ZQ0:')
; C
; C WRITE TO THE MESSAGE ID QUEUE
; C
; 	STATUS=WRTRTR(LUN,IEFN,MSGID,BUFFER,BUFSIZ,ITYPE)
; C
; 	IF(STATUS .NE. QUESUC)THEN
; 		TYPE *,' BAD QUEUE STATUS ON RTR WRITE'
; 		TYPE *,' DIRECTIVE STATUS: ',STATB(1)
; 		TYPE *,' I/O STATUS: ',STATB(2)
; 		CALL EXIT
; 	ELSE
; 		TYPE *,' SUCCESSFUL RTR WRITE'
; 	ENDIF
; .FILL
; .SK
; 	Possible error codes:
; .LIST 1,' '
; .le;Bad directive status (possibly device not mounted, etc.)
; (upper byte will be zero)
; .le;Bad I/O status (R0 lower byte= 1,  upper byte= I/O status)
; .LE;IE.UKN (-97) -- Message id does not exist.
; .le;IE.NDR (-72) -- No room left in queue.
; .le;IE.NBK (-41) -- Message to be written to queue exceeds 4014 bytes.
; .els
; end.doc ****************************** end.doc  
	.PAGE
	.MCALL	DIR$
	.MCALL	QIOW$
;
;	 0(R5)= NUMBER OF ARGUMENTS
;	 2(R5)= LUN
;	 4(R5)= EFN
;	 6(R5)= ADDRESS OF MESSAGE ID BUFFER
;	10(R5)= ADDRESS OF MESSAGE BUFFER
;	12(R5)= BYTE COUNT OF MESSAGE
;	14(R5)= ADDRESS OF ITYPE
;
	.PSECT	Q$CODE,RO,I,CON
WRTRTR::
	CMP	#6,(R5)+	; CORRECT NUMBER OF ARGUMENTS
	BEQ	10$		; YES
	TRAP	<128.+80.>	; FORTRAN OTS TRAP FOR ILLEGAL NUMBER
				; OF ARGUMENTS
	RETURN
10$:
	MOVB	@(R5)+,DOIO+Q.IOLU	; GET LOGICAL UNIT NUMBER
	MOVB	@(R5)+,DOIO+Q.IOEF	; EVENT FLAG
	MOV	(R5)+,DOIO+Q.IOPL+4	; MESSAGE ID BUFFER ADDRESS 
	MOV	(R5)+,DOIO+Q.IOPL	; MESSAGE TO WRITE BUFFER ADDRESS
	MOV	@(R5)+,DOIO+Q.IOPL+2 	; BYTE COUNT OF THE BUFFER
	MOV	@(R5),DOIO+Q.IOPL+10    ; MESSAGE TYPE
;
; NOW DO THE QIO 
;
	DIR$	#DOIO		; DO THE I/O
	BCC	30$		; DIRECTIVE ACCEPTED
	MOVB	$DSW,R0		; SIGN EXTEND BAD DIRECTIVE STATUS
	BIC	#177400,R0	; CLEAR I/O STATUS
	RETURN
;
; DIRECTIVE RECEIVED, RETURN THE I/O STATUS
;
30$:
	MOVB	IOSB,R0		; I/O STATUS
	SWAB	R0		; MOVE I/O STATUS TO UPPER BYTE
	CLRB	R0		; CLEAR LOW BYTE
	BISB	$DSW,R0		; MERGE DIRECTIVE STATUS IN LOWER BYTE
	RETURN
	.PAGE
	.PSECT	Q$DATA,RW,CON,D
;
; .le;P1= Message buffer address
; .le;P2= Byte count of user message
; .le;P3= Address of message id buffer (16 bytes long)
; .le;P4= Destroyed when id buffer relocated
; .le;P5= Type of message (0= deletable if queue is full, 1= not)
;
DOIO:
	QIOW$	IO.WVB+1,,,,IOSB,,
;
IOSB:
	.WORD	0,0
	.END
