;
;	Copperlist Example 2.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Example of copper timing and how it can be used to split colours
;	horizontaly
;



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



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



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


;
;	our second copperlist program
;
;	examples of spliting up the copper on the horizontal axis
;
SECONDCOPPER:	dc.w	$0180,$0000		; screen starts off black

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

;
;	aswell as waiting for vertical positions, the copper can wait for
;	horizontal positions as well.  $8F is the middle of the screen.
;	The horizontail copper wait register must be a odd number.
;	If you wait for $8E or $90 then the copper will become corrupt and
;	will most likely crash the machine.
;

		dc.w	$9009,$FFFE,$0180,$0F00,$908F,$FFFE,$0180,$00F0
;
; wait for line $90 and change colour to red, then wait for the middle of the
; same line and change to colour to green.
;
		dc.w	$9109,$FFFE,$0180,$0F00,$918F,$FFFE,$0180,$00F0
		dc.w	$9209,$FFFE,$0180,$0F00,$928F,$FFFE,$0180,$00F0
		dc.w	$9309,$FFFE,$0180,$0F00,$938F,$FFFE,$0180,$00F0
		dc.w	$9409,$FFFE,$0180,$0F00,$948F,$FFFE,$0180,$00F0
		dc.w	$9509,$FFFE,$0180,$0F00,$958F,$FFFE,$0180,$00F0
		dc.w	$9609,$FFFE,$0180,$0F00,$968F,$FFFE,$0180,$00F0
		dc.w	$9709,$FFFE,$0180,$0F00,$978F,$FFFE,$0180,$00F0
		dc.w	$9809,$FFFE,$0180,$0F00,$988F,$FFFE,$0180,$00F0
		dc.w	$9909,$FFFE,$0180,$0F00,$998F,$FFFE,$0180,$00F0
		dc.w	$9A09,$FFFE,$0180,$0F00,$9A8F,$FFFE,$0180,$00F0
		dc.w	$9B09,$FFFE,$0180,$0F00,$9B8F,$FFFE,$0180,$00F0
		dc.w	$9C09,$FFFE,$0180,$0F00,$9C8F,$FFFE,$0180,$00F0
		dc.w	$9D09,$FFFE,$0180,$0F00,$9D8F,$FFFE,$0180,$00F0
		dc.w	$9E09,$FFFE,$0180,$0F00,$9E8F,$FFFE,$0180,$00F0

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

;
;	This section creates and white and blue jaggie line.  The copper has
;	a "waiting" resolution of about 4 lo-res pixels.
;

		dc.w	$B009,$FFFE,$0180,$0FFF,$B081,$FFFE,$0180,$000F
		dc.w	$B109,$FFFE,$0180,$0FFF,$B183,$FFFE,$0180,$000F
		dc.w	$B209,$FFFE,$0180,$0FFF,$B285,$FFFE,$0180,$000F
		dc.w	$B309,$FFFE,$0180,$0FFF,$B387,$FFFE,$0180,$000F
		dc.w	$B409,$FFFE,$0180,$0FFF,$B489,$FFFE,$0180,$000F
		dc.w	$B509,$FFFE,$0180,$0FFF,$B58B,$FFFE,$0180,$000F
		dc.w	$B609,$FFFE,$0180,$0FFF,$B68D,$FFFE,$0180,$000F
		dc.w	$B709,$FFFE,$0180,$0FFF,$B78F,$FFFE,$0180,$000F
		dc.w	$B809,$FFFE,$0180,$0FFF,$B891,$FFFE,$0180,$000F
		dc.w	$B909,$FFFE,$0180,$0FFF,$B993,$FFFE,$0180,$000F
		dc.w	$BA09,$FFFE,$0180,$0FFF,$BA95,$FFFE,$0180,$000F
		dc.w	$BB09,$FFFE,$0180,$0FFF,$BB97,$FFFE,$0180,$000F
		dc.w	$BC09,$FFFE,$0180,$0FFF,$BC99,$FFFE,$0180,$000F
		dc.w	$BD09,$FFFE,$0180,$0FFF,$BD9B,$FFFE,$0180,$000F
		dc.w	$BE09,$FFFE,$0180,$0FFF,$BE9D,$FFFE,$0180,$000F

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


;
;	this section creates the red and white dotted line across the screen.
;	what it does is wait for the start of the line and then changes the
;	background colour as fast as it can.
;
;	after running this program you will notice that the space between the
;	colours is about 8 pixels.  Each copperlist entry takes 2 machine
;	cycles to execute.  It is not possible to modify the complete 32
;	colour registers in the "horizontal blank" (the area between the end
;	of a line and the start of the next line).
;
;	most games constantly modify the colour palette as it goes down the
;	screen.  A more current example is LIONHEART.  the back parallax scroll
;	only uses 3 colours.  The copperlist changes the colours for the
;	clouds and the mountains.  The end effect is that the screen looks like
;	it has a lot of colours on it.
;
		dc.w	$D009,$FFFE
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00
		dc.w	$0180,$0FFF,$0180,$0F00,$0180,$0FFF,$0180,$0F00

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

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


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


	END					; end of program



