	.TITLE	KWV11S
	.MCALL	EXIT$S,qiow$s
;
;
ODD:	.WORD	0			;Odd address indicator
;
errtxt:	.ascii	/kwv11a--- does not exist/
errtxl=.-errtxt
	.even
nopool:	.ascii	/kwv11a--- no pool space left/
nopoll=.-nopool
	.even
pattxt:	.ascii	/kwv11a--- patch area not found/
pattxl	=.-pattxt
	.even
;
START:	CLR	ODD			;Say device present
	CALL	$SWSTK,10$		;Enter system state
	MOV	#1000$,-(SP)		;Return address from $sgfin
	CALL	$SGFIN			;Toggle trap vector
	TST	@#170420		;Is this device here
	BCC	1$			;If cc,yes
	DEC	ODD			;Tell user odd address
1$:	RETURN				;Restore trap vectors
1000$:	TST	ODD			;Was device there
	BLT	9$			;If lt,no just exit
	MOV	R0,-(SP)		;save reg.
	MOV	R1,-(SP)		;
	MOV	R2,-(SP)		;
	MOV	R3,-(SP)
	MOV	#5,R2			;Set loop count
	MOV	#$CKINT,R0		;Get address to clock interupt code
5$:	CMP	(R0)+,#4737		;Look for patch area
	BEQ	66$			;if eq,match
	SOB	R2,5$			;continue with loop
	inc	odd			;indicate no
	br	50$			;and exit
66$:
7$:	MOV	#12704,-2(R0)		;Restore code for call @#VEC
	MOV	#$INTCT,(R0)		;   .....
	MOV	@#450,@#100		;Toggle the interupt vectors
	MOV	@#452,@#102		;from line clock to KWV11A
	MOV	#$NONSI,@#450		;Set nonsens interupt for line cock
	BIS	#100,@#177546		;Enable line clock
	CLR	@#170422		;Disable KWV11A
50$:	MOV	(SP)+,R3
	MOV	(SP)+,R2		;Restore reg.
	MOV	(SP)+,R1		;
	MOV	(SP)+,R0		;
	MTPS	#PR0			;Enable interupts
9$:	RETURN				;Return to user state

10$:	
	tst	odd			;any error
	bgt	102$			;if gt yes
	blt	101$			;if lt it doesn't exist
	EXIT$S				;Exit
101$:	mov	#errtxt,r1
	mov	#errtxl,r2
	br	104$
102$:	dec	odd
	bgt	103$
	mov	#pattxt,r1
	mov	#pattxl,r2
	br	104$
103$:	mov	#nopool,r1
	mov	#nopoll,r2
104$:	qiow$s	#io.wlb,#5,#5,,,,<r1,r2,#40>
	exit$s
	.END	START
