
;	Bitplane Example 3.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Turning on a 1 bitplane picture and changing colours down the screen
;	is a slightly darkening gradient



;
;	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)


;
;	set up bitplane address into copper list program before copper is
;	turned on
;
		move.l	#PICTURE,d0		; move ADDRESS of picture	
						; into d0
		move.w	d0,BP1LO+2		; store bottom 16 bits into
						; copperlist.  $00E2,0
						; we use +2 to skip the first
						; word (ie $00E2) and put the
						; data in the 0 word
		swap	d0			; swap upper 16 bits with
						; lower 16 bits in d0.
		move.w	d0,BP1HI+2		; store upper 16 bits


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

		move.l	#THIRDCOPPER,$00DFF080	; insert new copperlist
		move.w	#$8380,$00DFF096	; use new control bits
					; (turn on copper & bitplane dma)


;	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

		bsr	SCROLL_RAINBOW		; scroll rainbow colours
						; up the screen

		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_RAINBOW:	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

;
;	this routine uses the current colour table pointer and copies the
;	colours into the vertical block in the copperlist
;
;	example of data we are working on in the copper list
;
;	RAINBOW_COPPER:	dc.w	$2C09,$FFFE,$0182,$0000
;
;			OFFSET:	  00 ,  02 ,  04 ,  06 ,  08 (next entry)
;

		move.w	#128,d7			; 128 colours to do (see below)

		lea	RAINBOW_COPPER,a0	; address of rainbow copperlist
						; data

.sb.set.colour	cmp.w	#$FFDF,(a0)		; is it our special vertical
						; blank skip?
		bne	.not.special		; if not equal then skip add
		add.l	#4,a0			; skip over copperlist entry
						; (4 bytes)

.not.special	move.w	(a1)+,6(a0)		; put into 0 data field
		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


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


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



;	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 second bitplane copperlist program
;
THIRDCOPPER:	dc.w	$0180,$0000		; screen starts off black

		dc.w	$0120,0,$0122,0		; don't worry about this just
		dc.w	$0124,0,$0126,0		; yet as all it does is set
		dc.w	$0128,0,$012A,0		; all sprite positions to zero
		dc.w	$012C,0,$012E,0		; so no wondering sprites
		dc.w	$0130,0,$0132,0		; appear on the screen
		dc.w	$0134,0,$0136,0
		dc.w	$0138,0,$013A,0
		dc.w	$013C,0,$013E,0

BP1HI		dc.w	$00E0,0			; bitplane 1 address pointers
BP1LO		dc.w	$00E2,0

		dc.w	$100,$1200		; turn on 1 bitplane
		dc.w	$102,0			; hardware scroll to be zero
		dc.w	$104,0			; bitplane - sprite priority
		dc.w	$08E,$2C81		; window start (top left)
		dc.w	$090,$2CC1		; window stop (bottom right)
						; (STANDARD PAL DISPLAY VALUES)

		dc.w	$092,$38		; bitplane DMA start
		dc.w	$094,$d0		; bitplane DMA stop
		dc.w	$108,0			; odd modulo
		dc.w	$10A,0			; even modulo

RAINBOW_COPPER:	dc.w	$2C09,$FFFE,$0182,0
		dc.w	$2E09,$FFFE,$0182,0
		dc.w	$3009,$FFFE,$0182,0
		dc.w	$3209,$FFFE,$0182,0
		dc.w	$3409,$FFFE,$0182,0
		dc.w	$3609,$FFFE,$0182,0
		dc.w	$3809,$FFFE,$0182,0
		dc.w	$3A09,$FFFE,$0182,0

		dc.w	$3C09,$FFFE,$0182,0
		dc.w	$3E09,$FFFE,$0182,0
		dc.w	$4009,$FFFE,$0182,0
		dc.w	$4209,$FFFE,$0182,0
		dc.w	$4409,$FFFE,$0182,0
		dc.w	$4609,$FFFE,$0182,0
		dc.w	$4809,$FFFE,$0182,0
		dc.w	$4A09,$FFFE,$0182,0

		dc.w	$4C09,$FFFE,$0182,0
		dc.w	$4E09,$FFFE,$0182,0
		dc.w	$5009,$FFFE,$0182,0
		dc.w	$5209,$FFFE,$0182,0
		dc.w	$5409,$FFFE,$0182,0
		dc.w	$5609,$FFFE,$0182,0
		dc.w	$5809,$FFFE,$0182,0
		dc.w	$5A09,$FFFE,$0182,0

		dc.w	$5C09,$FFFE,$0182,0
		dc.w	$5E09,$FFFE,$0182,0
		dc.w	$6009,$FFFE,$0182,0
		dc.w	$6209,$FFFE,$0182,0
		dc.w	$6409,$FFFE,$0182,0
		dc.w	$6609,$FFFE,$0182,0
		dc.w	$6809,$FFFE,$0182,0
		dc.w	$6A09,$FFFE,$0182,0

		dc.w	$6C09,$FFFE,$0182,0
		dc.w	$6E09,$FFFE,$0182,0
		dc.w	$7009,$FFFE,$0182,0
		dc.w	$7209,$FFFE,$0182,0
		dc.w	$7409,$FFFE,$0182,0
		dc.w	$7609,$FFFE,$0182,0
		dc.w	$7809,$FFFE,$0182,0
		dc.w	$7A09,$FFFE,$0182,0

		dc.w	$7C09,$FFFE,$0182,0
		dc.w	$7E09,$FFFE,$0182,0
		dc.w	$8009,$FFFE,$0182,0
		dc.w	$8209,$FFFE,$0182,0
		dc.w	$8409,$FFFE,$0182,0
		dc.w	$8609,$FFFE,$0182,0
		dc.w	$8809,$FFFE,$0182,0
		dc.w	$8A09,$FFFE,$0182,0

		dc.w	$8C09,$FFFE,$0182,0
		dc.w	$8E09,$FFFE,$0182,0
		dc.w	$9009,$FFFE,$0182,0
		dc.w	$9209,$FFFE,$0182,0
		dc.w	$9409,$FFFE,$0182,0
		dc.w	$9609,$FFFE,$0182,0
		dc.w	$9809,$FFFE,$0182,0
		dc.w	$9A09,$FFFE,$0182,0

		dc.w	$9C09,$FFFE,$0182,0
		dc.w	$9E09,$FFFE,$0182,0
		dc.w	$A009,$FFFE,$0182,0
		dc.w	$A209,$FFFE,$0182,0
		dc.w	$A409,$FFFE,$0182,0
		dc.w	$A609,$FFFE,$0182,0
		dc.w	$A809,$FFFE,$0182,0
		dc.w	$AA09,$FFFE,$0182,0

		dc.w	$AC09,$FFFE,$0182,0
		dc.w	$AE09,$FFFE,$0182,0
		dc.w	$B009,$FFFE,$0182,0
		dc.w	$B209,$FFFE,$0182,0
		dc.w	$B409,$FFFE,$0182,0
		dc.w	$B609,$FFFE,$0182,0
		dc.w	$B809,$FFFE,$0182,0
		dc.w	$BA09,$FFFE,$0182,0

		dc.w	$BC09,$FFFE,$0182,0
		dc.w	$BE09,$FFFE,$0182,0
		dc.w	$C009,$FFFE,$0182,0
		dc.w	$C209,$FFFE,$0182,0
		dc.w	$C409,$FFFE,$0182,0
		dc.w	$C609,$FFFE,$0182,0
		dc.w	$C809,$FFFE,$0182,0
		dc.w	$CA09,$FFFE,$0182,0

		dc.w	$CC09,$FFFE,$0182,0
		dc.w	$CE09,$FFFE,$0182,0
		dc.w	$D009,$FFFE,$0182,0
		dc.w	$D209,$FFFE,$0182,0
		dc.w	$D409,$FFFE,$0182,0
		dc.w	$D609,$FFFE,$0182,0
		dc.w	$D809,$FFFE,$0182,0
		dc.w	$DA09,$FFFE,$0182,0

		dc.w	$DC09,$FFFE,$0182,0
		dc.w	$DE09,$FFFE,$0182,0
		dc.w	$E009,$FFFE,$0182,0
		dc.w	$E209,$FFFE,$0182,0
		dc.w	$E409,$FFFE,$0182,0
		dc.w	$E609,$FFFE,$0182,0
		dc.w	$E809,$FFFE,$0182,0
		dc.w	$EA09,$FFFE,$0182,0

		dc.w	$EC09,$FFFE,$0182,0
		dc.w	$EE09,$FFFE,$0182,0
		dc.w	$F009,$FFFE,$0182,0
		dc.w	$F209,$FFFE,$0182,0
		dc.w	$F409,$FFFE,$0182,0
		dc.w	$F609,$FFFE,$0182,0
		dc.w	$F809,$FFFE,$0182,0
		dc.w	$FA09,$FFFE,$0182,0

		dc.w	$FC09,$FFFE,$0182,0
		dc.w	$FE09,$FFFE,$0182,0

		dc.w	$FFDF,$FFFE		; skip past line 255

		dc.w	$0009,$FFFE,$0182,0
		dc.w	$0209,$FFFE,$0182,0
		dc.w	$0409,$FFFE,$0182,0
		dc.w	$0609,$FFFE,$0182,0
		dc.w	$0809,$FFFE,$0182,0
		dc.w	$0A09,$FFFE,$0182,0

		dc.w	$0C09,$FFFE,$0182,0
		dc.w	$0E09,$FFFE,$0182,0
		dc.w	$1009,$FFFE,$0182,0
		dc.w	$1209,$FFFE,$0182,0
		dc.w	$1409,$FFFE,$0182,0
		dc.w	$1609,$FFFE,$0182,0
		dc.w	$1809,$FFFE,$0182,0
		dc.w	$1A09,$FFFE,$0182,0

		dc.w	$1C09,$FFFE,$0182,0
		dc.w	$1E09,$FFFE,$0182,0
		dc.w	$2009,$FFFE,$0182,0
		dc.w	$2209,$FFFE,$0182,0
		dc.w	$2409,$FFFE,$0182,0
		dc.w	$2609,$FFFE,$0182,0
		dc.w	$2809,$FFFE,$0182,0
		dc.w	$2A09,$FFFE,$0182,0

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

						; start vertical blank


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


;
;	include raw picture data into assembly code
;
PICTURE:	INCBIN	1bp.oz.raw


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



	END					; end of program

