 
* Blitter example #1 *

	section	prog,code
;	opt	o+,w-

Start:


	lea 	gfxname,a1
	move.l	4.w,a6
	jsr	-408(a6)	
	move.l	d0,a1
	move.l	d0,gfxbase
	move.l	38(a1),oldcopper 
	move.l	a1,a6
	jsr	-456(a6)
	move.l	4.w,a6
	jsr	-132(a6)

	lea 	screen1,a0
	move.l 	#(320/8)*256,d0	
	lea	bitplanes,a1
	bsr 	insertscreen

	lea 	sprites,a0	
	bsr	clearsprites

	move.l 	#newcopper,$dff080 
	move.w	#0,$dff088
	move.w	#0,$dff1fc

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

.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 

	move.l 	gfxbase,a6
	jsr	-462(a6)

	move.l	4.w,a6	
	move.l	gfxbase,a1
	jsr	-414(a6)
	jsr	-138(a6)

	moveq 	#0,d0	
	rts	

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

	add.w #1,bobx
	cmp.w #300,bobx
	blo .okx			;change x pos
	move.w #0,bobx
.okx
	add.w #1,boby
	cmp.w #200,boby
	blo .oky			;change y pos
	move.w #0,boby
.oky
	
	bsr 	drawblock

	move.w	#$050,$dff180	
	rts

bobx: dc.w 0	;x pos in pixels
boby: dc.w 0	;y pos in lines

drawblock:		;call d0 = place to plot bob

	bsr blitwait			;wait for blitter to finish

	lea bobgfx,a0
	lea screen1,a1

	move.w bobx,d0
	move.w boby,d1
	mulu #40,d1			;get y pos

	move.w d0,d2
	lsr.w #4,d2			;divide by 16
	
	add.w d2,d1			;add it
	add.w d2,d1			;remember turn words to bytes

	lsl.w #4,d2			;multiply by 16

	sub.w d2,d0			;= pixels to shift right

	lea (a1,d1.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 #0,$dff046		;blit A last mask

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

	move.w #%1001<<8+%11110000,d1	;used (a,d) and miniterm (a=d)

	lsl.w #7,d0
	lsl.w #5,d0			;shift left 12 places
	or.w d0,d1			;insert Ash Values

	move.w d1,$dff040		;insert bltcon0


	move.w #-2,$dff064		;blit A mod (repeat once)
	move.w #40-4,$dff066		;blit D mod (after the blit has been
					;done for the width, 36 bytes is
					;added to the width.
	
	move.w #16*64+2,$dff058		;Blit size (starts the blitter)
					;height * 64 + 2 word width 
					;(2 word = 4 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	
	move.w 	#6-1,d2	
	lea 	2(a1),a1
.place	swap 	d1	
	move.w 	d1,(a1)	
	lea 	4(a1),a1
	swap 	d1	
	move.w 	d1,(a1)	
	lea 	4(a1),a1
	add.l 	d0,d1	
	dbra 	d2,.place
	rts

clearsprites: ;call a0 = cprlist sprites list

	move.l 	a0,a4
	move.w	#0,d7
.sprloop
	lea 	blanklongchip,a0
	move.w 	d7,d0
	move.l 	a4,a1
	bsr	insertsprite
	add.w 	#1,d7
	cmp.w 	#8,d7
	blo 	.sprloop
	rts

insertsprite: ;call a0 = sprite, a1 = copperlist, d0 = sprite number
	
	add.w 	d0,d0
	add.w 	d0,d0
	add.w 	d0,d0
	lea	2(a1,d0.w),a1
	move.l	a0,d0
	move.w d0,4(a1)
	swap d0	
	move.w d0,(a1)
	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 * 16
	dc.w 0
	dc.w %0000000100000000
	dc.w %0000001110000000
	dc.w %0000011111000000
	dc.w %0000111011100000
	dc.w %0001110001110000
	dc.w %0011110001111000
	dc.w %0111100000111100
	dc.w %0111111111111100
	dc.w %0011100000111000
	dc.w %0011100000111000
	dc.w %0011100000111000
	dc.w %0011100000111000
	dc.w %0111110001111100
	dc.w %0111111011111100
	dc.w 0
screen1: dcb.b 256*40,0

