**
** SORRY ABOUT THE FLICKER!
**
** A small piece of code to demostrate (big word!) how to move a bob
** according to a set of predefined co-ordinates (wow!)
**
** Code by Raist
**
** Graifx by Master Beat (Mr lufc himself!)
**
** Watcha!  Leeds are weedd!  Cool people neep MUFC (conquest of Europe!)

	opt c-

	include	source:include/hardware.i		; Harware equates

	section	Scrolling,code		; Use public memory

	lea	$dff000,a5		; Address of DMA in a5

	move.l	4,a6			; A6=Exec base
	lea	gfxname,a1		; address of lib name in a1
	moveq.l	#0,d0			; Any version
	jsr	-552(a6)		; Open the lib
	move.l	d0,gfxbase		; Save base address of gfx lib
	beq	error			; Quit if error found
	
	jsr	-132(a6)		; Forbid

	
****************************************************************************
;		Load the bitplane pointers
****************************************************************************
	move.l	#Screen,d0		; D0=Address of the screen

	move.w	d0,bpl1+2		; Load the bpl pointers
	swap	d0
	move.w	d0,bph1+2
	swap	d0
	add.l	#256*40,d0
	move.w	d0,bpl2+2
	swap	d0
	move.w	d0,bph2+2
	swap	d0
	add.l	#256*40,d0
	move.w	d0,bpl3+2
	swap	d0
	move.w	d0,bph3+2
	swap	d0
	add.l	#256*40,d0
	move.w	d0,bpl4+2
	swap	d0
	move.w	d0,bph4+2
	swap	d0
	add.l	#256*40,d0
	move.w	d0,bpl5+2
	swap	d0
	move.w	d0,bph5+2



****************************************************************************
;	          Set-Up The Co-Ordinates Tables
****************************************************************************
Dragon1
; First set-up the co-ordinates table for Dragon Logo 1
	lea	Cords1,a0	; A0=Address of co-ordinates table to transform
.Loopy
	cmpi.w	#$ffff,(a0)	; End of co-ordinates table?
	beq	.End		; If don't transform any more co-ordinates
	move.w	(a0),d7		; D7=X cord
	cmpi.w	#$ff00,d7	; Is X a pause code?
	bls	.NotPause	; If its lower than $ff00 it aint no pause
	add.l	#2,a0		; If it is a pause skip it
.NotPause
	move.l	(a0),d0		; Else D0=X Y  (X in high word)
	move.w	d0,d1		; D1=Low word of d1 (Y value)
	move.w	#0,d0		; Clear low word of d0
	swap	d0		; Put X offset in low word
	mulu	#40,d1		; Turn d0 into correct format
	divu	#16,d0		; D0 now=low word Xoffset high word=shift
	lsl.w	#1,d0		; Turn X offset into bytes
	add.w	d0,d1		; Add X offset to Y offset
	swap	d0		; Put barrel shift into low word
	lsl.w	#4,d0		; 4+8=12
	lsl.w	#8,d0		; Put barrel shift into 4 MSB
	move.w	d0,(a0)+	; Insert shift into 1st word
	move.w	d1,(a0)+	; Insert offset into 2nd word
	bra	.Loopy		; And convert the other co-ordinates
.End

	lea	cords1,a0	; A0=Address of cords
	move.w	2(a0),LastXY	; Set-up last XY

****************************************************************************
; 		Set-up the DMA
****************************************************************************
DMA	move.w	#$20,dmacon(a5)
	move.l	#Copperlist,cop1lch(a5)	; Load my copper list
	move.w	#$0,copjmp1(a5)		; Run my copper list


****************************************************************************
;		The Main Branching Routine
****************************************************************************
WaitVBL1
	cmpi.b	#$ff,vhposr(a5)
	bne	WaitVBL1

;	move.w	#$fff,color00(a5)	; Raster measure

	bsr	WipeLogo1		; Move Dragon Logo1
	
;	move.w	#$000,color00(a5)	; Raster measure

	btst	#6,$bfe001
	bne	WaitVBL1


****************************************************************************
;		Clean-up the system ready to leave
****************************************************************************
Clean_Up
	move.w	#$8e30,dmacon(a5)	; Enable everything
	move.l	gfxbase,a1
	move.l	38(a1),cop1lch(a5)	; System copper list
	move.w	#$0,copjmp1(a5)		; Run the system copper
	move.l	4,a6			; A6=Exec base
	move.l	gfxbase,a1		; address of gfx lib in a1
	jsr	-408(a6)		; Close the lib
	jsr	-138(a6)		; Permit
error	rts				; End the program



****************************************************************************
;		The Routine To Move Dragon Logo 1
****************************************************************************
; This routine wipes the old dragon logo image
; Something seems to be wrong with this wipe routine.  I've got to go out
; now & so I've no more time to finish it, Mark have a look will you to 
; prevent me looking like a lamer!
WipeLogo1
	btst	#14,dmaconr(a5)
	bne	WipeLogo1
	lea	Screen,a1		; A1=Destination
	add.w	LastXY,a1		; Offset
	move.w	#16,bltdmod(a5)		; 40-24
	move.w	#%100000000,bltcon0(a5)	; D wipe blit
	move.w	#$0,bltcon1		; Wipe
	moveq.l	#4,d0			; Number of bitplanes-1
.Loopy
	btst	#14,dmaconr(a5)
	bne	.Loopy
	move.l	a1,bltdpth(a5)
	move.w	#(74*64)+12,bltsize(a5)	; 176*74
	add.w	#256*40,a1		; Next plane
	dbra	d0,.Loopy

*******************************
* Actual Bob Movement Routine *
*******************************
MoveLogo1
; Find out where to blit the bob next
	move.l	cord1,a6		; A6=Pointer to next co-ordinates
	cmpi.w	#$ffff,(a6)		; Are we at end of cords table?
	bne	.NotEnd1
	lea	Cords1,a6		; Re-load cords table
.NotEnd1
	move.w	(a6)+,d1		; D1=Barrel shift
	move.w	(a6)+,d2		; D2=Offset
	move.l	a6,Cord1		; Save the cords pointer
	move.w	d2,LastXY		; Save LastXY pos
; Blit The Bob
	lea	Bob,a0			; A0=Address of bob
	lea	Screen,a1		; A1=Address of Screen
	move.w	#-2,bltamod(a5)		; 40-42 
	move.w	#16,bltdmod(a5)		; 40-24
	move.w	#$ffff,bltafwm(a5)	; No first word mask
	move.w	#$0000,bltalwm(a5)	; No last word mask
	move.w	#%100111110000,d4	; D4=Bltcon0 value
	move.w	#$0,d5			; D5=bltcon1 value
	or.w	d1,d4			; OR barrel shift
	or.w	d1,d5			; OR barrel shift
	move.w	d4,bltcon0(a5)
	move.w	d5,bltcon1(a5)
	add.w	d2,a1			; Add the offset
	moveq.l	#4,d0			; Number of planes to blit-1
.Loopy	btst	#14,dmaconr(a5)
	bne	.Loopy
	move.l	a0,bltapth(a5)
	move.l	a1,bltdpth(a5)
	move.w	#(74*64)+12,bltsize(a5)
	add.w	#74*22,a0
	add.w	#256*40,a1
	dbra	d0,.Loopy
	rts
	

****************************************************************************
;			THE COPPER LIST
****************************************************************************
	section	copperlist,code_c	; Chip memory
Copperlist	
	dc.w	diwstrt,$2c81		; Window start
	dc.w	diwstop,$2cc1		; Window stop
	dc.w	ddfstrt,$38		; Data fetch start
	dc.w	ddfstop,$d0		; Data fetch stop
	dc.w	bplcon0,%0101001000000000
	dc.w	bplcon1,$0
Pri	dc.w	bplcon2,$0		; Bitplane priority (over sprites)
	dc.w	bpl1mod,0,bpl2mod,0

bph1	dc.w	bpl1pth,$0		; The bitplane pointers
bpl1	dc.w	bpl1ptl,$0
bph2	dc.w	bpl2pth,$0
bpl2	dc.w	bpl2ptl,$0
bph3	dc.w	bpl3pth,$0
bpl3	dc.w	bpl3ptl,$0
bph4	dc.w	bpl4pth,$0
bpl4	dc.w	bpl4ptl,$0
bph5	dc.w	bpl5pth,$0
bpl5	dc.w	bpl5ptl,$0

	dc.w	$180,$000,$182,$fff,$184,$cce,$186,$99e
	dc.w	$188,$77d,$18a,$44c,$18c,$22c,$18e,$00b
	dc.w	$190,$ff0,$192,$ed0,$194,$da0,$196,$c90
	dc.w	$198,$a70,$19a,$950,$19c,$840,$19e,$730
	dc.w	$1a0,$620,$1a2,$f00,$1a4,$d00,$1a6,$b00
	dc.w	$1a8,$800,$1aa,$600,$1ac,$400,$1ae,$200
	dc.w	$1b0,$0f0,$1b2,$0d0,$1b4,$0c0,$1b6,$0a0
	dc.w	$1b8,$090,$1ba,$070,$1bc,$060,$1be,$040
	
	dc.w	$ffff,$fffe





****************************************************************************
;			Variables
****************************************************************************
	section	fast_variables,data
gfxname	dc.b	'graphics.library',0	; Name of lib to load
	even
gfxbase	dc.l	0			; Space for libs address



************************************************
* The Co-Ordinates Variables For Dragon Logo 1 *
************************************************
LastXY	 dc.w	0			; Last offset 
Cord1	dc.l	Cords1			; Pointer to cords table
Cords1	include	'source:raistlin/Table.s'
	dc.w	$ffff			; End of cords table

*****************************************************************************
;        		The Gfx Data In Chip Mem 		            
*****************************************************************************
	section	chip_variables,data_c

Screen	dcb.b	256*40*5,$0
*****************************
* Gfx data for Dragon Logo1 *
*****************************
Bob	incbin	'source:bitmaps1/tdmlogo.gfx'


