
; Interrupts Example 3		Vertical Blank Interrupt

; Poking a Copper list in order to bounce three bars, each consisting of
;five coloured strips.

		include		hardware.i
		include		HW_Macros.i
		include		HW_Start.i

		opt o-

; Define address of our Copper List

Main		STARTCOP	#CList

; Enable Copper DMA

		move.w		#SETIT!DMAEN!COPEN,DMACON(a5) use our settings

; Set address of Level 3 interrupt handler

		move.l		#Bounce,$6c		set handler address

; Enable VBI interrupt ( Vertical Blank Interrupt )

		move.w		#SETIT+INTEN+VERTB,INTENA(a5)

; Wait for LMB to be pressed

Loop		btst		#6,CIAAPRA
		bne.s		Loop

		rts					exit

; VBI handler. Called at start of each Vertical Blanking period

Bounce		lea		$dff000,a5		a5->Register base


; Decide which direction to move the top bar

		lea		bar1,a0			a0-->first bar
		tst.b		direction1		up or down ?
		bne.s		up1			branch for up

; Top bar is going down, bump Wait value for each strip in the bar.

		addq.b		#1,0(a0)		1st strip down
		addq.b		#1,8(a0)		2nd strip down
		addq.b		#1,16(a0)		3rd strip down
		addq.b		#1,24(a0)		4th strip down
		addq.b		#1,32(a0)		5th strip down
		addq.b		#1,40(a0)		background
		bra.s		chk_direction1		jump over up rountine

; Top bar is going up, decrease Wait value for each strip in the bar.

up1		subq.b		#1,0(a0)		1st strip up
		subq.b		#1,8(a0)		2nd strip up
		subq.b		#1,16(a0)		3rd strip up
		subq.b		#1,24(a0)		4th strip up
		subq.b		#1,32(a0)		5th strip up
		subq.b		#1,40(a0)		background

; Update variables controlling the top bar.

chk_direction1	addq.b		#1,counter1		increase counter
		cmpi.b		#50,counter1		change direction ?
		bne.s		bounce_2		if not don't worry
		not.b		direction1		else toggle flag
		move.b		#0,counter1		and reset counter

; Decide which direction to move the middle bar

bounce_2	lea		bar2,a0			a0-->second
		tst.b		direction2		up or down ?
		bne.s		up2			branch for up

; Middle bar is going down, bump Wait value for each strip in the bar.

		addq.b		#1,0(a0)		1st strip down
		addq.b		#1,8(a0)		2nd strip down
		addq.b		#1,16(a0)		3rd strip down
		addq.b		#1,24(a0)		4th strip down
		addq.b		#1,32(a0)		5th strip down
		addq.b		#1,40(a0)		background
		bra.s		chk_direction2		jump over up rountine
		
; Middle bar is going up, decrease Wait value for each strip in the bar.

up2		subq.b		#1,0(a0)		1st strip up
		subq.b		#1,8(a0)		2nd strip up
		subq.b		#1,16(a0)		3rd strip up
		subq.b		#1,24(a0)		4th strip up
		subq.b		#1,32(a0)		5th strip up
		subq.b		#1,40(a0)		background

; Update variables controlling the middle bar.

chk_direction2	addq.b		#1,counter2		increase counter
		cmpi.b		#100,counter2		change direction ?
		bne.s		bounce_3		if not don't worry
		not.b		direction2		else toggle flag
		move.b		#0,counter2		and reset counter

; Decide which direction to move the bottom bar

bounce_3	lea		bar3,a0			a0-->third bar
		tst.b		direction3		up or down ?
		bne.s		up3			branch for up

; Bottom bar is going down, bump Wait value for each strip in the bar.

		addq.b		#1,0(a0)		1st strip down
		addq.b		#1,8(a0)		2nd strip down
		addq.b		#1,16(a0)		3rd strip down
		addq.b		#1,24(a0)		4th strip down
		addq.b		#1,32(a0)		5th strip down
		addq.b		#1,40(a0)		background
		bra.s		chk_direction3		jump over up rountine

; Bottom bar is going up, decrease Wait value for each strip in the bar.
		
up3		subq.b		#1,0(a0)		1st strip up
		subq.b		#1,8(a0)		2nd strip up
		subq.b		#1,16(a0)		3rd strip up
		subq.b		#1,24(a0)		4th strip up
		subq.b		#1,32(a0)		5th strip up
		subq.b		#1,40(a0)		background

; Update variables controlling the bottom bar.

chk_direction3	addq.b		#1,counter3		increase counter
		cmpi.b		#50,counter3		change direction ?
		bne.s		no_change		if not don't worry
		not.b		direction3		else toggle flag
		move.b		#0,counter3		and reset counter

; Clear interrupt request bits

no_change	move.w		INTREQR(a5),d0		get bits
		and.w		#$7fff,d0		clear bit 15
		move.w		d0,INTREQ(a5)		clear request

; Exit back to User Mode

		rte

*****	Required Data

counter1	dc.b		49
direction1	dc.b		0
counter2	dc.b		0
direction2	dc.b		0
counter3	dc.b		0
direction3	dc.b		0
		even

*****	Required CHIP data

section		data custom,chip		****  Use this for A68K  ****

;		Section		custom,data_C	**** Use this for Devpac ****

CList		CMOVE		COLOR00,$0000		colour 0 = black
		CWAIT		0,40			wait for (0,40)
		
bar1		CWAIT		0,84
		CMOVE		COLOR00,$06ce		colour 0 = light blue
		CWAIT		0,85
		CMOVE		COLOR00,$006d		colour 0 = dark blue
		CWAIT		0,87
		CMOVE		COLOR00,$000f		colour 0 = blue
		CWAIT		0,90
		CMOVE		COLOR00,$006d		colour 0 = dark blue
		CWAIT		0,92
		CMOVE		COLOR00,$06ce		colour 0 = light blue
		CWAIT		0,93
		CMOVE		COLOR00,$0000		colour 0 = black
		
bar2		CWAIT		0,94
		CMOVE		COLOR00,$08e0		colour 0 = light green
		CWAIT		0,95
		CMOVE		COLOR00,$02c0		colour 0 = dark green
		CWAIT		0,97
		CMOVE		COLOR00,$00f0		colour 0 = green
		CWAIT		0,100
		CMOVE		COLOR00,$02c0		colour 0 = dark green
		CWAIT		0,102
		CMOVE		COLOR00,$08e0		colour 0 = light green
		CWAIT		0,103
		CMOVE		COLOR00,$0000		colour 0 = black
		
bar3		CWAIT		0,204
		CMOVE		COLOR00,$06ce		colour 0 = light blue
		CWAIT		0,205
		CMOVE		COLOR00,$006d		colour 0 = dark blue
		CWAIT		0,207
		CMOVE		COLOR00,$000f		colour 0 = blue
		CWAIT		0,210
		CMOVE		COLOR00,$006d		colour 0 = dark blue
		CWAIT		0,212
		CMOVE		COLOR00,$06ce		colour 0 = light blue
		CWAIT		0,213
		CMOVE		COLOR00,$0000		colour 0 = black
		
		CEND

		end

