;
;	Copperlist Example 4.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Rotate the colours in a copperlist section around on it's self
;



;
;	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	#FOURTHCOPPER,$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

;
;	to test how long a routine is taking, programmers generally change
;	the colour of the screen when first the program is run
;
		move.w	#$0F00,$00DFF180

		bsr	ROTATE_BAR

;
;	then change it to an other and the coloured lines on the screen
;	tell exactly what is being used.  in this case about 1 1/2 copper
;	lines.
;
		move.w	#$0000,$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



;
;	This little routine will cycle the silver bar around on it's self
;
;	There are 15 colours in that bar, but we must only move 14 colours
;	up one position.  The first colour is saved before it is over
;	written then it's put in the last position when all the moves have
;	been done.
;
;	SILVER_BAR	dc.w	$A009,$FFFE,$0180,$0222
;				0, 1, 2, 3, 4, 5, 6, 7, 8 (byte count)
;
ROTATE_BAR:	move.w	#15-1,d7		; 15 lines to move
		lea	SILVER_BAR+6,a0		; skip to colour value
		move.w	(a0),d0			; save first colour

.rotate.loop	move.w	8(a0),(a0)		; move next colour over
						; current

		add.w	#8,a0			; next colour in copperlist
						; there are 4 words or
						; 8 bytes per copperlist line

		sub.w	#1,d7			; one less line to do
		bne.s	.rotate.loop		; remaining lines = 0 ?
						; if not then keep on going

		move.w	d0,(a0)			; put saved colour on last
		rts



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



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


;
;	our fourth copperlist program
;
;	puts 3 coloured bars onto the screen
;
FOURTHCOPPER:	dc.w	$0180,$0000		; screen starts off black

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

		dc.w	$8009,$FFFE,$0180,$0531	; gold bar
		dc.w	$8109,$FFFE,$0180,$0641
		dc.w	$8209,$FFFE,$0180,$0851
		dc.w	$8309,$FFFE,$0180,$0971
		dc.w	$8409,$FFFE,$0180,$0B80
		dc.w	$8509,$FFFE,$0180,$0CA0
		dc.w	$8609,$FFFE,$0180,$0EC0
		dc.w	$8709,$FFFE,$0180,$0FE0
		dc.w	$8809,$FFFE,$0180,$0EC0
		dc.w	$8909,$FFFE,$0180,$0CA0
		dc.w	$8A09,$FFFE,$0180,$0B80
		dc.w	$8B09,$FFFE,$0180,$0971
		dc.w	$8C09,$FFFE,$0180,$0851
		dc.w	$8D09,$FFFE,$0180,$0641
		dc.w	$8E09,$FFFE,$0180,$0531
		dc.w	$8F09,$FFFE,$0180,$0000

SILVER_BAR	dc.w	$A009,$FFFE,$0180,$0222 ; silver bar
		dc.w	$A109,$FFFE,$0180,$0444
		dc.w	$A209,$FFFE,$0180,$0666
		dc.w	$A309,$FFFE,$0180,$0888
		dc.w	$A409,$FFFE,$0180,$0AAA
		dc.w	$A509,$FFFE,$0180,$0CCC
		dc.w	$A609,$FFFE,$0180,$0EEE
		dc.w	$A709,$FFFE,$0180,$0FFF
		dc.w	$A809,$FFFE,$0180,$0EEE
		dc.w	$A909,$FFFE,$0180,$0CCC
		dc.w	$AA09,$FFFE,$0180,$0AAA
		dc.w	$AB09,$FFFE,$0180,$0888
		dc.w	$AC09,$FFFE,$0180,$0666
		dc.w	$AD09,$FFFE,$0180,$0444
		dc.w	$AE09,$FFFE,$0180,$0222
		dc.w	$AF09,$FFFE,$0180,$0000

		dc.w	$C009,$FFFE,$0180,$0531	; gold bar
		dc.w	$C109,$FFFE,$0180,$0641
		dc.w	$C209,$FFFE,$0180,$0851
		dc.w	$C309,$FFFE,$0180,$0971
		dc.w	$C409,$FFFE,$0180,$0B80
		dc.w	$C509,$FFFE,$0180,$0CA0
		dc.w	$C609,$FFFE,$0180,$0EC0
		dc.w	$C709,$FFFE,$0180,$0FE0
		dc.w	$C809,$FFFE,$0180,$0EC0
		dc.w	$C909,$FFFE,$0180,$0CA0
		dc.w	$CA09,$FFFE,$0180,$0B80
		dc.w	$CB09,$FFFE,$0180,$0971
		dc.w	$CC09,$FFFE,$0180,$0851
		dc.w	$CD09,$FFFE,$0180,$0641
		dc.w	$CE09,$FFFE,$0180,$0531
		dc.w	$CF09,$FFFE,$0180,$0000

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


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


	END					; end of program



