;
;	Bitplane Example 6.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Put both of our bitmap picture on the screen at the same time.
;
;	You will only see part of picture 1 (1 bitplane) so we will move
;	it up and down
;



;
;
;
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	#PICTURE1,d0		; ozamiga picture

		move.w	d0,BP1LO1+2		; bitplane 1
		swap	d0
		move.w	d0,BP1HI1+2


		move.l	#PICTURE2,d0		; pink floyd picture

		move.w	d0,BP1LO2+2		; bitplane 1
		swap	d0
		move.w	d0,BP1HI2+2

		swap	d0
		add.l	#FLOYDSIZE,d0
		move.w	d0,BP2LO2+2		; bitplane 2
		swap	d0
		move.w	d0,BP2HI2+2

		swap	d0
		add.l	#FLOYDSIZE,d0
		move.w	d0,BP3LO2+2		; bitplane 3
		swap	d0
		move.w	d0,BP3HI2+2
		
		swap	d0
		add.l	#FLOYDSIZE,d0
		move.w	d0,BP4LO2+2		; bitplane 4
		swap	d0
		move.w	d0,BP4HI2+2



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

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

;	put in our little delay otherwise the screen will move 3 times
;	as it can be run 3 times while the raster line is still on
;	postion $FF

		move.w	#256,d0			; count down from 256 to 0
.delay		sub.w	#1,d0
		bne	.delay

		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



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



MOVE_BITPLANE:
		move.l	#PICTURE1,d0		; ozamiga picture
		move.w	DISPLAY_LINE,d1
		mulu	#40,d1
		add.l	d1,d0

		move.w	d0,BP1LO1+2		; bitplane 1
		swap	d0
		move.w	d0,BP1HI1+2

;
;	move display position up and down
;
		tst.w	MOVE_DIRECTION
		bne	.down

.up		add.w	#1,DISPLAY_LINE
		cmp.w	#113,DISPLAY_LINE
		bne	.return
		not.w	MOVE_DIRECTION
		rts

.down		sub.w	#1,DISPLAY_LINE
		tst.w	DISPLAY_LINE
		bne	.return
		not.w	MOVE_DIRECTION
.return		rts



DISPLAY_LINE	dc.w	0			; start of display line 0
MOVE_DIRECTION	dc.w	0			; start off up


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



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



;
;	put the 1 bitplane picture on the top half of the screen and the
;	4 bitplane picture at the bottom
;
SIXTHCOPPER:	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

BP1HI1		dc.w	$00E0,0			; bitplane 1 address pointers
BP1LO1		dc.w	$00E2,0

		dc.w	$100,$1200		; 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,$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

		dc.w	$0182,$00FF		; top pictures colour is cyan

;
;	now display picture 2 (pinkfloyd picture)
;

		dc.w	$BB09,$FFFE		; wait for line $2B
		dc.w	$0100,$0200		; turn off bitmplane DMA

BP1HI2		dc.w	$00E0,0			; bitplane 1 address pointers
BP1LO2		dc.w	$00E2,0
BP2HI2		dc.w	$00E4,0			; bitplane 2 address pointers
BP2LO2		dc.w	$00E6,0
BP3HI2		dc.w	$00E8,0			; bitplane 3 address pointers
BP3LO2		dc.w	$00EA,0
BP4HI2		dc.w	$00EC,0			; bitplane 4 address pointers
BP4LO2		dc.w	$00EE,0

;
;	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	$BC09,$FFFE		; wait for next line
		dc.w	$0100,$4200		; turn on 4 bitplanes

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


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


;
;	include raw picture data's into assembly code
;
PICTURE1:	INCBIN	1bp.oz.raw

PICTURE2:	INCBIN	4bp.oz.raw


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



	END					; end of program

