;
;	Bitplane Example 9.
;
;	Written for OZAmiga by Chris Leathley.
;
;	Turning on a 1 bitplane hi-res picture (Deluxe Paint MED-RES)
;	and use a colour modifier to change (or cycle) the WARNING text
;
;	this display changes the modulo and colour half way down the screen
;	to create a reflection effect
;


;
;	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 (longword)
		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	#COPPERLIST,$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



;
;	our copperlist program
;
COPPERLIST:	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,$9200		; turn on 1 bitplane
						; with hi-res mode (bit 15)

		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,$3C		; bitplane DMA start (for hi-res
		dc.w	$094,$d4		; bitplane DMA stop	mode)
		dc.w	$108,0			; odd modulo
		dc.w	$10A,0			; even modulo

		dc.w	$2B09,$FFFE,$180,$F00	; red line
		dc.w	$2C09,$FFFE,$180,$000	; screen back to black
		dc.w	$0182,$0FF0		; yellow "warning"

;
;	make the reflection effect by giving it a negative modulo
;
		dc.w	$AD09,$FFFE,$180,$005	; blue background
		dc.w	$108,-(80+80)		; odd modulo
		dc.w	$10A,-(80+80)		; even modulo

		dc.w	$182,$880		; half bright yellow


		dc.w	$FFDF,$FFFE		; skip NTSC vertical blank

		dc.w	$2C09,$FFFE,$180,$F00	; another red line
		dc.w	$2D09,$FFFE,$180,$000

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

						; start vertical blank


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


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


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



	END					; end of program

