 
* Blitter example #1 *

	section	prog,code
;	opt	o+,w-

Start:


	lea 	gfxname,a1
	move.l	4.w,a6
	jsr	-408(a6)		;open graphics.library
	move.l	d0,a1
	move.l	d0,gfxbase
	move.l	38(a1),oldcopper 	;store old copper address
	move.l	a1,a6			;gfx base
	jsr	-456(a6)		;own blitter!
	move.l	4.w,a6			;exec base
	jsr	-132(a6)		;no multitasking

	lea 	screen1,a0		;screen address
	move.l 	#(320/8)*256,d0		;=(screenwidth/8)*screenheight
	lea	bitplanes,a1		;copperlist bitplanes address
	bsr 	insertscreen		;insert screen

	lea 	sprites,a0		;sprite copperlist address
	bsr	clearsprites		;clear all sprites

	move.l 	#newcopper,$dff080 	;insert copper list
	move.w	d0,$dff088
	move.w	#0,$dff1fc

	**** Put other setup routines here ****

	move.w	#100*40,d0		;where to place bob
	bsr	drawblock		;draw a block to the screen

	move.w	#160*40+36,d0		;another one!
	bsr	drawblock



.waitlmb
	btst 	#0,$dff005		;is in pal area?
	beq 	.waitlmb		;no, then loop
.loopy	btst 	#0,$dff005		;is a pal area
	bne 	.loopy			;yes then loop

	bsr 	routine

	btst	#6,$bfe001		;left mouse button?	
	bne	.waitlmb 		;no


	**** Put other close stuff here. ****
	

	move.l 	oldcopper,$dff080 	;replace old copperlist address

	move.l 	gfxbase,a6		;gfxbase
	jsr	-462(a6)		;Disown blitter

	move.l	4.w,a6			;execbase
	move.l	gfxbase,a1		;gfxbase
	jsr	-414(a6)		;close graphics.library
	jsr	-138(a6)		;turn mulitasking back on

	moveq 	#0,d0			;no cli return code
	rts				;exit program to cli

routine: ** Called every 50 Hz (Pal) when rastor is at the top of screen **

	add.w 	#1,blank_clear		;add 1 to var
	cmp.w	#10,blank_clear		;is it 10?
	beq 	.clear			;yep - clear bob
	cmp.w	#20,blank_clear		;is it 20?
	bne	.done			;no, don't do anything
	move.w	#100*40,d0		;where to place bob
	bsr 	drawblock

	move.w	#160*40+36,d0		;another one!
	bsr	drawblock

	move.w 	#0,blank_clear		;clear var
	bra 	.done
.clear
	move.w	#100*40,d0		;where to place bob
	bsr 	clearblock
	move.w	#160*40,d0		;another one!
	bsr	clearblock

.done

	bsr	shiftblock

	move.w	#$050,$dff180		;show rastor time used (none used visible! (will be a black area)
	rts

blank_clear: dc.w 0

shiftblock:

	bsr blitwait			;wait for blitter to finish


	lea screen1+160*40,a0		;source
	lea screen1+160*40-2,a1		;dest

	move.l a0,$dff050		;blit A source
	move.l a1,$dff054		;blit D dest

	move.w #$ffff,$dff044		;blit A first mask
	move.w #$ffff,$dff046		;blit A last mask

	move.w #$0<<12+0<<1,$dff042	;Bsh value (0)+ Dest (0) for Bltcon1

	move.w #$F<<12+%1001<<8+%11110000,$dff040

					;Ash Value (0) +
					;change the Ash value from 0 to $f
					;to see how it changes the scroll
					;speed!!!
					
					;Channels used Value (A and D)
					;LF miniterm (A=D) ($f0)

	move.w #0,$dff064		;blit A mod (no modulo value)
	move.w #0,$dff066		;blit D mod (no modulo value)
	
	move.w #17*64+20,$dff058	;Blit size (starts the blitter)
					;height * 64 + 20 words width 
					;(20 words = 40 bytes width)

	bsr blitwait

	rts

drawblock:		;call d0 = place to plot bob

	bsr blitwait			;wait for blitter to finish

	lea bobgfx,a0
	lea screen1,a1
	lea (a1,d0.w),a1		;add d0 to a1

	move.l a0,$dff050		;blit A source
	move.l a1,$dff054		;blit D dest

	move.w #$ffff,$dff044		;blit A first mask
	move.w #$ffff,$dff046		;blit A last mask

	move.w #$0<<12+0<<1,$dff042	;Bsh value (0)+ Dest (0) for Bltcon1

	move.w #$0<<12+%1001<<8+%11110000,$dff040

					;Ash Value (0) +
					;change the Ash value from 0 to $f
					;to see how it shifts the data!!!
					
					;Channels used Value (A and D)
					;LF miniterm (A=D) ($f0)

	move.w #0,$dff064		;blit A mod (no modulo value)
	move.w #40-2,$dff066		;blit D mod (after the blit has been
					;done for the width, 38 bytes is
					;added to the width.
	
	move.w #17*64+1,$dff058		;Blit size (starts the blitter)
					;height * 64 + 1 word width 
					;(1 word = 2 bytes width)

	bsr blitwait

	rts

clearblock:
	bsr blitwait

	lea screen1,a1
	lea (a1,d0.w),a1

	move.l a1,$dff054		;blit D dest

	move.w #$0<<12+0<<1,$dff042	;Bsh value (0)+ Dest (0) for Bltcon1

	move.w #$0<<12+%0001<<8+%00000000,$dff040

					;Ash Value (0) +
					;Channels used Value (D)
					;LF miniterm (D) (no miniterm)

	move.w #40-2,$dff066		;blit D mod (after the blit has been
					;done for the width, 38 bytes is
					;added to the width.
	
	move.w #17*64+1,$dff058		;Blit size (starts the blitter)
					;height * 64 + 1 word width 
					;(1 word = 2 bytes width)
	bsr blitwait

	rts
blitwait:

	btst #6,$dff002
	bne blitwait			;has blitter finished?
	rts

insertscreen: ;call d0 = bitplane size, a0 = screen, a1 = cprlist bitplanes

	move.l	a0,d1			;bitplane address into d1
	move.w 	#6-1,d2			;number of bitplanes -1
	lea 	2(a1),a1		;goto higher bitplane cprlist
.place	swap 	d1			;swap words in longword
	move.w 	d1,(a1)			;insert high address in cprlist
	lea 	4(a1),a1		;goto lower bitplane cprlist
	swap 	d1			;swap words back to normal
	move.w 	d1,(a1)			;insert lower address in cprlist
	lea 	4(a1),a1		;goto higher bitplane cprlist
	add.l 	d0,d1			;add bitplane length to screen
	dbra 	d2,.place		;do all bitplanes
	rts

clearsprites: ;call a0 = cprlist sprites list

	move.l 	a0,a4			;copy sprite cpr address
	move.w	#0,d7			;clear counter.
.sprloop
	lea 	blanklongchip,a0	;empty sprite
	move.w 	d7,d0			;sprite number to insert
	move.l 	a4,a1			;copperlist sprite area
	bsr	insertsprite		;insert into copperlist
	add.w 	#1,d7			;next sprite
	cmp.w 	#8,d7			;compare with 8
	blo 	.sprloop		;if lower jump
	rts

insertsprite: ;call a0 = sprite, a1 = copperlist, d0 = sprite number
	
	add.w 	d0,d0			;sprite num *2
	add.w 	d0,d0			;sprite num *4
	add.w 	d0,d0			;sprite num *8
	lea	2(a1,d0.w),a1		;get correct cpr address
	move.l	a0,d0			;copy sprite to d0
	move.w d0,4(a1)			;copy lower address to cprlist
	swap d0				;swap longword
	move.w d0,(a1)			;copy higher address to cprlist
	rts


oldcopper:	dc.l 0
gfxbase:	dc.l 0
gfxname:	dc.b "graphics.library",0
	   even

	section copper,data_c

NEWCOPPER:
	dc.w	$100,%0001000000000000	;bplcon0 (screen control)
		     ;fedcba9876543210
	dc.w	$102,$0			;bplcon1 (hsr)
	dc.w	$104,$0			;bplcon2 (priority control)
	dc.w	$108,$0			;bpl1mod (modulo for odd planes)
	dc.w	$10a,$0			;bpl2mod (modulo for even planes)
	dc.w	$92,$38			;ddfstrt (screen start)
	dc.w	$94,$d0			;ddfstop (screen stop)
	dc.w	$8e,$2c81		;diwstrt (window start)
	dc.w	$90,$2cc1		;diwstop (window stop)
	
bitplanes:
	dc.w	$e0,0,$e2,0,$e4,0,$e6,0,$e8,0,$ea,0,$ec,0,$ee,0,$f0,0
	dc.w	$f2,0,$f4,0,$f6,0	;address of bitplanes
	
sprites:
	dc.w	$120,0,$122,0,$124,0,$126,0,$128,0,$12a,0,$12c,0,$12e,0
	dc.w	$130,0,$132,0,$134,0,$136,0,$138,0,$13a,0,$13c,0,$13e,0
					;address of sprites
	              ; RGB				
colour0: dc.w	$0180,$0000		;colour 0
colour1: dc.w	$0182,$0eff		;colour 1
	dc.w	$0184,$0def		;colour 2	
	dc.w	$0186,$0cde		;colour 3
	dc.w	$0188,$0bcd		;colour 4
	dc.w	$018a,$0abc		;colour 5
	dc.w	$018c,$09ab		;colour 6
	dc.w	$018e,$089a		;colour 7
	dc.w	$0190,$0789		;colour 8
	dc.w	$0192,$0678		;colour 9
	dc.w	$0194,$0567		;colour 10
	dc.w	$0196,$0456		;colour 11
	dc.w	$0198,$0345		;colour 12
	dc.w	$019a,$0234		;colour 13
	dc.w	$019c,$0123		;colour 14
	dc.w	$019e,$0012		;colour 15

	dc.w	$ffff,$fffe		;end of clist

blanklongchip:	dc.l	0		;a blank longword

bobgfx: 				;16 pixels * 17
					;the letter B
	DC.w %0001111111100000
	DC.w %0000011101110000
	DC.w %0000001100111000
	DC.w %0000001100111000
	DC.w %0000001100111000
	DC.w %0000001101110000
	DC.w %0000001111100000
	DC.w %0000001111000000
	DC.w %0000001111110000
	DC.w %0000001101111000
	DC.w %0000001100111100
	DC.w %0000001100011100
	DC.w %0000001100011100
	DC.w %0000001100011100
	DC.w %0000001100111100
	DC.w %0000001101111000
	DC.w %0000001111110000

screen1: dcb.b 256*40,0


