**
** This little program sets-up 3 planes of copper bars and then
** scrolls them all to give a parallax copper effect (like the one
** in the XCOPY III demo -however theres looks way better!)
**
** Coded by Raistlin
** Gfx by ??????????

	opt c-

	include	source:include/hardware.i		; Harware equates

	section	Scrolling,code		; Use public memory

	lea	$dff000,a5		; Address of DMA in a5

	move.l	4,a6			; A6=Exec base
	lea	gfxname,a1		; address of lib name in a1
	moveq.l	#0,d0			; Any version
	jsr	-552(a6)		; Open the lib
	move.l	d0,gfxbase		; Save base address of gfx lib
	beq	error			; Quit if error found
	
	jsr	-132(a6)		; Forbid

	
****************************************************************************
;		Load the bitplane pointers
****************************************************************************
	move.l	#Screen,d0		; D0=Address of the screen

	move.w	d0,bpl1+2		; Load the bpl pointers
	swap	d0
	move.w	d0,bph1+2

****************************************************************************
;	Set-Up The Parallax Copper, Wait Values
****************************************************************************
SetUp_Paralax
	lea	ParaCop,a0		; A0=Address to build value
	move.w	#$2001,d1		; D1=Initial wait value
	move.w	#$fffe,d2		; D2=Mask value
	move.w	#$0180,d3		; D3=Colour register
	move.w	#$0000,d4		; D4=Colour value
	move.w	#222,d0			; Number of waits-1
.Loopy
	move.w	d1,(a0)+		; Insert wait value
	move.w	d2,(a0)+		; Insert mask value
	move.w	d3,(a0)+		; Insert register value
	move.w	d4,(a0)+		; Insert colour value
	add.w	#$0100,d1		; Increment wait value
	dbra	d0,.Loopy		; Keep building.


****************************************************************************
; 		Set-up the DMA
****************************************************************************
WaitDMA
.Wait1	btst	#0,vposr(a5)
	bne	.Wait1
.Wait2	cmpi.b	#55,vhposr(a5)
	bne	.Wait2
	move.w	#$20,dmacon(a5)		; Disable sprites
	move.l	#Copperlist,cop1lch(a5)	; Load my copper list
	move.w	#$0,copjmp1(a5)		; Run my copper list




****************************************************************************
;		The Main Branching Routine
****************************************************************************
MouseWait
	cmpi.b	#200,vhposr(a5)
	bne	MouseWait

	bsr	Movebars

	btst	#6,$bfe001		; Test LMB
	bne	MouseWait



****************************************************************************
;		Clean-up the system ready to leave
****************************************************************************
Clean_Up
	move.w	#$8e30,dmacon(a5)	; Enable sprites
	move.l	gfxbase,a1
	move.l	38(a1),cop1lch(a5)	; System copper list
	move.w	#$0,copjmp1(a5)		; Run the system copper
	move.l	4,a6			; A6=Exec base
	move.l	gfxbase,a1		; address of gfx lib in a1
	jsr	-408(a6)		; Close the lib
	jsr	-138(a6)		; Permit

error	rts				; End the program


*****************************************************************************
;		 The Parallax Copper Background 
*****************************************************************************
; This section scrolls the 3 different
; levels of copper bars
****************************************
* First alter the positions of level 1 *
****************************************
MoveBars
	subq.b	#1,CDelay1		; Decrement delay
	beq	.NoDelay1
	move.l	Level1P,a0		; A0=Current pointer
	bra	Delay1
.NoDelay1
	move.b	#1,CDelay1		; Restart delay
	move.l	Level1P,a0		; A0=Start address to read cols from
	addq.w	#2,a0			; Increment pointer by 3 lines
	cmpi.w	#$ffff,(a0)		; End of list?
	bne	.Nope1
	lea	Level1,a0		; Reset pointer
.Nope1	move.l	a0,Level1P		; Save pointer
Delay1	lea	ParaCop+6,a1		; A1=Start address to put cols
	move.l	#222,d0			; D0=Number of cols to transfer-1
.Loopy1
	move.w	(a0)+,(a1)		; Transfer the colours
	cmpi.w	#$ffff,(a0)		; End of list 1?
	bne	.NotEnd1
	lea	Level1,a0		; If end re-load pointer
.NotEnd1
	addq.w	#8,a1			; Point to next address to load colour
	dbra	d0,.Loopy1

***********************************
* Next alter positions of level 2 *
***********************************
Bar2
	subq.b	#1,CDelay2		; Decrement delay
	beq	.NoDelay2
	move.l	Level2P,a0		; A0=Current pointer
	bra	Delay2
.NoDelay2
	move.b	#2,CDelay2		; Restart delay
	move.l	Level2P,a0		; A0=Start address to read cols from
	addq.w	#2,a0			; Increment pointer by 2 lines
	cmpi.w	#$ffff,(a0)		; End of list?
	bne	.Nope2
	lea	Level2,a0		; Re-load pointer
.Nope2	move.l	a0,Level2P		; Save pointer
Delay2	lea	ParaCop+6,a1		; A1=Start address to put cols
	move.l	#222,d0			; D0=Number of cols to transfer-1
.Loopy2
	cmpi.w	#$0000,(a0)+		; Gap?
	beq	.Gap			; If so dont insert this value
	move.w	(a0),(a1)		; Insert new colour
.Gap	cmpi.w	#$ffff,(a0)		; End of col list
	bne	.NotEnd2
	lea	Level2,a0		; If end re-load pointer
.NotEnd2
	addq.w	#8,a1			;Point to next address to load colour
	dbra	d0,.Loopy2

**************************************
* Finally alter positions of level 3 *
**************************************
Bar3	
	subq.b	#1,CDelay3		; Decrement delay
	beq	.NoDelay3
	move.l	Level3P,a0		; A0=Current pointer
	bra	Delay3
.NoDelay3
	move.b	#3,CDelay3		; Restart delay
	move.l	Level3P,a0		; A0=Start address to read cols from
	addq.w	#2,a0			; Increment pointer by 1 line
	cmpi.w	#$ffff,(a0)		; End of list?
	bne	.Nope3
	lea	Level3,a0		; Reload pointer
.Nope3	move.l	a0,Level3P		; Save pointer
Delay3	lea	ParaCop+6,a1		; A1=Start address to put cols
	move.l	#222,d0			; D0=Number of cols to transfer-1

.Loopy3
	cmpi.w	#$0000,(a0)+		; Gap?
	beq	.Gap			; If so don't insert this value
	move.w	(a0),(a1)		; Insert new colour
.Gap	cmpi.w	#$ffff,(a0)		; End of col list
	bne	.NotEnd3
	lea	Level3,a0		; If end re-load pointer
.NotEnd3
	addq.w	#8,a1			;Point to next address to load colour
	dbra	d0,.Loopy3
	rts				




****************************************************************************
;			THE COPPER LIST
****************************************************************************
	section	copperlist,code_c	; Chip memory
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 fetch stop
	dc.w	bplcon0,%0001001000000000
	dc.w	bplcon1,$0
	dc.w	bpl1mod,-40,bpl2mod,-40


bph1	dc.w	bpl1pth,$0		; The bitplane pointers
bpl1	dc.w	bpl1ptl,$0

ParaCop	ds.w	892

	dc.w	$ffff,$fffe



****************************************************************************
;			Variables
****************************************************************************
gfxname	dc.b	'graphics.library',0	; Name of lib to load
	even
gfxbase	dc.l	0			; Space for libs address

screen	ds.b	40

**********************************
* The Parallax Copper Bar Values *
**********************************
Level1P	dc.l	Level1			; Pointer
CDelay1	dc.b	2			; Delay counter
	even
Level1
	dc.w	$111,$800,$a00,$c00,$e00,$f00,$e00,$c00		; Bar 1
	dc.w	$a00,$800,$111
	dc.w	$111,$008,$00a,$00c,$00e,$00f,$00e,$00c		; Bar 2
	dc.w	$00a,$008,$111
	dc.w	$111,$080,$0a0,$0c0,$0e0,$0f0,$0e0,$0c0		; Bar 3
	dc.w	$0a0,$080,$111
	dc.w	$111,$808,$a0a,$c0c,$e0e,$f0f,$e0e,$c0c		; Bar 4
	dc.w	$a0a,$808,$111
	dc.w	$111,$880,$aa0,$cc0,$ee0,$ff0,$ee0,$cc0		; Bar 5
	dc.w	$aa0,$880,$111
	dc.w	$111,$088,$0aa,$0cc,$0ee,$0ff,$0ee,$0cc		; Bar 6
	dc.w	$0aa,$088,$111
	dc.w	$ffff						; End of bars

Level2P	dc.l	Level2			; Pointer
CDelay2	dc.b	3
	even
Level2
	dc.w	$111,$800,$900,$a00,$b00,$c00,$d00,$e00		; Bar 1
	dc.w	$d00,$c00,$b00,$a00,$900,$800,$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$111,$808,$909,$a0a,$b0b,$c0c,$d0d,$e0e		; Bar 2
	dc.w	$d0d,$c0c,$b0b,$a0a,$909,$808,$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$111,$080,$090,$0a0,$0b0,$0c0,$0d0,$0e0		; Bar 3
	dc.w	$0d0,$0c0,$0b0,$0a0,$090,$080,$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$111,$008,$009,$00a,$00b,$00c,$00d,$00e		; Bar 4
	dc.w	$00d,$00c,$00b,$00a,$009,$008,$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
CEnd2	dc.w	$ffff						; End of bars


Level3P	dc.l	Level3			; Pointer
CDelay3	dc.b	4
	even
Level3
	dc.w	$111,$400,$500,$600,$700,$800,$900,$a00		; Bar 1
	dc.w	$b00,$c00,$d00,$e00,$f00,$e00,$d00,$c00
	dc.w	$b00,$a00,$900,$800,$700,$600,$500,$400
	dc.w	$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap
	dc.w	$111,$040,$050,$060,$070,$080,$090,$0a0		; Bar 2
	dc.w	$0b0,$0c0,$0d0,$0e0,$0f0,$0e0,$0d0,$0c0
	dc.w	$0b0,$0a0,$090,$080,$070,$060,$050,$040
	dc.w	$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap
	dc.w	$111,$004,$005,$006,$007,$008,$009,$00a		; Bar 3
	dc.w	$00b,$00c,$00d,$00e,$00f,$00e,$00d,$00c
	dc.w	$00b,$00a,$009,$008,$007,$006,$005,$004
	dc.w	$111
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
	dc.w	$000,$000,$000,$000,$000,$000,$000,$000		; Gap	
CEnd3	dc.w	$ffff						; End of bars


