;*******************************
;
;    Copper - Demonstration
;
;*******************************

org $30000
load $30000

DMACON          = $dff096

ExecBase        = 4
Permit          = -138
Forbid          = -132
OpenLibrary     = -408
CloseLibrary    = -414

s:	move.l 	ExecBase,a6
	lea  	GfxName,a1
	jsr  	OpenLibrary(a6)
	move.l 	d0,GfxBase

	move.l 	ExecBase,a6
	jsr  	Forbid(a6)


        lea.l 	$50000,a0	
	move.l 	#6645,d0	
clear:	clr.l 	(a0)+			
        dbf 	d0,clear	 
				

	lea.l	coltab(pc),a1	
	bsr 	copperinit      

	move.l 	GfxBase,a0
	add.l 	#$32,a0		

	move.w 	#$0080,DMACON  	
	move.l 	(a0),OldCopper  
	move.l 	#$55000,(a0)  	
	move.w 	#$80A0,DMACON	

	move.l 	#0,a2		
main:	btst 	#6,$bfe001      
	beq 	ende		

	lea.l	coltab(pc),a1	
	add.l	#1,a2		
	cmp.l	#32,a2		
	bne	cont		
	move.l  #0,a2		
cont:	adda.l	a2,a1		
	bsr	copperinit	
	move.l	#$ff,d3		
loop:	tst.l	(a6)		
	dbra	d3,loop		
	bra	main				

ende:	move.l 	GfxBase,a0
	add.l 	#$32,a0		

	move.w 	#$0080,DMACON  	
	move.l 	OldCopper,(a0)  
	move.w 	#$8180,DMACON  	

	move.l 	ExecBase,a6
	jsr  	Permit(a6)	

	move.l 	GfxBase,a1	
	jsr  	CloseLibrary(a6)
	rts			

copperinit:
	clr.l 	d1		
	lea.l 	$55000,a0	
				
	move.l 	#$00e00005,(a0)+
	move.l 	#$00e20000,(a0)+
	move.l 	#$01800f00,(a0)+
	move.l 	#80,d0		
loop1:	move.b 	d0,(a0)+	
	move.b 	#1,(a0)+	
	move.l 	#$fffe0180,(a0)+
	clr.l 	d6
	move.b 	(a1,d1),d6	
	eori 	#$0ff0,d6	
	move 	d6,(a0)+	
	addq 	#1,d1		
	cmpi 	#32,d1		
	bne 	loop2		
	clr.l 	d1		
loop2:	add.l 	#1,d0		
	cmp.l 	#255,d0		
	beq 	loop3		
	bra	loop1
loop3:	move.l	#$ff01fffe,(a0)+
	move.l	#$01800f00,(a0)+
	move.l 	#$fffffffe,(a0)+
	rts

even
coltab:	dc.b	$00,$10,$20,$30,$40,$50,$60,$70,$80,$90
	dc.b 	$a0,$b0,$c0,$d0,$e0,$f0,$f0,$e0,$d0
	dc.b 	$c0,$b0,$a0,$90,$80,$70,$60,$50,$40,$30
	dc.b	$20,$10,$00,$00,$10,$20,$30,$40,$50,$60
	dc.b	$70,$80,$90,$a0,$b0,$c0,$d0,$e0,$f0,$f0
	dc.b	$e0,$d0,$c0,$b0,$a0,$90,$80,$70,$60,$50
	dc.b    $40,$30,$20,$10,$00

GfxName:dc.b 	'graphics.library',0
even
GfxBase:blk.l 	1,0
OldCopper:
	blk.l 	1,0
