	
	.text
	.arm
	.global	show_titel
	.type	show_titel,function
	
	.include	"mem_macros.i"
	
@****: Titel speicher Struktur

	.set	GUPPY1_SPR1,	0		@GUPPY1 SPRITE 1
	.set	GUPPY1_SPR2,	4		@GUPPY1 SPRITE 2
	.set	GUPPY1_SPR3,	8		@GUPPY1 SPRITE 3
	.set	GUPPY1_SPR4,	12		@GUPPY1 SPRITE 4
	
	
	.set	GUPPY2_SPR1,	16		@GUPPY2 SPRITE 1
	.set	GUPPY2_SPR2,	20		@GUPPY2 SPRITE 2


	.set	TITEL_STRUCT_LEN	,24
	
@****:	
	
show_titel:

	stmfd	sp!,{r0-r12,lr}

	@**** mach dunkel
	
	mov	r0,#0xff
	strh	r0,[r6,#0x50]
	mov	r0,#0x1f	
	strh	r0,[r6,#0x54]
	
	@**** set gfx

	mov 	r6,#0x4000000   		@
	mov	r1,#0x1f00		@mode 0 bg 2/3 + sprites
	strh 	r1,[r6]			@store

	@**** speicher

	mov	r0,#TITEL_STRUCT_LEN
	stack_alloc_mc	r0		@get mem for titelzeug
	mov	r12,r1			@
	

	@**** init gfx

	mov 	r6,#0x4000000   		@
	ldr	r1,=0x1481		@0     tile,  +40960 (20)map / 256 c prio 0	
	strh 	r1,[r6,#0xc]	
		
	ldr	r1,=0x158c		@49152 tile, +43008 (21) map / 256 c  prio 1
	strh 	r1,[r6,#0xe]
	
	ldr	r1,=0x5680		@0 tile, +45056 (22) map / 256 c  prio 1
	strh 	r1,[r6,#0xa]
	
	ldr	r1,=0x5680		@0 tile, +45056 (22) map / 256 c  prio 1
	strh 	r1,[r6,#0x8]
	
	@**** scroll bg0/bg1 raus
	
	mov	r0,#128
	strh	r0,[r6,#0x10]
	strh	r0,[r6,#0x14]
	

	

	
	@**** titel1 pal (256 farben)
	
	ldr	r0,=titelpal
	mov	r1,#0x5000000
	mov	r2,#256*2
	bl	dmacpy	
	
	@**** titel1 gfx + gpbg
	
	ldr	r0,=titelgfx
	mov	r1,#0x6000000
	ldr	r2,=39744
	bl	dmacpy	
	
	@**** titel_gr gfx 
	
	ldr	r0,=titelgrgfx
	mov	r1,#0x6000000
	add	r1,r1,#49152
	mov	r2,#9216
	bl	dmacpy	
	
	mov 	r6,#0x4000000
	mov	r2,#-159
	strh	r2,[r6,#0x1e]
	
	@**** titel + titel_gr map
	
	ldr	r2,=titelmap
	ldr	r4,=titelgrmap
	ldr	r8,=titelgpbgmap
	mov	r3,#0x6000000
	add	r5,r3,#40960
	add	r9,r3,#45056
	add	r3,r3,#43008
	
	
	mov	r1,#20
map1y:	mov	r0,#30
map1x:	
	ldrh	r6,[r2],#2
	strh	r6,[r5],#2
	
	ldrh	r6,[r4],#2
	strh	r6,[r3],#2
	
	ldrh	r6,[r8],#2
	add	r6,r6,#600
	strh	r6,[r9],#2
	
	subs	r0,r0,#1
	bne	map1x
	
	add	r3,r3,#4
	add	r5,r5,#4
	ldr	r6,=610		@empty
	strh	r6,[r9],#2
	strh	r6,[r9],#2
	@add	r9,r9,#4
	
	subs	r1,r1,#1
	bne	map1y	
	
	@**** fülle rest von bg0 1 (da 512x256)
	
	ldr	r6,=610	@empty
	mov	r1,#32*(32+12)
map01xy:
	strh	r6,[r9],#2
	subs	r1,r1,#1
	bne	map01xy	
	
	@**** spr gfx
	
	ldr	r0,=titelsprgfx
	mov	r1,#0x6000000
	add	r1,r1,#0x10000
	mov	r2,#32768
	bl	dmacpy
	
	@**** spr pal
	
	ldr	r0,=titelsprpal
	mov	r1,#0x5000000
	add	r1,r1,#0x200
	mov	r2,#256*2
	bl	dmacpy
	
	@**** make sprites guppy 1
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#0			@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0x2000c000		@mode 64x64, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY1_SPR1]
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#8			@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0xa000c000		@mode 32x64, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY1_SPR2]
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#128			@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0x6000c000		@mode 64x32, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY1_SPR3]
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#128+8		@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0xa0004000		@mode 8x32, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY1_SPR4]
	
	@**** make sprites guppy 2
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#256			@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0x2000c000		@mode 64x64, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY2_SPR1]
	
	mov	r0,#160
	mov	r1,#0
	mov	r3,#256+128		@tilenummer
	mov	r4,#0			@prio
	ldr	r5,=0x2000c000		@mode 16x32, 256c
	mov	r6,#0
	
	bl	spr_new_sprite
	str	r7,[r12,#GUPPY2_SPR2]
	
	@**** mach heller

	mov	r6,#0x4000000
	mov	r0,#0x1f	
dtoh:
	mov	r2,#160
	bl	wait
	mov	r2,#159
	bl	wait

	strh	r0,[r6,#0x54]
	subs	r0,r0,#1
	cmp	r0,#-1
	bne	dtoh
	
	@****	move guppy1 rein
	
	mov	r4,#5
	mov	r5,#160
mvg1:	swi	0x50000			@vbl
	bl	move_guppy1
	cmp	r5,#66
	sub	r5,r5,#4
	bge	mvg1
	
	@****	move guppy2 rein
	
	mov	r4,#170
	mov	r5,#160
mvg2:	swi	0x50000			@vbl
	bl	move_guppy2
	cmp	r5,#51
	sub	r5,r5,#4
	bge	mvg2
	
	@****	springe bg 3
	
	mov	r6,#184-64-10
	ldr	r5,=jumpdata
	mov	r4,#0x4000000
	ldr	r7,=309
jbg3:	
	swi	0x50000	
	ldrh	r2,[r5],#2
	rsb	r2,r2,r7
	strh	r2,[r4,#0x1e]
	
	subs	r6,r6,#1
	bne	jbg3

	@**** transp gp 1&0 zu 3&2
	
	mov	r4,#0x4000000
	ldr	r5,=0xc43
	ldr	r6,=0x71f
	strh	r5,[r4,#0x50]
	strh	r6,[r4,#0x52]

	@**** scroll gp 1&0
	
	
	
	mov	r5,#-5
	strh	r5,[r4,#0x12]
	strh	r5,[r4,#0x16]
	
	mov	r5,#120
	ldr	r6,=-288
scbg:	swi	0x50000			@vbl
	strh	r5,[r4,#0x10]
	strh	r6,[r4,#0x14]
	cmp	r5,#-80
	sub	r5,r5,#4
	add	r6,r6,#4
	bge	scbg

	@**** wait for taste
	
waita:	mov	r4,#0x4000000
	swi	0x50000			@vbl
	ldr 	r0,[r4,#0x130]
	tst	r0,#1
	bne	waita
		

	@**** free sprite

	ldr	r0,[r12,#GUPPY1_SPR1]
	bl	spr_rem_sprite
	ldr	r0,[r12,#GUPPY1_SPR2]
	bl	spr_rem_sprite
	ldr	r0,[r12,#GUPPY1_SPR3]
	bl	spr_rem_sprite
	ldr	r0,[r12,#GUPPY1_SPR4]
	bl	spr_rem_sprite
	
	ldr	r0,[r12,#GUPPY2_SPR1]
	bl	spr_rem_sprite
	ldr	r0,[r12,#GUPPY2_SPR2]
	bl	spr_rem_sprite

	
	@**** free mem
	
	stack_free_mc			@free mem

	ldmfd	sp!,{r0-r12,lr}
	bx	lr
	
	
@***********************************************************:
@*:
@*: move guppy 1
@*:
@*: r4  = x
@*: r5  = y
@*: r12 = &this

move_guppy1:

	stmfd	sp!,{r0,r1,r2,lr}
	

	ldr	r0,[r12,#GUPPY1_SPR1]
	mov	r1,r4
	mov	r2,r5
	bl	spr_change_xy
	
	ldr	r0,[r12,#GUPPY1_SPR2]
	add	r1,r4,#64
	mov	r2,r5
	bl	spr_change_xy
	
	ldr	r0,[r12,#GUPPY1_SPR3]
	mov	r1,r4
	add	r2,r5,#64
	bl	spr_change_xy
	
	ldr	r0,[r12,#GUPPY1_SPR4]
	add	r1,r4,#64
	add	r2,r5,#64
	bl	spr_change_xy

	ldmfd	sp!,{r0,r1,r2,lr}
	bx	lr	
	
@***********************************************************:
@*:
@*: move guppy 2
@*:
@*: r4  = x
@*: r5  = y
@*: r12 = &this

move_guppy2:

	stmfd	sp!,{r0,r1,r2,lr}
	

	ldr	r0,[r12,#GUPPY2_SPR1]
	mov	r1,r4
	mov	r2,r5
	bl	spr_change_xy
	
	ldr	r0,[r12,#GUPPY2_SPR2]
	mov	r1,r4
	add	r2,r5,#64
	bl	spr_change_xy
	
	ldmfd	sp!,{r0,r1,r2,lr}
	bx	lr		
	
	
	.pool
	
	
titelgfx:	.include	"gfx/titel.gfx.s"	@38400
titelgpbggfx:	.include	"gfx/titel_gpbg.gfx.s"	@1344 = 39744
titelpal: 	.include	"gfx/titel.pal.s"	@256*2
titelmap:	.include	"gfx/titel.map.s"	@1200

titelgrgfx:	.include	"gfx/titel_gr.gfx.s"	@9216
titelgrmap:	.include	"gfx/titel_gr.map.s"	@1200


titelgpbgmap:	.include	"gfx/titel_gpbg.map.s"	@1200

titelsprgfx:	.include	"gfx/titel_spr.gfx.s"	@
		.include	"gfx/titel_spr2.gfx.s"	@32768
titelsprpal: 	.include	"gfx/titel_spr.pal.s"	@256*2

jumpdata:

     .hword 0xffd8,0xffdb,0xffdf,0xffe2,0xffe6,0xffe9,0xffed,0xfff0,0xfff4,0xfff7,0xfffb,0xffff,0x0003,0x0007,0x000b,0x000e,0x0012,0x0016,0x001b,0x001f,0x0023,0x0027
     .hword 0x002b,0x0028,0x0024,0x0020,0x001c,0x0018,0x0014,0x0011,0x000e,0x000a,0x0007,0x0004,0x0001,0xffff,0xfffc,0xfffa,0xfff8,0xfff5,0xfff3,0xfff2,0xfff0,0xffee,0xffed,0xffeb,0xffea,0xffe9,0xffe8,0xffe7,0xffe7,0xffe6,0xffe6,0xffe5
     .hword 0xffe5,0xffe5,0xffe6,0xffe6,0xffe6,0xffe7,0xffe7,0xffe8,0xffe9,0xffea,0xffec,0xffed,0xffee,0xfff0,0xfff2,0xfff4,0xfff6,0xfff8,0xfffa,0xfffd,0xffff,0x0002,0x0005,0x0008,0x000b,0x000e,0x0011,0x0015,0x0019,0x001c,0x0020,0x0024
     .hword 0x0029,0x0028,0x0024,0x0020,0x001d,0x001a,0x0018,0x0016,0x0014,0x0013,0x0012,0x0012,0x0012,0x0012,0x0013,0x0014,0x0016,0x0018,0x001a,0x001d,0x0020,0x0024,0x0028,0x0028



