;
;	Copperlist Example 5.
;
;	Written for OZAmiga by Chris Leathley.
;
;	just a few example of what can be done with the copper and a list
;	of colours.  First bit does a cycle horizontally and second cycles
;	colours down the screen.
;



;
;	Branch offsets into the Amiga's rom kernal librarys (exec)
;
Forbid		=	-132		; turn off Multitasking
Permit		=	-138		; turn it back on again
CloseLibrary	=	-414		; open a library (from ram or disk)
OpenLibrary	=	-552		; close an opened library


; --------------------------------------------------------------------------

; a68k code
	SECTION	code,CODE,CHIP			; make sure in chip memory

; devpac code
;	SECTION	code,CODE_C			; make sure in chip memory

; --------------------------------------------------------------------------


;	program starts here
;
START:		clr.l	$0			; clear address 0

		move.l	$4,a6			; turn off multitasking
		jsr	Forbid(a6)

.wait_vb	cmp.b	#$FF,$00DFF006		; wait for vb to change
		bne.s	.wait_vb

		move.l	#FIFTHCOPPER,$00DFF080	; insert new copperlist
		move.w	#$8280,$00DFF096	; use new control bits


;	wait for user to press the left mouse button and then exit program
;
MAIN_LOOP:	cmp.b	#$FF,$00DFF006		; wait for vertical blank
		bne.s	MAIN_LOOP

		btst	#$07,$00BFE001		; don't scroll if joystick
		beq.s	MAIN_LOOP		; button is being pressed

		move.w	#$F00,$00DFF180
		bsr	SCROLL_LINE		; cycle colours in single line

		move.w	#$0F0,$00DFF180
		bsr	SCROLL_BLOCK

		move.w	#$000,$00DFF180

		btst	#$06,$00BFE001		; left mouse button ?
		bne.s	MAIN_LOOP		; no? do it all again


;	program finished, exit back to dos
;
EXIT:		move.l	$4,a6			; exec pointer
		lea	GFX_NAME,a1		; library name
		moveq	#0,d0			; library version
		jsr	OpenLibrary(a6)		; open graphics library

		move.l	d0,a1			; d0 has pointer to library
		move.l	$0026(a1),$00DFF080	; restore original copperlist

		jsr	CloseLibrary(a6)	; close graphics library

		jsr	Permit(a6)		; turn back on multitasking
		moveq	#0,d0			; no errors
		rts				; return of amiga dos



; --------------------------------------------------------------------------



;
;	scrolls (cycles) the colours from the colour tables along the single
;	line in the copperlist
;
SCROLL_LINE:	move.l	CTABLE_PNT,a1		; get pointer to our position
						; in the colour table

		add.l	#2,a1			; goto next entry (colour)

		cmp.w	#-1,(a1)		; is our address pointing to
						; then end of the table
		bne	.sl.not.end		; (represented by -1)
		lea	COLOUR_TABLE,a1		; if so then get start of table

.sl.not.end	move.l	a1,CTABLE_PNT		; save new address in pointer

		lea	LINE_COPPER+2,a0	; copperlist to modify
		move.w	#56,d7			; 56 colours to do (see below)

.sl.set.colour	move.w	(a1)+,(a0)		; get colour from table and
						; put into the copperlist
						; the address of the colour
						; table is now incremented to
						; point to the next entry

		add.l	#4,a0			; next colour data in copperlist

		cmp.w	#-1,(a1)		; end of colour table?
		bne	.sl.next.colour
		lea	COLOUR_TABLE,a1		; if so then reset address

.sl.next.colour	sub.w	#1,d7			; 1 less colour to do
		bne	.sl.set.colour		; any more left? if so, do again
		rts



CTABLE_PNT	dc.l	COLOUR_TABLE		; pointer to start of colour
						; table



;
;	this routine uses the current colour table pointer and copies the
;	colours into the vertical block in the copperlist
;
SCROLL_BLOCK:	lea	SOLID_COPPER+6,a0	; copperlist to modify
		move.l	CTABLE_PNT,a1		; get pointer to our position
		move.w	#32,d7			; 32 colours to do (see below)

.sb.set.colour	move.w	(a1)+,(a0)
		add.l	#8,a0			; next colour data in copperlist
		cmp.w	#-1,(a1)		; end of colour table?
		bne	.sb.next.colour
		lea	COLOUR_TABLE,a1		; if so then reset address
.sb.next.colour	sub.w	#1,d7			; 1 less colour to do
		bne	.sb.set.colour		; any more left? if so, do again
		rts



; --------------------------------------------------------------------------



;	graphics library name
;
GFX_NAME:	dc.b	'graphics.library',0
		EVEN



;
;	colours to be used in our copperlist example
;
;	all the colours in the rainbow (oh, how nice)
;	(I bet you won't find ultra violet (he he))
;
COLOUR_TABLE:	dc.w	$0F0F,$0F0E,$0F0D,$0F0C	; pink to red
		dc.w	$0F0B,$0F0A,$0F09,$0F08
		dc.w	$0F07,$0F06,$0F05,$0F04
		dc.w	$0F03,$0F02,$0F01
		dc.w	$0F00,$0F10,$0F20,$0F30	; red to yellow
		dc.w	$0F40,$0F50,$0F60,$0F70
		dc.w	$0F80,$0F90,$0FA0,$0FB0
		dc.w	$0FC0,$0FD0,$0FE0
		dc.w	$0FF0,$0EF0,$0DF0,$0CF0	; yellow to green
		dc.w	$0BF0,$0AF0,$09F0,$08F0
		dc.w	$07F0,$06F0,$05F0,$04F0
		dc.w	$03F0,$02F0,$01F0
		dc.w	$00F0,$00F1,$00F2,$00F3	; green to cyan
		dc.w	$00F4,$00F5,$00F6,$00F7
		dc.w	$00F8,$00F9,$00FA,$00FB
		dc.w	$00FC,$00FD,$00FE
		dc.w	$00FF,$00EF,$00DF,$00CF	; cyan to blue
		dc.w	$00BF,$00AF,$009F,$008F
		dc.w	$007F,$006F,$005F,$004F
		dc.w	$003F,$002F,$001F
		dc.w	$000F,$010F,$020F,$040F	; blue to pink
		dc.w	$040F,$050F,$060F,$080F
		dc.w	$080F,$090F,$0A0F,$0C0F
		dc.w	$0C0F,$0D0F,$0E0F

		dc.w	-1			; we use -1 to tell us it's
						; then end of the colour table



;
;	our fifth copperlist program
;
;	examples of colour cycling
;
FIFTHCOPPER:	dc.w	$0180,$0000		; screen starts off black

		dc.w	$0100,$0000		; turn off bitplane display

		dc.w	$8009,$FFFE

;	4 colours per line * by 14 source lines = 56 entrys

LINE_COPPER:	dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000
		dc.w	$0180,$0000,$0180,$0000,$0180,$0000,$0180,$0000

		dc.w	$8109,$FFFE,$0180,$0000	; screen back to black


;	solid section (block) to also be cycled.
;
;	32 colours to process
;
SOLID_COPPER:	dc.w	$A009,$FFFE,$0180,$0000
		dc.w	$A109,$FFFE,$0180,$0000
		dc.w	$A209,$FFFE,$0180,$0000
		dc.w	$A309,$FFFE,$0180,$0000
		dc.w	$A409,$FFFE,$0180,$0000
		dc.w	$A509,$FFFE,$0180,$0000
		dc.w	$A609,$FFFE,$0180,$0000
		dc.w	$A709,$FFFE,$0180,$0000
		dc.w	$A809,$FFFE,$0180,$0000
		dc.w	$A909,$FFFE,$0180,$0000
		dc.w	$AA09,$FFFE,$0180,$0000
		dc.w	$AB09,$FFFE,$0180,$0000
		dc.w	$AC09,$FFFE,$0180,$0000
		dc.w	$AD09,$FFFE,$0180,$0000
		dc.w	$AE09,$FFFE,$0180,$0000
		dc.w	$AF09,$FFFE,$0180,$0000
		dc.w	$B009,$FFFE,$0180,$0000
		dc.w	$B109,$FFFE,$0180,$0000
		dc.w	$B209,$FFFE,$0180,$0000
		dc.w	$B309,$FFFE,$0180,$0000
		dc.w	$B409,$FFFE,$0180,$0000
		dc.w	$B509,$FFFE,$0180,$0000
		dc.w	$B609,$FFFE,$0180,$0000
		dc.w	$B709,$FFFE,$0180,$0000
		dc.w	$B809,$FFFE,$0180,$0000
		dc.w	$B909,$FFFE,$0180,$0000
		dc.w	$BA09,$FFFE,$0180,$0000
		dc.w	$BB09,$FFFE,$0180,$0000
		dc.w	$BC09,$FFFE,$0180,$0000
		dc.w	$BD09,$FFFE,$0180,$0000
		dc.w	$BE09,$FFFE,$0180,$0000
		dc.w	$BF09,$FFFE,$0180,$0000

		dc.w	$C009,$FFFF,$0180,$0000	; screen back to black

		dc.w	$FFFF,$FFFE		; end of copper list
						; start vertical blank


; --------------------------------------------------------------------------



	END					; end of program

