*
*
*	p_pause( (long)timeout ); - uses RTX if there, otherwises uses
*		200Hz system timer to emulate it
*
*
	.text

	.globl _p_pause
_p_pause:
	pea	0			* go into supervisor mode
	move.w	#$20,-(sp)		* Super(0)
	trap	#1			* enter GEMDOS
	addq.l 	#6,sp			* restore stack
	tst.b	$94			* check RTX vector
	bne	no_rtx			* no, emulate
	move.l	d0,-(sp)		* set SSP back
	move.w	#$20,-(sp)		* Super(savessp)
	trap 	#1			* enter GEMDOS
	addq.l 	#6,sp			* restore stack
*
* OK, now do RTX call
*
	move.l	4(sp),-(sp)		* timeout
	move.w	#$c,-(sp)		* p_pause
	trap	#5			* enter RTX
	addq.l	#6,sp
	cmp.l	#-1,d0			in system but not installed
	beq	sup_no
	rts

sup_no:				* reenter supervisor
	pea	0			* go into supervisor mode
	move.w	#$20,-(sp)		* Super(0)
	trap	#1			* enter GEMDOS
	addq.l 	#6,sp			* restore stack

*
* emulate
*
no_rtx:
	move.l	4(sp),d1	millisecond delay
	addq.l	#3,d1		round
	divu	#5,d1		change into tic count
	ext.l	d1		extend result
	add.l	$4ba,d1		raw timer tic

wait1	cmp.l	$4ba,d1		wait until timer catches up
	bhi	wait1

	move.l d0,-(sp)			* set SSP back
	move.w #$20,-(sp)		* Super(savessp)
	trap #1				* enter GEMDOS
	addq.l #6,sp			* restore stack

	clr.l	d0
	rts

	.end
