;
;	Bitplane Example 4.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Turn on a 4 bitplane picture
;



;
;
;
FLOYDSIZE	=	112*40		; size of our picture.
					; it is 112 lines high and 320 pixels
					; across which devived by 8 = 40



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

		swap	d0			; swap halves again (return to
						; normal)

		add.l	#FLOYDSIZE,d0		; add size of a pitplane

		move.w	d0,BP2LO+2		; same again for bitplane 2
		swap	d0
		move.w	d0,BP2HI+2

		swap	d0
		add.l	#FLOYDSIZE,d0

		move.w	d0,BP3LO+2		; bitplane 3
		swap	d0
		move.w	d0,BP3HI+2
		
		swap	d0
		add.l	#FLOYDSIZE,d0

		move.w	d0,BP4LO+2		; bitplane 4
		swap	d0
		move.w	d0,BP4HI+2



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

		move.l	#FOURTHCOPPER,$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

		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



;
;	turn on a four bitplane picture and set up colours for that picture
;
FOURTHCOPPER:	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
BP2HI		dc.w	$00E4,0			; bitplane 2 address pointers
BP2LO		dc.w	$00E6,0
BP3HI		dc.w	$00E8,0			; bitplane 3 address pointers
BP3LO		dc.w	$00EA,0
BP4HI		dc.w	$00EC,0			; bitplane 4 address pointers
BP4LO		dc.w	$00EE,0

		dc.w	$100,$4200		; turn on 4 bitplanes
		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,$9CC1		; window stop (bottom right)
						; (STANDARD PAL DISPLAY VALUES)

; since of picture is only 112 lines high we have to calculate a new window
; stop position.  112 = $70 hex so $2C + $70 = 9C.

; **************************************************************************
; *** as an exersise try placing the picture in the middle of the screen ***
; **************************************************************************


		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

;
;	set up colour registers 0 to 15.
;
		dc.w	$0180,$0000		; set up colours for picture
		dc.w	$0182,$0FFF		; grey scale
		dc.w	$0184,$0CCC
		dc.w	$0186,$0888
		dc.w	$0188,$0555
		dc.w	$018A,$0000		; ** NOT USED **
		dc.w	$018C,$0000		; ** NOT USED **
		dc.w	$018E,$0000		; ** NOT USED **
		dc.w	$0190,$0A0F		; rainbow colours
		dc.w	$0192,$048F
		dc.w	$0194,$00B0
		dc.w	$0196,$0FF0
		dc.w	$0198,$0E70
		dc.w	$019A,$0C00
		dc.w	$019C,$0000		; ** NOT USED **
		dc.w	$019E,$0000		; ** NOT USED ** 

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


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


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


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



	END					; end of program

