** Revision Header * Header built automatically - do not edit! *************
*
*	(C) Copyright 1991 by Olaf `Olsen' Barthel, all rights reserved
*
*	Name .....: WaitLine.asm
*	Created ..: Monday 26-Aug-91 11:20
*	Revision .: 1
*
*	Date            Author          Comment
*	=========       ========        ====================
*	26-Aug-91	Olsen		Created this file!
*
****************************************************************************

	section	text,code

	xdef	_WaitLine

;	VOID __asm WaitLine(register __d1 Line);
;
;		Small routine to wait for a specific Y-position of the	
;	electron beam (busy polling, actually).
;
;	Register usage is as follows:
;
;		d0	= Electron beam line number
;		d1	= Line number
;		a0	= Address of VPOSR register
;		a1	= Address of VHPOSR register

_WaitLine:
	lea.l	$dff006,a1	; Grab VHPOSR

	moveq	#0,d0		; Clear line counter

	sub.w	#1,d1		; Subtract one line to make it valid

	btst	#8,d1		; Bit 8 required?
	beq.s	3$

	lea.l	$dff004,a0	; Grab VPOSR

1$	move.w	(a0),d0		; Get 8th bit of line counter
	btst	#0,d0		; Bit set?
	beq.s	2$
	move.w	(a1),d0		; Get position of electron beam
	lsr.w	#8,d0		; Shift to get the high order byte
	bset	#8,d0		; Set the 8th bit
	cmp.w	d1,d0		; Compare with desired line number
	blt.s	1$		; Loop until reached
	rts

2$	move.w	(a1),d0		; Get position of electron beam
	lsr.w	#8,d0		; Shift to get the high order byte
	cmp.w	d1,d0		; Compare with desired line number
	blt.s	1$		; Loop until reached
	rts

3$	move.w	(a1),d0		; Get position of electron beam
	lsr.w	#8,d0		; Shift to get the high order byte
	cmp.w	d1,d0		; Compare with desired line number
	blt.s	3$		; Loop until reached
	rts

	end
