INTRO

;all code & gfx  by henrik stolpe
;load bitmap in $58000 (3 bpl)
;load textbitmap into $98000 (1 bpl)
;featuring 
;8 color logo
;4 channel sampled loop
;2 speed,2 direction,3 color sinus spritescroll
;shaded copperhorizon
;blitter scroll text

******************** Euqates ********************
aud0lch = $dff0a0
aud0len = $dff0a4
aud0per = $dff0a6
aud0vol = $dff0a8
aud1lch = $dff0b0
aud1len = $dff0b4
aud1per = $dff0b6
aud1vol = $dff0b8
aud2lch = $dff0c0
aud2len = $dff0c4
aud2per = $dff0c6
aud2vol = $dff0c8
aud3lch = $dff0d0
aud3len = $dff0d4
aud3per = $dff0d6
aud3vol = $dff0d8

;******************init main**************************
s:
	lea 	copper,a3
	lea 	copper,a0		
	move.l 	a0,$dff080		;copper to cop1lch
	move 	$dff088,d0		;copjmp1 to d0
	move 	#$83e0,$dff096	;enable DMA
;	move.w	#$0020,$dff096	;disable sprite
	move.w	#$1500,$dff104	;set video prio
	move	#$800f,$dff096	;turn on 4 channel sound




;****************call routines************************
;	bsr 	sound
	bsr	makebar
	bsr	getcol
	bsr	setspritecol
	bsr	getsprites
	bsr	initscroll
	bsr	flashinit

;**********************************************************
;******************vertical blanking interupt**************
;**********************************************************
interupt:
	cmp.b	#$00,$dff006	;test beamposition
	bne	wait			
	and	#1,$dff004		;set LOF
	beq	interupt		;test again

	
;************mainloop**********
	jsr	movesprites
	jsr	flash
	jsr	ready
	
wait:
	btst	#6,$bfe001
	bne	interupt
	jsr	slut
	rts

;**********************************************
;********************routines******************
;**********************************************


;**************COLOR FLASH INIT*********************
flashinit:
		lea	flashdata,a4
		lea 	flashcol,a6
		moveq	#84,d1
		move.w	d1,fd1
		rts



;**************COLOR FLASH**************************
flash:
		move.l	fd1,d1
		lea	flashcol,a6
		move.w	#$0fe2,(a6)+
		move.w	#$fffe,(a6)+
		move.w	#$0182,(a6)+
		move.w	(a4)+,(a6)
;		subq	#1,d1
;		cmp.w	#0,d1
		beq	resetcol
		rts

resetcol:
		add	#40,d1
		lea	flashdata,a4
		rts

	
fd1:
		dc.w	0

;**************BLITTER SCROLL*******************

ready:
	btst	#14,$dff002	;testa om blitterbusy
	bne	ready	;		
	move.l	#$47000,$dff050	;blitterpointer to sA
	move.l	#$46ffe,$dff054	;blitterpointer to dest D
	clr.l	$dff064		;rensa blittermodulo for  	move.l	#$ffffffff,$dff044	;wordmask for sA
	move	#$e9f0,$dff040	;enable blittercontrol bits
	move	#$0716,$dff058	;blit start/size,win h,b
	
	add	#1,speeden
	cmp	#8,speeden
	bne	wait
	clr	speeden
	clr.l	d1
	
tagen:
	lea	texten,a3		;text i a0
	add	pos,a3			
	cmp.b	#$ff,(a3)
	bne	inte_reset
	clr	pos
	bra	tagen
	
inte_reset:
	move.b	(a3),d1
	sub.b	#32,d1		;Textbredd (32)
	move	d1,d6
	divu	#20,d1		;Texthojd (20)
	mulu	#920,d1
	mulu	#2,d6
	add	d6,d1
	
	add.l	#$98000,d1		;bitmap i d0
	add	#1,pos
	move.l	d1,a3		;bitmap i a0
	
ready2:
	btst	#14,$dff002	;testa om blitter busy
	bne	ready2
	move.l	a3,$dff050		;a0 i blitterpointer sA
	move.l	#$47030,$dff054	;pointer to dest D
	move	#38,$dff064	;modulo for source A
	move	#46,$dff066	;modulo for dest D
	move.l	#$ffffffff,$dff044	;word mask for sA
	move	#$09f0,$dff040	;blitter control reg0
	clr	$dff042		;clear controlreg 1
	move	#$0601,$dff058	;blit start and size
	rts		
	


texten:
	dc.b 	"STATIC IN MOTION WITH HIS FIRST INTRO "
	dc.b	$ff
	even

speeden:
	dc.w	0
	
pos:
	dc.w	0







;**********move sprites***************
movesprites:
	add.b	d4,d2		;to tha right
	sub.b	d3,d5		;to tha left	

;*********move sprite layer0**********
	move.b	d5,$79001
	add	#55,d5
	move.b	d5,$89001
	sub	#55,d5
	add	#120,d5
	move.b	d5,$90001
	sub	#120,d5

;********move sprite layer1***********
	move.b	d2,$78001
	add	#50,d2
	move.b	d2,$91001
	sub	#50,d2
	sub	#50,d2
	move.b	d2,$92001
	add	#50,d2

;*******apply sinus*******************
sin:
	moveq	#0,d1
	moveq	#0,d6
	move	done,d1
	move	dsix,d6
	add	#1,d6
	jsr	testit5
	move	d1,done
	move	d6,dsix
	rts

done:
	dc.w	0

dsix:
	dc.w	0
;************get picture colors****************
getcol:
;load colors
	move	#8,d3
	lea	colors,a3
	lea	$5f802,a2		;farg avstand icop=4
	add	#2,a3

colorloop:
	move	(a2),(a3)	
	add	#2,a2
	add	#4,a3
	subq	#1,d3
	cmp	#1,d3
	bne	colorloop
	rts

;*****************set sprite colors************
setspritecol:
;sp0/1
	move	#$0006,$dff1a2
	move	#$000a,$dff1a4
	move	#$000c,$dff1a6
;sp2/3		
	move	#$00a0,$dff1ac
	move	#$0070,$dff1ae
	move	#$0040,$dff1b0
;sp4/5
	move	#$0e00,$dff1b2
	move	#$0900,$dff1b4
	move	#$0600,$dff1b6
	rts

;******************get sprite data**************
getsprites:
;set dummy sprites
	move.l	#$00000000,$30000

;setup sprite0
	move.l	#$78000,a1
	lea	sprite0,a2
	jsr	sploop
;setup sprite1
	move.l	#$90000,a1
	lea	sprite1,a2
	jsr	sploop
;setup sprite2
	move.l	#$79000,a1
	lea	sprite2,a2
	jsr	sploop
;setup sprite3
	move.l	#$91000,a1
	lea	sprite3,a2
	jsr	sploop
;setup sprite4
	move.l	#$89000,a1
	lea	sprite4,a2
	jsr	sploop
;setup sprite5
	move.l	#$92000,a1
	lea	sprite5,a2
	jsr	sploop
	rts
	
sploop:
	move.w	(a2)+,(a1)+
	move.w	(a2),(a1)+
	lea	spritedata,a2

sploopit:
	move.l	(a2)+,(a1)	
	cmp.l	#$00000000,(a1)+
	bne	sploopit	
	rts

;****************init sprite scroll************
initscroll:
;set sprite scroll speed
	move.b	#4,d4		;scroll speed/step
	move.b	#2,d3		;scroll speed/step2

;sinus setup
	moveq	#1,d7		;direction indicator
	move	#0,dsix		;amplitude
	move	#1,done		;sinus inc	
	move.b	#$6a,d0		;startpos
	rts	


;************sprite sinus***************
chdir5:
	sub	#40,d6
	cmp	#0,d7
	beq	down5
	sub	#2,d1
	sub	#1,d7
	rts

down5:
	add	#2,d1
	add	#1,d7	

testit5:
	cmp	#40,d6
	beq	chdir5
	add	d1,d0
	move.b	d0,$92000
	sub.b	#$6a,d0
	add.b	#$40,d0
	move.b	d0,$79000
	sub.b	#$40,d0
	add.b	#$80,d0
	move.b	d0,$91000
	sub.b	#$80,d0
	add.b	#$6a,d0
	rts

***************sampled sound player*********
sound:
;set length of sound in bytes
len = 6000


chanl0:
	move.l	#48000,aud0lch
	move.w	#[len/2],aud0len
	move.w	#0358,aud0per
	move.w	#0064,aud0vol
		
chanl1:
	move.l	#$48000,aud1lch
	move.w	#[len/2],aud1len
	move.w	#0358,aud1per
	move.w	#0064,aud1vol
	
chanl2:
	move.l	#$48000,aud2lch
	move.w	#[len/2],aud2len
	move.w	#0358,aud2per
	move.w	#0064,aud2vol
	
chanl3:
	move.l	#$48000,aud3lch
	move.w	#[len/2],aud3len
	move.w	#0358,aud3per
	move.w	#0064,aud3vol
	rts 	


;***********make copper bar**********
makebar:
	move.b	#$1,d3
	move.b	#$b8,d1			;vertical cunt(start position)
	move.w	#$000f,d2		;color
	moveq	#1,d4
	lea	bar,a3

barlp:
	;color line
	move.b	d1,(a3)+
	move.b	#$0f,(a3)+
	move.w	#$fffe,(a3)+
	move.w	#$0180,(a3)+
	move.w	d2,(a3)+
	add.b	d3,d1

;black line
	move.b	d1,(a3)+
	move.b	#$0f,(a3)+
	move.w	#$fffe,(a3)+
	move.w	#$0180,(a3)+
	move.w	#$0000,(a3)+
	add.b	d3,d1

makeline:
;color line
	move.b	d1,(a3)+
	move.b	#$0f,(a3)+
	move.w	#$fffe,(a3)+
	move.w	#$0180,(a3)+
	move.w	d2,(a3)+
	add.b	d3,d1

;black line
	move.b	d1,(a3)+
	move.b	#$0f,(a3)+
	move.w	#$fffe,(a3)+
	move.w	#$0180,(a3)+
	move.w	#$0000,(a3)+
	add	d3,d1
	add	#1,d4
	sub.b	d3,d2
	cmp	#14,d4
	bne	barlp
	rts

;**********end nicely*****************
slut:
	move.l	#$000f,$dff096		;kill sound
	move.l	4,a6			;avsluta bildhantering
	lea	gfxname,a1
	jsr	-408(a6)
	move.l	d0,a1
	move.l	38(a1),$dff080
	jsr	-414(a6)
	rts	

gfxname:
	dc.b	'graphics.library',0
	even


;*****************************************************
;*************************data************************
;*****************************************************

copper:
	dc.w	$008e,$2c81,$0090,$29c1	;set display window (start,stop)
	dc.w	$0092,$0038,$0094,$00d0 ;set bitplane datafetch horis pos
	dc.w	$0180,$0000 	;set bitplan con0,bakgrund svart
	dc.w	$0100,$3200	;set bitplan con0
				;i 0090 lbyte=hor,ubyte=vert

;**************sprite pointers********
;sp0
	dc.w 	$0120,$0007		
	dc.w	$0122,$8000
;sp1
	dc.w	$0124,$0009 		
	dc.w	$0126,$0000

;sp3
	dc.w	$012c,$0009
	dc.w	$012e,$1000

;sp2	
	dc.w	$0128,$0007
	dc.w	$012a,$9000

;sp4
	dc.w	$0130,$0008
	dc.w	$0132,$9000

;sp5
	dc.w	$0134,$0009
	dc.w	$0136,$2000


;dummy sprites
	dc.w	$0138,$0003
	dc.w	$013a,$0000
	dc.w	$013c,$0003
	dc.w	$013e,$0000


;************bitplane pointers********
bitplan:
	dc.w	$00e0,$0005,$00e2,$8000 ;bpl1   pa $58000
	dc.w	$00e4,$0005,$00e6,$a800 ;bpl2   pa $58000+2800
	dc.w	$00e8,$0005,$00ea,$d000 ;bpl3	pa $58000+(2800)x2

;************picture colors***********
colors:	
	dc.w	$0182,$0000,$0184,$0000,$0186,$0000
	dc.w	$0188,$0000,$018a,$0000,$018c,$0000	
	dc.w	$018e,$0000,$0190,$0000

;************copper bar***************

bar:
	blk.w	208,0

reload:
	dc.w	$0fe2,$fffe,$0092,$0020
	dc.w	$0fe2,$fffe,$0094,$00d8
	dc.w	$0fe2,$fffe,$00e0,$0004	
	dc.w	$0fe2,$fffe,$00e2,$7000

flashcol:
	blk.w	4,0	

;***************sprite data*************
spritedata:
	dc.w	$0990,$07e0
	dc.w	$13c8,$0ff0
	dc.w	$23c4,$1ff8
	dc.w	$13c8,$0ff0
	dc.w	$0990,$07e0
	dc.w	$0000,$0000

;***********sprite position data*******
sprite0:
	dc.w	$6d60,$7200
	blk.w	12,0
	
sprite1:
	dc.w	$ad60,$ff00
	blk.w	12,0

sprite2:
	dc.w	$40ae,$ff00
	blk.w	12,0
	
sprite3:
	dc.w	$a0fe,$ff00
	blk.w	12,0

sprite4:
	dc.w	$5a5e,$fd00
	blk.w	12,0

sprite5:
	dc.w	$6afe,$f300
	blk.w	12,0
	
flashdata:
	dc.w	$0f00,$0e00,$0d00,$0c00
	dc.w	$0b00,$0a00,$0900,$0800
	dc.w	$0700,$0600,$0500,$0400
	dc.w	$0300,$0200,$0100,$0200
	dc.w	$0300,$0400,$0500,$0600
	dc.w	$0700,$0800,$0900,$0a00
	dc.w	$0b00,$0c00,$0d00,$0e00
	dc.w	$0f00,$0e00,$0d00,$0c00
	dc.w	$0b00,$0a00,$0900,$0800
	dc.w	$0700,$0600,$0500,$0400
	dc.w	$0300,$0200,$0100,$0200
	dc.w	$0300,$0400,$0500,$0600
	dc.w	$0700,$0800,$0900,$0a00
	dc.w	$0b00,$0c00,$0d00,$0e00
	dc.w	$0f00,$0e00,$0d00,$0c00
	dc.w	$0b00,$0a00,$0900,$0800
	dc.w	$0700,$0600,$0500,$0400
	dc.w	$0300,$0200,$0100,$0200
	dc.w	$0300,$0400,$0500,$0600
	dc.w	$0700,$0800,$0900,$0a00
	dc.w	$0b00,$0c00,$0d00,$0e00

	dc.w	$ffff,$fffe