; This source file is part of the LynxLib miscellaneous library by
; Robert Fischer, and is Copyright 1990 by Robert Fischer.  It costs no
; money, and you may not make money off of it, but you may redistribute
; it.  It comes with ABSOLUTELY NO WARRANTY.  See the file LYNXLIB.DOC
; for more details.
; To contact the author:
; 	Robert Fischer \\80 Killdeer Rd \\Hamden, CT   06517   USA
; 	(203) 288-9599     fischer-robert@cs.yale.edu

; Stuff having to do with clocking
; By Robert Fischer, January 17, 1988
.include "atari.s"

	.globl _read_clock
	.globl _wait

_read_clock:
	clr.l	-(sp)		; Supervisor Mode
	move.w	#$20,-(sp)
	trap	#GEMDOS
	addq	#6,sp

	move.l	_hz_200, -(sp)

	move.l	d0,-(sp)		; User mode
	move.w	#$20,-(sp)
	trap	#GEMDOS
	addq	#6,sp

	move.l	(sp)+, d0
	rts


_wait: .cargs .delay.w
	move.l	d4, -(sp)		; Save Registers

	bsr		_read_clock
	move.w	.delay+4(sp), d4
	ext.l	d4
	add.l	d0, d4

waitloop:
	bsr		_read_clock
	cmp.l	d0, d4
	bpl		waitloop

	move.l	(sp)+, d4
	rts
