;	SECTION		chipmemory,data_c	

							;BY BLAINE EVANS
							;1 ERITH WAY
							;PONTYBODKIN
							;NR MOLD
							;CLWYD
							;CH7 4TR
							;TEL O352-771673
* Parallex  scrolling by splitting screen into 
* seperate smaller screens.Each section is 40*80 words*3
* and will scroll independant of each other

	opt	c-,d+

	move.l	4.w,a6			;FIND EXEC BASE
	lea	gfxlib(pc),a1		;LOAD GRAPHICS LIBRARY IN A1
	moveq	#$00,d0			;VERSION 0
	jsr	-552(a6)		;OPEN LIBRARY
	move.l	d0,_gfxbase		;STORE D0 (GFX ADDRESS )
	beq	nolib_exit		;ELSE EXIT
	bsr	plane_addresses		;BRANCH TO CALCULATE PLANE ADDRESSES
	bsr	initalise
	move.l	_gfxbase,a0		;LOAD ADDRESS OF GRAPHICS LIB IN A0
	move.l	50(a0),oldcop		;STORE CURRENT COPPER,ETC TO RETRIEVE LATER
S
	move.l	#newcop,50(a0)		;POINT TO OUR COPPERLIST

wait					;WAIT LOOP

	cmp.b	#255,$dff006		;VERTICAL BLANKING GAP 
	bne.s	wait			;
;	move.w	#$fff,$180(a6)
	bsr	scroll_1
	bsr	scroll_2
	bsr	scroll_3
	bsr	scroll_4
	bsr	scroll_5
;	move.w	#$000,$180(a6)
	Btst	#6,$bfe001		;QUIT LEFT MOUSE PRESSED
	bne.s	wait			;ELSE LOOP TO WAIT
ended					
	move.l	_gfxbase,a0		;LOAD GRAPHICS LIB ADDRESS IN A0
	move.l	oldcop,50(a0)		;RESTORE OLD COPPER TO RETURN TO EDITTER
dealloc	
	move.l	4.w,a6			;FIND EXEC BASE
nomem_exit	
	move.l	_gfxbase,a1		;LOAD GRAPHICS BASE IN A1
	jsr	-414(a6)		;CLOSE LIBRARY
nolib_exit
	rts				;RETURN TO EDITER
plane_addresses				;CALCULATE PLANE ADDRESSES
	move.l	#Screen_1,d0		;EACH PLANE =
	move.w	d0,Bpl0ptl		;40DOWN * 80WORDS ACROSS
	swap	d0			;3 PLANES
	move.w	d0,Bpl0pth
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl
	swap	d0
	move.w	d0,Bpl1pth
	swap	d0	
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl
	swap	d0
	move.w	d0,Bpl2pth
	swap	d0	 
					;AREA NO. 2
	move.l	#Screen_2,d0
	move.w	d0,Bpl0ptl2
	swap	d0
	move.w	d0,Bpl0pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl2
	swap	d0
	move.w	d0,Bpl1pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl2
	swap	d0
	move.w	d0,Bpl2pth2
	swap	d0
					;AREA NO. 3
	move.l	#Screen_3,d0
	move.w	d0,Bpl0ptl3
	swap	d0
	move.w	d0,Bpl0pth3
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl3
	swap	d0
	move.w	d0,Bpl1pth3
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl3
	swap	d0
	move.w	d0,Bpl2pth3
	swap	d0
					;AREA NO. 4
	move.l	#Screen_4,d0
	move.w	d0,Bpl0ptl4
	swap	d0
	move.w	d0,Bpl0pth4
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl4
	swap	d0
	move.w	d0,Bpl1pth4
	swap	d0	
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl4
	swap	d0
	move.w	d0,Bpl2pth4
	swap	d0	 
					;AREA NO. 5
	move.l	#Screen_5,d0
	move.w	d0,Bpl0ptl5
	swap	d0
	move.w	d0,Bpl0pth5
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl5
	swap	d0
	move.w	d0,Bpl1pth5
	swap	d0	
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl5
	swap	d0
	move.w	d0,Bpl2pth5
	swap	d0	 
	rts

Initalise
	move.l	#Screen_2,d0		;BECAUSE THIS SCROLLS LEFT-RIGHT
	add.l	#40,d0			;BIT-POINTERS NEED TO BE SET TO
	move.w	d0,Bpl0ptl2		;END SO SCROLL VALUE CAN BE SUBTRACTED
	swap	d0
	move.w	d0,Bpl0pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl2
	swap	d0
	move.w	d0,Bpl1pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl2
	swap	d0
	move.w	d0,Bpl2pth2
	swap	d0
********				;SAME FOR THIS AREA
	move.l	#Screen_4,d0		;LEFT TO RIGHT SCROLL
	add.l	#40,d0
	move.w	d0,Bpl0ptl4
	swap	d0
	move.w	d0,Bpl0pth4
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl4
	swap	d0
	move.w	d0,Bpl1pth4
	swap	d0	
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl4
	swap	d0
	move.w	d0,Bpl2pth4
	swap	d0	 
	move.w	#$Ff,scroll1		;SCROLL VALUES FOR COPPER
	move.w	#$00,scroll2
	move.w	#$ff,scroll3
	move.w	#$00,scroll4
	move.w	#$ff,scroll5
	clr.b	count_scroll1		;VALUES FOR FLAGS
	clr.b	count_scroll2
	clr.b	count_scroll3
	clr.b	count_scroll4
	clr.b	count_scroll5
	lea	$dff000,a6		;LOAD A6 WITH CUSTOM BASE ADDRESS
	rts


scroll_1
	move.w	scroll1,d0		;IS SCROLL VALUE=0
	cmp.w	#$00,d0			;
	beq	reset			;YES INC BP POINTERS
	subi.w	#$11,scroll1		;ELSE SUBTRACT 1
	rts
reset					
	lea	scroll1,a0		;REPLACE SCROLL VALUE TO 
	move.w	#$ff,(a0)		;15
	add.b	#1,count_scroll1	;
	cmp.b	#20,count_scroll1	;IS FLAG =20
	beq	swap_planes		;YES RESET BP POINTERS TO START
	addi.w	#2,Bpl0ptl		;ELSE ADD 2 TO BP POINTERS
	addi.w	#2,Bpl1ptl
	addi.w	#2,Bpl2ptl
	rts
swap_planes
	move.b	#0,count_scroll1	;CLEAR FLAG
	move.l	#Screen_1,d0		;RESET BP POINTERS TO START
	move.w	d0,Bpl0ptl
	swap	d0
	move.w	d0,Bpl0pth
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl
	swap	d0
	move.w	d0,Bpl1pth
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl
	swap	d0
	move.w	d0,Bpl2pth
	swap	d0
	rts

scroll_2				;SAME AS ABOVE ONLY LEFT TO RIGHT
	move.w	scroll2,d0
	cmp.w	#$ff,d0
	beq	reset_scroll2
	add.w	#$11,scroll2
	rts
reset_scroll2
	lea	scroll2,a0
	move.w	#$00,(a0)
	add.b	#1,count_scroll2
	cmp.b	#20,count_scroll2
	beq	swap_planes_scroll2
	subi.w	#2,Bpl0ptl2
	subi.w	#2,Bpl1ptl2
	subi.w	#2,Bpl2ptl2
	rts
swap_planes_scroll2
	move.b	#0,count_scroll2
	move.l	#Screen_2,d0
	add.l	#40,d0
	move.w	d0,Bpl0ptl2
	swap	d0
	move.w	d0,Bpl0pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl2
	swap	d0
	move.w	d0,Bpl1pth2
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl2
	swap	d0
	move.w	d0,Bpl2pth2
	swap	d0
	rts

scroll_3
	add.b	#1,V_count		;ONLY SCROLLED EVERY OTHER FRAME
	cmp.b	#2,V_count
	beq	Every_Other
	rts
Every_Other
	move.b	#0,V_count
	move.w	scroll3,d0
	cmp.w	#$00,d0
	beq	reset_scroll3
	sub.w	#$11,scroll3
	rts
reset_scroll3
	lea	scroll3,a0
	move.w	#$ff,(a0)
	add.b	#1,count_scroll3
	cmp.b	#20,count_scroll3
	beq	swap_planes_scroll3
	addi.w	#2,Bpl0ptl3
	addi.w	#2,Bpl1ptl3
	addi.w	#2,Bpl2ptl3
	rts
swap_planes_scroll3
	move.b	#0,count_scroll3
	move.l	#Screen_3,d0
	move.w	d0,Bpl0ptl3
	swap	d0
	move.w	d0,Bpl0pth3
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl3
	swap	d0
	move.w	d0,Bpl1pth3
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl3
	swap	d0
	move.w	d0,Bpl2pth3
	swap	d0
	rts


scroll_4
	add.b	#1,V_count2		;EVERY OTHER FRAME
	cmp.b	#2,V_count2
	beq	Every_Other2
	rts
Every_Other2
	move.b	#0,V_count2
	move.w	scroll4,d0
	cmp.w	#$ff,d0
	beq	reset_scroll4
	add.w	#$11,scroll4
	rts
reset_scroll4
	lea	scroll4,a0
	move.w	#$00,(a0)
	add.b	#1,count_scroll4
	cmp.b	#20,count_scroll4
	beq	swap_planes_scroll4
	subi.w	#2,Bpl0ptl4
	subi.w	#2,Bpl1ptl4
	subi.w	#2,Bpl2ptl4
	rts
swap_planes_scroll4
	move.b	#0,count_scroll4
	move.l	#Screen_4,d0
	add.l	#40,d0
	move.w	d0,Bpl0ptl4
	swap	d0
	move.w	d0,Bpl0pth4
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl4
	swap	d0
	move.w	d0,Bpl1pth4
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl4
	swap	d0
	move.w	d0,Bpl2pth4
	swap	d0
	rts
scroll_5
	add.b	#1,V_count3			;EVERY 3RD FRAME
	cmp.b	#3,V_count3			;WILL GET A BIT 
	beq	Every_Other3			;JERKY
	rts
Every_Other3
	move.b	#0,V_count3
	move.w	scroll5,d0
	cmp.w	#$00,d0
	beq	reset_scroll5
	sub.w	#$11,scroll5
	rts
reset_scroll5
	lea	scroll5,a0
	move.w	#$ff,(a0)
	add.b	#1,count_scroll5
	cmp.b	#20,count_scroll5
	beq	swap_planes_scroll5
	addi.w	#2,Bpl0ptl5
	addi.w	#2,Bpl1ptl5
	addi.w	#2,Bpl2ptl5
	rts
swap_planes_scroll5
	move.b	#0,count_scroll5
	move.l	#Screen_5,d0
	move.w	d0,Bpl0ptl5
	swap	d0
	move.w	d0,Bpl0pth5
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl1ptl5
	swap	d0
	move.w	d0,Bpl1pth5
	swap	d0
	add.l	#40*80,d0
	move.w	d0,Bpl2ptl5
	swap	d0
	move.w	d0,Bpl2pth5
	swap	d0
	rts


gfxlib	dc.b	"graphics.library",0	
	even
_gfxbase	dc.l	0			;LONG WORD TO STORE GFX ADDRESS
oldcop		dc.l	0			;OLD COPPERLIST ADDRESS
count_scroll1		dc.b	0		;FLAGS
count_scroll2		dc.b	0
count_scroll3		dc.b	0
count_scroll4		dc.b	0
count_scroll5		dc.b	0
V_count			dc.b	0
V_count2		dc.b	0
V_count3		dc.b	0
	even
	SECTION		chipmemory,data_c	


newcop
	dc.w	$0100,%0011001000000000		;3 PLANES
	dc.w	$0102
scroll1	dc.w	$0000				;SCROLL VALUE
	dc.w	$0104,%0000000000000000		;PRIORITY 
	dc.w	$0108,$0024,$010a,$0024		;MODULAS,EXTRA WORDS FOR SCROLLING
	dc.w	$0092,$0028,$0094,$00d0		;200*40 SCREEN
	dc.w	$008e,$3781,$0090,$fec1		;CENTRED TO LEAVE GAP AT TOP 
						;AND BOTTOM MORE EVEN
planes
	dc.w	$00e0
Bpl0pth	dc.w	$0000
	dc.w	$00e2
Bpl0ptl	dc.w	$0000		
	dc.w	$00e4
Bpl1pth	dc.w	$0000
	dc.w	$00e6
Bpl1ptl	dc.w	$0000
	dc.w	$00e8
Bpl2pth	dc.w	$0000
	dc.w	$00ea
Bpl2ptl	dc.w	$0000
	dc.w	$00ec
Bpl3pth	dc.w	$0000
	dc.w	$00ee
Bpl3ptl	dc.w	$0000	
	dc.w	$00f0
Bpl4pth	dc.w	$0000
	dc.w	$00f2
Bpl4ptl	dc.w	$0000
	dc.w	$00f4
Bpl5pth	dc.w	$0000
	dc.w	$00f6
Bpl5ptl	dc.w	$0000

sprites						;SPRITES
	dc.w	$0120,$0000,$0122,$0000	
	dc.w	$0124,$0000,$0126,$0000
	dc.w	$0128,$0000,$012a,$0000
	dc.w	$012c,$0000,$012e,$0000
	dc.w	$0130,$0000,$0132,$0000
	dc.w	$0134,$0000,$0136,$0000
	dc.w	$0138,$0000,$013a,$0000
	dc.w	$013c,$0000,$013e,$0000

	dc.w	$0180,$0000,$0182,$0fff		;COLORS PLAY 1
	dc.w	$0184,$0bbe,$0186,$088d
	dc.w	$0188,$055c,$018a,$022b
	dc.w	$018c,$000a,$018e,$0777

	dc.w	$0190,$0000,$0192,$0fff		;COLORS PLAY 2
	dc.w	$0194,$0d00,$0196,$070f
	dc.w	$0198,$00f2,$019a,$00ff
	dc.w	$019c,$0ff0,$019e,$0fa0

	dc.w	$01a0,$0d50,$01a2,$05C0	;SPRITE COLORS
	dc.w	$01a4,$0ff0,$01a6,$0dd4
	dc.w	$01a8,$0444,$01aa,$0880
	dc.w	$01ac,$006f,$01ae,$04ff
	dc.w	$01b0,$0DDD,$01b2,$00d6
	dc.w	$01b4,$0460,$01b6,$0D06
	dc.w	$01b8,$0f48,$01ba,$0ff4
	dc.w	$01bc,$000f,$01be,$0f0f
****************************************  COPPER 2  *********************
copper_2
	dc.w	$5f01,$ff00
	dc.w	$0100,%0011001000000000		
	dc.w	$0102
scroll2	dc.w	$0000				;SCROLLING
	dc.w	$0104,%0000000000000000		;PRIORITY 

	dc.w	$00e0
Bpl0pth2	dc.w	$0000
	dc.w	$00e2
Bpl0ptl2	dc.w	$0000		
	dc.w	$00e4
Bpl1pth2	dc.w	$0000
	dc.w	$00e6
Bpl1ptl2	dc.w	$0000
	dc.w	$00e8
Bpl2pth2	dc.w	$0000
	dc.w	$00ea
Bpl2ptl2	dc.w	$0000
****************************************  COPPER 3  *********************
copper_3
	dc.w	$8701,$ff00
	dc.w	$0100,%0011001000000000		
	dc.w	$0102
scroll3	dc.w	$0000				;SCROLLING
	dc.w	$0104,%0000000000000000		;PRIORITY for sprites 0,1

	dc.w	$00e0
Bpl0pth3	dc.w	$0000
	dc.w	$00e2
Bpl0ptl3	dc.w	$0000		
	dc.w	$00e4
Bpl1pth3	dc.w	$0000
	dc.w	$00e6
Bpl1ptl3	dc.w	$0000
	dc.w	$00e8
Bpl2pth3	dc.w	$0000
	dc.w	$00ea
Bpl2ptl3	dc.w	$0000
****************************************  COPPER 4  *********************
copper_4
	dc.w	$af01,$ff00
	dc.w	$0100,%0011001000000000		
	dc.w	$0102
scroll4	dc.w	$0000			;	SCROLLING
	dc.w	$0104,%0000000000000000		;PRIORITY for sprites 0,1

	dc.w	$00e0
Bpl0pth4	dc.w	$0000
	dc.w	$00e2
Bpl0ptl4	dc.w	$0000		
	dc.w	$00e4
Bpl1pth4	dc.w	$0000
	dc.w	$00e6
Bpl1ptl4	dc.w	$0000
	dc.w	$00e8
Bpl2pth4	dc.w	$0000
	dc.w	$00ea
Bpl2ptl4	dc.w	$0000
****************************************  COPPER 5  *********************
copper_5
	dc.w	$D701,$ff00
	dc.w	$0100,%0011001000000000		
	dc.w	$0102
scroll5	dc.w	$0000			;	SCROLLING
	dc.w	$0104,%0000000000000000		;PRIORITY for sprites 0,1

	dc.w	$00e0
Bpl0pth5	dc.w	$0000
	dc.w	$00e2
Bpl0ptl5	dc.w	$0000		
	dc.w	$00e4
Bpl1pth5	dc.w	$0000
	dc.w	$00e6
Bpl1ptl5	dc.w	$0000
	dc.w	$00e8
Bpl2pth5	dc.w	$0000
	dc.w	$00ea
Bpl2ptl5	dc.w	$0000

	dc.w	$ffff,$fffe			;END OF COPPERLIST
Screen_1		incbin	source:bitmaps/Blaine.raw
Screen_2		incbin	source:bitmaps/Blaine.raw
Screen_3		incbin	source:bitmaps/Blaine.raw
Screen_4		incbin	source:bitmaps/Blaine.raw
Screen_5		incbin	source:bitmaps/Blaine.raw
