**
** Example of blitting using interleaved bob and screen to obtain
** faster speeds during graphical manipulation with the block image
** transferer (thats the watchamicallit chip to you!)
**
** Code by the MUFC deity.........Raistlin
**
** Grafix by the lufc brain problem supporter......Master Beat

	opt c-

	include	source:include/hardware.i		; Hardware offset
	section	hardware,code		; Public memory

	lea	$dff000,a5		; Hardware offset

	move.l	4,a6			; Exec base
	lea	gfxname,a1
	moveq.l	#0,d0			; Any version
	jsr	-552(a6)		; Open library
	move.l	d0,gfxbase		; Save gfx base
	beq	error
	
	jsr	-132(a6)		; Permit

*****************************************************************************
;			Set-Up The Bitplane Pointers
*****************************************************************************
	move.l	#Screen,d0		; Address of screen
	move.w	d0,bpl1+2		; Load bitplane pointers
	swap	d0
	move.w	d0,bph1+2
	swap	d0
	add.l	#40,d0			; Get to next bitplane
	move.w	d0,bpl2+2
	swap	d0
	move.w	d0,bph2+2
	swap	d0
	add.l	#40,d0
	move.w	d0,bpl3+2
	swap	d0
	move.w	d0,bph3+2
	swap	d0
	add.l	#40,d0
	move.w	d0,bpl4+2
	swap	d0
	move.w	d0,bph4+2
	swap	d0
	add.l	#40,d0
	move.w	d0,bpl5+2
	swap	d0
	move.w	d0,bph5+2

*****************************************************************************
;			  Set-Up DMA
*****************************************************************************
DMA
.Wait1	btst	#0,vposr(a5)		; Wait VBL
	bne	.Wait1
.Wait2	cmpi.b	#55,vhposr(a5)
	bne	.Wait2
	move.w	#$20,dmacon(a5)		; Disable sprites
	move.l	#Copperlist,cop1lch(a5)	; Insert new copper list
	move.w	#$0,copjmp1(a5)		; Run that copper list

*****************************************************************************
;			Main Branching Routine
*****************************************************************************
WaitVBL
	cmpi.b	#255,vhposr(a5)		; Wait VBL
	bne	WaitVBL
	bsr	Blitter			; Do the blit
	btst	#6,$bfe001		; Mouse Wait
	bne	WaitVBL
	bra	CleanUp			; Clean-up system


*****************************************************************************
;			       Clean Up
*****************************************************************************
CleanUp
	move.w	#$83e0,dmacon(a5)	; Enable sprite dma
	move.l	gfxbase,a1		; A1=Address of gfx lib
	move.l	38(a1),cop1lch(a5)	; Load sys copper list
	move.w	#$0,copjmp1(a5)		; Run sys copper list
	move.l	4,a6			; Exec base
	move.l	gfxbase,a1
	jsr	-408(a6)		; Close library
	jsr	-138(a6)		; Permit
	moveq.l	#0,d0			; Keep CLI happy
error	rts				; Bye Bye


*****************************************************************************
;		     Do The Interleaved Blit
*****************************************************************************
Blitter	btst	#14,dmaconr(a5)
	bne	Blitter
	move.l	#Bob,bltapth(a5)	; Source=Bob
	move.l	#Screen+4010,bltdpth(a5); Dest=Screen
	move.w	#0,bltamod(a5)		; No A modulo
	move.w	#12,bltdmod(a5)		; 40-28(length of bob)	
	move.w	#$ffff,bltafwm(a5)	; No mask
	move.w	#$ffff,bltalwm(a5)	; No mask
	move.w	#%100111110000,bltcon0(a5) ; A-D blit
	move.w	#$0,bltcon1(a5)		; Wipe
	move.w	#(74*5*64)+14,bltsize(a5); Height*number of bitplanes
	rts				; Normal width (74Height 224Width)


*****************************************************************************
;			Copper List
*****************************************************************************
	section	copper,data_c		; Chip data
Copperlist
	dc.w	diwstrt,$2c81		; window start	
	dc.w	diwstop,$2cc1		; window stop
	dc.w	ddfstrt,$38		; data fetch start
	dc.w	ddfstop,$d0		; data fect stop
	dc.w	bplcon0,%0101001000000000 ; 5 bitplanes
	dc.w	bplcon1,$0		; Clear scroll register
	dc.w	bplcon2,$0		; Clear priority register
	dc.w	bpl1mod,40*4		; length of line*No. of bpls-1
	dc.w	bpl2mod,40*4		; Ditto
; Bitplane pointers
bph1	dc.w	bpl1pth,$0	
bpl1	dc.w	bpl1ptl,$0
bph2	dc.w	bpl2pth,$0
bpl2	dc.w	bpl2ptl,$0
bph3	dc.w	bpl3pth,$0
bpl3	dc.w	bpl3ptl,$0
bph4	dc.w	bpl4pth,$0
bpl4	dc.w	bpl4ptl,$0
bph5	dc.w	bpl5pth,$0
bpl5	dc.w	bpl5ptl,$0
; Colours
	dc.w	$180,$000,$182,$ff0,$184,$ed0,$186,$db0
	dc.w	$188,$ca0,$18a,$f46,$18c,$f34,$18e,$e34
	dc.w	$190,$d34,$192,$c23,$194,$aaf,$196,$99f
	dc.w	$198,$88f,$19a,$77f,$19c,$56f,$19e,$44f
	dc.w	$1a0,$620,$1a2,$f00,$1a4,$d00,$1a6,$b00
	dc.w	$1a8,$800,$1aa,$600,$1ac,$400,$1ae,$200
	dc.w	$1b0,$0f0,$1b2,$0d0,$1b4,$0c0,$1b6,$0a0
	dc.w	$1b8,$090,$1ba,$070,$1bc,$060,$1be,$040

	dc.w	$ffff,$fffe		; Wait for lufc to win something!


*****************************************************************************
;			     Variables
*****************************************************************************
	section	variables,data		; Public
gfxname	dc.b	'graphics.library',0
	even
gfxbase	dc.l	0			; Space for gfx base address



*************************
* Chip Data & Variables *
*************************
	section	gfxstuff,data_c
screen	dcb.b	256*40*5,0		; Screen data
Bob	incbin	'source:bitmaps1/TDM_Logo2.gfx'	; Bob data
