	
	.text
	.arm
	.global	show_logo
	.type	show_logo,function
	
show_logo

	stmfd	sp!,{r0-r12,lr}


	;**** mach dunkel
	
	mov	r0,#$ff
	strh	r0,[r6,#$50]
	mov	r0,#$1f	
	strh	r0,[r6,#$54]
	
	;**** set gfx

	mov 	r6,#$4000000   		;
	mov	r1,#$1400		;mode 0 bg 2/3 + sprites
	strh 	r1,[r6]			;store

	;**** init gfx

	mov 	r6,#$4000000   		;
	ldr	r1,=$1481		;0 tile,   +40960 (20)map / 256 c prio 0	
	strh 	r1,[r6,#$c]	
		
	ldr	r1,=$1508		;32k tile, +43008 (21) map / 16 c  prio 1
	strh 	r1,[r6,#$e]
	
		
	;**** logo 2 pal (64 farben)
	
	ldr	r0,=logo2pal
	mov	r1,#$5000000
	mov	r2,#64*2
	bl	dmacpy	
	
	;**** logo 1 pal (16 farben)
	
	ldr	r0,=logo1pal
	mov	r1,#$5000000
	add	r1,r1,#64*2
	mov	r2,#16*2
	bl	dmacpy	
	
	;**** logo 2 gfx 
	
	ldr	r0,=logo2gfx
	mov	r1,#$6000000
	ldr	r2,=23616
	bl	dmacpy	
	
	;**** logo 1 gfx 
	
	ldr	r0,=logo1gfx
	mov	r1,#$6000000
	add	r1,r1,#32768
	ldr	r2,=8075
	bl	dmacpy
	
	;**** map 2
	
	ldr	r2,=logo2map
	mov	r3,#$6000000
	add	r3,r3,#40960
	
	mov	r1,#20
map2y	mov	r0,#30
map2x	ldrh	r4,[r2],#2
	strh	r4,[r3],#2
	subs	r0,r0,#1
	bne	map2x
	add	r3,r3,#4
	subs	r1,r1,#1
	bne	map2y
	
	;**** map 1
	
	ldr	r2,=logo1map
	mov	r3,#$6000000
	add	r3,r3,#43008
	
	mov	r1,#20
map1y	mov	r0,#30
map1x	ldrh	r4,[r2],#2
	orr	r4,r4,#$4000		;palette 4
	strh	r4,[r3],#2
	subs	r0,r0,#1
	bne	map1x
	add	r3,r3,#4
	subs	r1,r1,#1
	bne	map1y	

	;**** mach heller

	mov	r6,#$4000000
	mov	r0,#$1f	
dtoh2
	mov	r2,#160
	bl	wait
	mov	r2,#159
	bl	wait

	strh	r0,[r6,#$54]
	subs	r0,r0,#1
	cmp	r0,#-1
	bne	dtoh2

	;**** setze transp.
	
	ldr	r1,=$448		;bg2-3
	strh	r1,[r6,#$50]
	ldr	r1,=$151f
	strh	r1,[r6,#$52]
	
	;**** schalte bg2 wieder an
	
	mov 	r6,#$4000000   		;
	mov	r1,#$1c00		;mode 0 bg 2/3 + sprites
	strh 	r1,[r6]			;store
	
	;**** init timer 1 irq for sound
	
	ldr	r0,=irq_smp
	mov	r1,#4			;timer 1			
	ldr	r2,=add_irq_th+1
	mov	lr,pc
	bx	r2
	
	
		
	;**** logo1 enttransparenten :)

	mov	r6,#$4000000
	mov	r10,#31	
enttra

	mov	r2,#160
	bl	wait
	mov	r2,#159
	bl	wait
	mov	r2,#158
	bl	wait
	mov	r2,#157
	bl	wait
	mov	r2,#156
	bl	wait	
	
	cmp	r10,#16
	bne	wait_sound
	
	;**** spiele lachen
	
	stmfd	sp!,{r0,r1,r2,r6,r10}
	ldr	r0,=lachen_smp+128
	ldr	r1,=20366-128
	ldr	r2,=($ffff-(16777216/8192))
	mov	r3,#0
	mov	r4,#0
	ldr	r10,=sd_struct
	bl	play_sound
	ldmfd	sp!,{r0,r1,r2,r6,r10}
	
wait_sound	
	
	mov	r1,r10,lsl #8
	orr	r1,r1,#$1f
	strh	r1,[r6,#$52]

	subs	r10,r10,#1
	cmp	r10,#-1
	bne	enttra	
			
	mov	r0,#0
	strh	r0,[r6,#$50]
	strh	r0,[r6,#$52]			
			
	;**** warte
	
	mov	r3,#120
wasteti	
	mov	r2,#160
	bl	wait
	mov	r2,#159
	bl	wait
	
	subs	r3,r3,#1
	bne	wasteti
		
	;**** mach hell
	
	mov	r0,#$fc
	strh	r0,[r6,#$50]
	mov	r0,#$0
	strh	r0,[r6,#$54]
	
	;**** rem timer 1 
	
	ldr	r0,=irq_smp
	mov	r1,#4			;timer 1			
	ldr	r2,=rem_irq_th+1
	mov	lr,pc
	bx	r2
	
	;**** stop timer 0/1
	
	mov	r6,#$4000000
	add	r7,r6,#$200
	
	mov	r0,#$0			;alles aus
	strh	r0,[r7]
	

	;**** mach dunkler

	mov	r6,#$4000000
	mov	r0,#$1f	
dtoh
	mov	r2,#160
	bl	wait
	mov	r2,#159
	bl	wait

	rsb	r1,r0,#$1f
	strh	r1,[r6,#$54]
	subs	r0,r0,#1
	cmp	r0,#-1
	bne	dtoh

	
	ldmfd	sp!,{r0-r12,lr}
	bx	lr
	
	.pool
		

;**** sound irq

irq_smp
	stmfd	sp!,{r7,lr}

	ldr	r7,=sd_struct
	bl	play_sound_irq

	ldmfd	sp!,{r7,lr}
	bx	lr		
	
	.pool
		
			
		.align	4
lachen_smp	.incbin	"sound/samples/kinder3.aif"  
		.align	4
	
logo1gfx	.include	"gfx/logo1.gfx.s"	;8075
logo1pal 	.include	"gfx/logo1.pal.s"	;16*2
logo1map	.include	"gfx/logo1.map.s"	;1200

logo2gfx	.include	"gfx/logo2.gfx.s"	;23616
logo2pal 	.include	"gfx/logo2.pal.s"	;64*2
logo2map	.include	"gfx/logo2.map.s"	;1200

;*****************************************************************************************************************
;*
;*	WRAM 
;*
;*****************************************************************************************************************

	.section    	.ewram,"ax"
	
		.align	4
sd_struct	
sd_sample	.long	0
sd_samplecnt	.long	0
sd_stop		.long	0
sd_con		.long	0		;0000 00BA  a = timer 1/2, b = dma 1/2
