	.text

	move.l	4(sp),a0		* compute size to Ptermres
	move.l	$c(a0),d0
	add.l	$14(a0),d0
	add.l	$1c(a0),d0
	add.l	#$100,d0
	move.l	d0, size_store		* keep value
	
	move.l	#install, -(sp)		* address of install routine
	move.w	#38, -(sp)		* Supexec()
	trap	#14			* -> xbios
	addq.l	#6, sp			* correct sp
	
	move.w	#0, -(sp)		* No error
	move.l	size_store, -(sp)	* size of pgm.
	move.w	#$31, -(sp)		* Ptermres()
	trap	#1

idle:
	bra	idle			* infinite loop

*----------------
*
*    Rwabs() intercept
*	o  save return address
*	o  setup to return to ret_handler
*	o  turn on the indicator
*	o  follow through old Rwabs() vector
*
handler:
	move.l	(sp),ret_addr		* save return address
	move.l	#ret_handler,(sp)	* arrange return to ret_handler

	cmp.w	#6, 14(sp)		* is it the ramdisk ???
	bne	skip			* NO -> do nothing
	
	move.w	sr, -(sp)		* save sr
	or.w	#$700, sr		* disable IRQs
	move.b	#14, $ff8800		* select GIA PORT A
	and.b	#$FD, $ff8802		* turn on DRIVE-A led ...
	move.w	(sp)+, sr		* restore sr
	st	now_flag		* keep action in mind

skip:
	move.l	old_rw,a0		* follow through to
	jmp	(a0)			*	original handler


*----------------
*
*    Rwabs return intercept
*	o  turn off the indicator
*	o  flip indicator offset
*	o  return to original caller
*
ret_handler:

	tst	now_flag		* NOW ?
	beq	skip2			* No ---

	clr.b	now_flag		* reset flag
	move.w	sr, -(sp)		* save sr
	or.w	#$700, sr		* mask out ALL IRQs
	move.b	#14, $ff8800		* select GIA-PORT A
	or.b	#2, $ff8802		* set bit 1
	move.w	(sp)+, sr		* reset sr

skip2:
	move.l	ret_addr,a0		* return to original caller
	jmp	(a0)

*----------------
*
*    Rwabs() intercept installer
*
hdv_rw	equ	$476

install:
	move.l	hdv_rw,old_rw		* save old vector
	move.l	#handler,hdv_rw		* install our new one
	rts


	.bss
size_store:	ds.l	1		* temp storage
old_rw:		ds.l	1		* = original hdv_rw vector
ret_addr:	ds.l	1		* = caller's return address
now_flag:	ds.w	1		* = LED turned ON before RWABS ?
