
; Display Example 6. -- Vertical Scrolling --

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

; Use macro to set BPL pointers and build colour defenition in Copper List.
; Display is 320x512 in 16 colours.

Main		COPBPLC		CopPlanes,bitplane,(320/8)*512,4

; Define address of Copper List

		STARTCOP	#MyCopper

; Enable bitplane and Copper DMA.

		move.w		#SETIT!DMAEN!COPEN!BPLEN,DMACON(a5)

; Install vertical blank interrupt handler and enable it.

		move.l		#NewLevel3,$6c		install
		
		move.w		#SETIT!INTEN!VERTB,INTENA(a5)

; Wait for user to press the left mouse button

mouse		btst		#6,CIAAPRA
		bne.s		mouse

; And exit.

		rts

;		************************
;		* Vert Blank Interrupt *
;		************************


NewLevel3	lea		$dff000,a5		a5->hardware base

		bsr		Scroll
		
		move.w		INTREQR(a5),d0		get bits
		and.w		#VERTB!COPER!BLIT,d0
		move.w		d0,INTREQ(a5)		clear request
		rte					back to user mode


;		****************************
; 		* Scroll up or down 1 line *
;		****************************

Scroll		move.l		Counter,d0
		move.l		direction,d1
		move.l		terminate,d2

		add.l		d1,d0		bump counter
		move.l		d0,Counter	save new value
		cmp.l		d0,d2		change direction?
		bne.s		no_change	no, exit routine
		
		move.l		spare,terminate	switch direction limits
		move.l		d2,spare
		neg.l		d1
		move.l		d1,direction	change direction

no_change	mulu		#40,d0		calculate offset
		add.l		#bitplane,d0	form start address
		bsr		PutPointers	update Copper list
		rts

;		**************************
;		* Poke bit plane address *
;		*    into Copper list    *
;		**************************

; Entry		d0=start address of 1st bit planes data

PutPointers	moveq.l		#4-1,d1		number of bit planes - 1
		lea		CopPlanes,a0	a0->into Copper list

put_loop	move.w		d0,6(a0)	low word of address
		swap		d0
		move.w		d0,2(a0)	high word of address
		swap		d0
		add.l		#40*512,d0	addr of next bit plane
		addq.l		#8,a0		next pointer in Copper list
		dbra		d1,put_loop

		rts

;		***************************
;		*        Variables        *
;		***************************


Counter		dc.l		0		offset
direction	dc.l		1		1=up, -1=down
terminate	dc.l		255		change direction at ...
spare		dc.l		0

;		***************************
;		*     CHIP Memory Data    *
;		***************************

;section		data custom,chip
		section		fish,data_c
		
MyCopper	CMOVE		DIWSTRT,$2c81		PAL -- 256 lines
		CMOVE		DIWSTOP,$2cc1
		CMOVE		DDFSTRT,$0038		LoRes
		CMOVE		DDFSTOP,$00d0
		CMOVE		BPL1MOD,$0000		No modulos
		CMOVE		BPL2MOD,$0000
		CMOVE		BPLCON0,$4200		4 bitplanes & colour
		CMOVE		BPLCON1,$0000		No scrolling
		CMOVE		BPLCON2,$0000		Ignore priority

CopPlanes	CMOVE		BPL1PTH,0		Bit plane pointers
		CMOVE		BPL1PTL,0		filled in by the
		CMOVE		BPL2PTH,0		program!
		CMOVE		BPL2PTL,0
		CMOVE		BPL3PTH,0
		CMOVE		BPL3PTL,0
		CMOVE		BPL4PTH,0
		CMOVE		BPL4PTL,0

CopColours	CMOVE		COLOR00,$0000		The colours will be
		CMOVE		COLOR01,$0000		filled in by the
		CMOVE		COLOR02,$0000		program!
		CMOVE		COLOR03,$0000
		CMOVE		COLOR04,$0000
		CMOVE		COLOR05,$0000
		CMOVE		COLOR06,$0000
		CMOVE		COLOR07,$0000
		CMOVE		COLOR08,$0000
		CMOVE		COLOR09,$0000
		CMOVE		COLOR10,$0000
		CMOVE		COLOR11,$0000
		CMOVE		COLOR12,$0000
		CMOVE		COLOR13,$0000
		CMOVE		COLOR14,$0000
		CMOVE		COLOR15,$0000

		CEND					end of list

bitplane	incbin		'pic3.bm'

		end

		
