
; Blitter Example 		Scroll Texts -- A 32x32 pixel font scroller.

;				Bit planes are 352x256, playfield is 320x256
;				and a bitplane modulo of 4 bytes is used.
;				Result is 32 pixels off right side that
;				is not visible and can be used to write a
;				scroll text into!

; 				The font was designed in DPaint on a
;				320x256x4 display and cut as a brush 320x99x4
;				There are 10 chars per line, starting with
;				the character A.

;				The screen is scrolled 2 pixels per VBL, so
;				a new character is printed every 16 VBL's.

		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,(352/8)*256,4

; Define address of Copper List

		STARTCOP	#MyCopper

; Enable bitplane and Copper DMA.

		move.w		#SETIT!DMAEN!COPEN!BPLEN!BLTEN,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

; Screen is scrolled 2 pixels each VBI so we need to blit next character
;after 16 VBL's. This is the counter that controls this.

		tst.w		VCount			5 second delay
		bne.s		Scroll	

; When counter reaches zero, blit a character and reset the counter.

		bsr		DoChar
		move.w		#16,VCount

; Now scroll screen left

Scroll		subq.w		#1,VCount
		bsr		ScrollScreen

; And clear the interrupt

		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 Screen Using Blitter*
;		******************************

ScrollScreen	move.l		#bitplane,d7		address of bitplane

; Scrolling starts at end of last last line of the text area. The text area
;starts 140 lines down the display and is 32 lines high.

		add.l		#173*(352/8),d7
		subq.l		#2,d7			last word scroll area

		move.l		#256*(352/8),d6		size of bpl
		moveq.l		#3,d5			bpl counter

; Use blitter to scroll each line of the display

BWait		btst		#14,DMACONR(a5)		wait for Blitter
		bne.s		BWait

		move.l		d7,BLTAPTH(a5)		source
		move.l		d7,BLTDPTH(a5)		dest = source
		move.w		#0,BLTAMOD(a5)		no modulo
		move.w		#0,BLTDMOD(a5)
		move.w		#-1,BLTAFWM(a5)		no masking
		move.w		#$29f0,BLTCON0(a5)	A Scrl=2,use A,D, A=D
		move.w		#$0002,BLTCON1(a5)	B Scrl=0, Descending
		move.w		#32<<6!22,BLTSIZE(a5)	22 words by 32 lines

		add.l		d6,d7
		dbra		d5,BWait

		rts

;		*******************************
;		* Next Character Using Blitter*
;		*******************************

DoChar		move.l		Cursor,a0		get next character
		moveq.l		#0,d0			from data.
		move.b		(a0)+,d0
		tst.b		(a0)
		bne.s		NoWrap
		lea		Message,a0

NoWrap		move.l		a0,Cursor

		cmp.b		#' ',d0			if a space correct it
		bne.s		NotSpace		since space after Z

		move.b		#'Z'+1,d0

NotSpace	sub.b		#'A',d0
		moveq.l		#0,d1

; There are 10 characters per line, so determine which line the character is
;on

		cmp.b		#10,d0
		blt.s		GotNum
		sub.b		#10,d0
		move.l		#33*(320/8),d1		next row
		cmp.b		#10,d0
		blt.s		GotNum
		sub.b		#10,d0
		add.l		d1,d1			next row

; 4 bytes per character so determine offset from start of line, add to line
;offset and then add result to start of Font data. This is the address of the
;font data.

GotNum		asl.w		#2,d0			num * 4
		add.l		d1,d0
		add.l		#Font,d0		a0->char data

; Character is always printed off right side of display 140 lines down.

		move.l		#bitplane,d1
		add.l		#141*(352/8)-4,d1
		moveq.l		#3,d2			bpl counter

; Blit the character

BWait1		btst		#14,DMACONR(a5)		wait for Blitter
		bne.s		BWait1

		move.l		d0,BLTAPTH(a5)		source = font
		move.l		d1,BLTDPTH(a5)		dest = screen
		move.w		#40-4,BLTAMOD(a5)	font modulo
		move.w		#44-4,BLTDMOD(a5)	screen modulo
		move.l		#-1,BLTAFWM(a5)		no masking
		move.w		#$09f0,BLTCON0(a5)	use AD, D=A
		move.w		#0,BLTCON1(a5)		normal mode
		move.w		#32<<6!2,BLTSIZE(a5)	32x32 pixels
		
		add.l		#(320/8)*99,d0		Font bpl size
		add.l		#(352/8)*256,d1		Screen bpl size
		dbra		d2,BWait1		for 4 planes
		
		rts

;		***************************
;		*	   Data		  *
;		***************************

VCount		dc.w		0

Cursor		dc.l		Message

Message		DC.B		'A FIRST SCROLL TEXT USING THE BLITTER      SCREEN IS SIXTEEN COLOUR AND THIS '
		DC.B		'TEXT IS BEING WRITTEN AND SCROLLED USING THE BLITTER FROM WITHIN A VBI '
		DC.B		'HANDLER                    NO SCROLLER IS COMPLETE WITHOUT A GREETS LIST '
		DC.B		'SO HERE GOES                   MIKE CROSS  DAVE EDWARDS  PAUL KENT  '
		DC.B		'STEVE MARSHALL  AFRO  PAUL CLASBY            TIME TO WRAP           ',0
		EVEN
		
;		***************************
;		*     CHIP Memory Data    *
;		***************************

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

;		Section		custom,data_C	**** Use this for Devpac ****
		
MyCopper	CMOVE		DIWSTRT,$2c81		PAL -- 256 lines
		CMOVE		DIWSTOP,$2cc1
		CMOVE		DDFSTRT,$0038		LoRes
		CMOVE		DDFSTOP,$00d0
		CMOVE		BPL1MOD,$0004		4 byte modulos
		CMOVE		BPL2MOD,$0004
		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

; The font used in this example contains 32x32x4 character. There are 10
;characters per line and the first character is 'A'. The screen containing
;the characters is 320x99x4.

Font		incbin		'font.bm'
		even

; The display used is 352x256x4.

bitplane	ds.b		(352/8)*256*4

; The colour data

	dc.w	$0000,$0FFF,$0FEC,$0ED9,$0EC7,$0EB5,$0DA2,$0D90
	dc.w	$0C80,$0B70,$0A60,$0950,$0840,$0730,$0620,$0510


		end

		
