***********************************************************
* This shows how to manipulate the colors in the copper to
* produce a neat "scrolling" effect.
* 1992 Epsilon
***********************************************************

WaitVblank	MACRO
.\@1		move.l	4(a5),d0
		andi.l	#$3ff00,d0
		cmpi.l	#$0f300,d0
		bne.b	.\@1
.\@2		move.l	4(a5),d0
		andi.l	#$3ff00,d0
		cmpi.l	#$0f400,d0
		bne.b	.\@2
		ENDM

***********************************************************

		bsr.w	TakeSystem
MouseWait:	WaitVblank

		bsr.b	Line1Alter
		bsr.b	Line2Alter

		btst.b	#6,$bfe001	; wait for left mouse button
		bne.s	MouseWait

		bsr.w	RestoreSystem
		rts

***********************************************************	

Line1Alter:	move.l	#60,d0		; 60, 4 pixel location per raster
		lea	line+6,a0	; first position in copper

top:		cmpi.w	#$0fff,(a0)	; is color white?
		bne.s	.1
		clr.w	(a0)+		; set to black
		bra.s	.2
.1:		add.w	#$0111,(a0)+	; next gray shade
.2:		addq.l	#2,a0		; next position
		dbra	d0,top		; loop
		rts

***********************************************************	

Line2Alter:	addq.l	#1,line_count
		cmpi.l	#$20,line_count	
		bne.s	move_line
		neg.b	direction
		move.l	#0,line_count
	
move_line:	move.b	direction,d3
		add.b	d3,line2		; move line
		add.b	d3,endl2		; move bottom of line or bonus
					;   garbage will result
		move.l	#60,d0			; there are 60, 4 pixel locations per line
		lea	line2+6,a0		; address of color
		move.l	table_ptr,a1		; address of new color in table
top2:		cmpi.w	#$ffff,(a1)		; end of color table?
		bne.s	looper			; no!
		lea	table,a1		; set it to start of table
looper:		move.w	(a1)+,(a0)+		; move color and get next one
		addq.l	#2,a0			; next location in copper list
		dbra	d0,top2			; loop

		move.l	table_ptr,a1		; it the start color the last
		cmp.l	#$ffff,(a1)		;   color in the list?
		beq.s	it_trash		; yes
		addq.l	#2,table_ptr		; get next color
		bra.s	it_ok
it_trash:	move.l	#table,table_ptr	; set ptr. to start of list
it_ok:		rts

***********************************************************	
* If any of this confuses you totally, read the following:
*	Amiga System Programmer's Guide, pp. 91-92, 94-96
*
*	Amiga Hardware Referance Manual, pp. 213, 217, 274, 325-326
***********************************************************

TakeSystem:	move.l	#$dff000,a5		; Custom chip base
		move.l	#Copper,$80(a5)		; install copper
		rts				; Done

***********************************************************

RestoreSystem:	move.l	#$dff000,a5		; Custom chip base

		movea.l	4.w,a6			; ExecBase
		lea	GraphicsName,a1		; "graphics.library"
		jsr	-$198(a6)		; OldOpenLibrary()
		move.l	d0,a1			; Copy ptr to GfxBase
		move.l	$26(a1),$80(a5)		; Install old system copperlist
		jsr	-$19e(a6)		; CloseLibrary()
		rts				; Done

***********************************************************	

		section fish,data

table:		dc.w	$0000,$0001,$0003,$0005,$0007,$0009,$000b,$000d,$000f
		dc.w	$000f,$000d,$000b,$0009,$0007,$0005,$0003,$0001,$0000
		dc.w	$0000,$0100,$0300,$0500,$0700,$0900,$0b00,$0d00,$0f00
		dc.w	$0f00,$0d00,$0b00,$0900,$0700,$0500,$0300,$0100,$0000
		dc.w	$0000,$0010,$0030,$0050,$0070,$0090,$00b0,$00d0,$00f0
		dc.w	$00f0,$00d0,$00b0,$0090,$0070,$0050,$0030,$0010,$0000
		dc.w	$0000,$0310,$0510,$0920,$0b30,$0e30,$0e50,$0f70,$0fb0
		dc.w	$0fb0,$0f70,$0e50,$0e30,$0b30,$0920,$0510,$0310,$0000
		dc.w	$ffff

table_ptr:	dc.l	table
line_count:	dc.l	0

direction:	dc.b	1
GraphicsName:	dc.b	'graphics.library',0
		EVEN

***********************************************************	

		section	squid,data_c
		

Copper:		dc.l	$01000000,$01020000,$01040000,$01080000,$010a0000
		dc.l	$008e2c81,$0090f4c1,$00920038,$009400d0

line:		dc.w	$900f,$fffe
		dc.l	$01800000,$01800fff,$01800eee,$01800ddd,$01800ccc
		dc.l	$01800bbb,$01800aaa,$01800999,$01800888,$01800777
		dc.l	$01800666,$01800555,$01800444,$01800333,$01800222
		dc.l	$01800111,$01800000,$01800111,$01800222,$01800333
		dc.l	$01800444,$01800555,$01800666,$01800777,$01800888
		dc.l	$01800999,$01800aaa,$01800bbb,$01800ccc,$01800ddd
		dc.l	$01800eee,$01800fff,$01800eee,$01800ddd,$01800ccc
		dc.l	$01800bbb,$01800aaa,$01800999,$01800888,$01800777
		dc.l	$01800666,$01800555,$01800444,$01800333,$01800222
		dc.l	$01800111,$01800000,$01800111,$01800222,$01800333
		dc.l	$01800444,$01800555,$01800666,$01800777,$01800888
		dc.l	$01800999,$01800aaa,$01800bbb,$01800ccc,$01800ddd
		dc.l	$01800eee,$01800fff,$01800eee,$01800ddd,$910ffffe
		dc.l	$01800000
line2:		dc.l	$950ffffe
		rept	64
		dc.l	$01800000
		endr

endl2:		dc.l	$960ffffe,$01800000,-2,-2
