	.title	pdp92	direct access i/o for ted under RSTS/E
	.ident	/9.2.01/

;	Bypass rms direct i/o for TED on RSTS/E
;	08-Apr-86  10:37:02  Brian Nelson


	.psect
	.include	/SY:[1,2]COMMON.MAC/
	.psect	code	,ro,i,lcl,rel,con
	.psect	data	,ro,d,lcl,rel,con

lunmap:	.word	1,2,0

	.psect	code

rstsge::mov	#XRB	,r0		; Setup a read request
	mov	4(sp)	,(r0)+		; XRLEN, size of the read
	clr	(r0)+			; XRBC, Must be zero
	mov	2(sp)	,(r0)+		; XRLOC, buffer address
	mov	10(sp)	,r1		; Window number
	asl	r1			; Word addressing
	movb	lunmap(r1),(r0)		; XRCI,Insert correct channel number
	aslb	(r0)+			; Times 2
	clrb	(r0)+			; XRBLKM, clear out
	mov	6(sp)	,(r0)+		; XRBLK, virtual block to write
	clr	(r0)+			; XRTIME, unused
	clr	(r0)+			; XRMOD, unused
	.READ				; Do it
	clr	r0			; Assume failure
	tstb	FIRQB			; Did it work ?
	bne	100$			; No, exit
	inc	r0			; Yes, return(1)
100$:	return				; Exit

rstspu::mov	#XRB	,r0		; Setup a read request
	mov	4(sp)	,(r0)+		; XRLEN, size of the write
	mov	4(sp)	,(r0)+		; XRBC, size of the write
	mov	2(sp)	,(r0)+		; XRLOC, buffer address
	mov	10(sp)	,r1		; Window number
	asl	r1			; Word addressing
	movb	lunmap(r1),(r0)		; XRCI,Insert correct channel number
	aslb	(r0)+			; Times 2
	clrb	(r0)+			; XRBLKM, clear out
	mov	6(sp)	,(r0)+		; XRBLK, virtual block to write
	clr	(r0)+			; XRTIME, unused
	clr	(r0)+			; XRMOD, unused
	.WRITE				; Do it
	clr	r0			; Assume failure
	tstb	FIRQB			; Did it work ?
	bne	100$			; No, exit
	inc	r0			; Yes, return(1)
100$:	return				; Exit



rstscl::mov	#1	,r0		; Do nothing for tentative files
	return

	.psect	data
workna:	.asciz	/TED$TEMP:EDIT.TMP/
tempna:	.asciz	/EDIT.TMP/
	.even
	.psect	code

rstscr::mov	#1	,-(sp)		; Primary work file
	mov	#workna	,-(sp)		; Preferred name
	call	op			; Check it out
	bne	20$			; Success
	mov	#tempna	,(sp)		; Failed, try w/o logical name
	call	op			; ....
	beq	100$			; Failed, die now
20$:	mov	#2	,2(sp)		; Next channel
	mov	#workna	,(sp)		; Try it again
	call	op			; ...
	bne	100$			; Success
	mov	#tempna	,(sp)		; No, try again
	call	op			; ...
100$:	cmp	(sp)+	,(sp)+		; Pop stack and exit
	return


op:	mov	#FIRQB	,r0		; Insure no defaults hanging around
	mov	#40	,r1		; So clear the FIRQB out
10$:	clrb	(r0)+			; Do it
	sob	r1	,10$		; Next please
	mov	2(sp)	,r1		; Get string length
20$:	tstb	(r1)+			; Find the end yet?
	bne	20$			; No
	sub	2(sp)	,r1		; Yes, get length
	dec	r1			; ....
	mov	#XRB	,r0		; Setup for .FSS
	mov	r1	,(r0)+		; XRLEN, length of string
	mov	r1	,(r0)+		; XRBC , length of string
	mov	2(sp)	,(r0)+		; XRLOC, buffer address
	clr	(r0)+			; Unused
	clr	(r0)+			; Unused..
	clr	(r0)+			; Unused....
	clr	(r0)+			; Unused......
	.FSS				; At last, do it
	tstb	FIRQB			; Success?
	bne	90$			; No
	movb	#CREFQ	,FIRQB+FQFUN	; Now try to create it
	movb	4(sp)	,FIRQB+FQFIL	; Channel
	aslb	FIRQB+FQFIL		; Times two
	mov	#100040	,FIRQB+FQMODE	; Tentative
..clus	== . + 2			;
	mov	#20	,FIRQB+FQCLUS	; Clustersize
	CALFIP				; Do it
	tstb	FIRQB			; Success?
	bne	90$			; No
	mov	#1	,r0		; Return(success)
	return				; Exit

90$:	clr	r0			; Failed
	return				; Exit

	.end
