;******************************
;*
;* introScreen
;*

introScreen

	;prolog

	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7
	
	;init module
	
	dexti	>modChannels
	movei	r4,modChannels
	dexti	>modInit
	movei	r2,modInit
	gpci	r7,2		;next 4 + X
	jmpi	r2,0
	movei	r0,globalTitleMod	;delay slot
	movei	r1,>>globalTitleMod	;delay slot
	moveih	r0,>globalTitleMod	;delay slot
	moveih	r1,>>>globalTitleMod	;delay slot
	
	;start music
	
	dexti	>modStart
	movei	r1,modStart
	gpci	r7,2		;next 4 + X
	jmpi	r1,0		;start
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	;reset start position
	
	gpci	r7,2
	br	setStartPosition
	dexti	>levelTCData		;delay slot
	movei	r6,levelTCData		;delay slot
	nop			;delay slot
	nop			;delay slot

introScreenLoop

	;wait vpos (930)

	dexti	>waitVPos
	movei	r4,waitVPos
	gpci	r7,2	
	jmpi	r4,0
	movei	r3,$a1	;delay slot
	nop		;delay slot
	moveih	r3,$3	;delay slot
	nop		;delay slot	
		
	;frame switch
	
	dexti	>switchFrames
	movei	r4,switchFrames
	gpci	r7,2
	jmpi	r4,0
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	;process ps2 keys
	
	dexti	>PS2Process
	movei	r4,PS2Process
	gpci	r7,2		
	jmpi	r4,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	;update counters (used for map anim)

	dexti	>updateCounters
	movei	r4,updateCounters
	gpci	r7,2
	jmpi	r4,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot	
	
	;testKeys
	
	dexti	>testKeys
	movei	r4,testKeys
	gpci	r7,2
	jmpi	r4,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot	
		
	;anim map

	dexti	>animMap
	movei	r4,animMap
	gpci	r7,2		
	jmpi	r4,0
	dexti	>lvTMapData	;		delay slot
	movei	r0,lvTMapData	;		delay slot
	nop			;		delay slot
	nop			;		delay slot
	
	;calcPlayer

	dexti	>calcPlayer
	movei	r2,calcPlayer
	gpci	r7,2		
	jmpi	r2,0
	dexti	>playerData	;delay slot
	movei	r0,playerData	;delay slot
	dexti	>lvTMapData	;delay slot
	movei	r1,lvTMapData	;delay slot
	
	;draw map
	
	dexti	>drawMap
	movei	r0,drawMap
	gpci	r7,2		
	jmpi	r0,0
	dexti	>lvTMapData	;		delay slot
	movei	r0,lvTMapData	;		delay slot
	nop			;		delay slot
	nop			;		delay slot
	
	;calcEnemys
	
	dexti	>calcEnemys
	movei	r0,calcEnemys
	gpci	r7,2
	jmpi	r0,0
	dexti	>lvTMapData	;		delay slot
	movei	r1,lvTMapData	;		delay slot
	nop			;		delay slot
	nop			;		delay slot
	
	;drawEnemy
	
	dexti	>drawEnemys
	movei	r0,drawEnemys
	gpci	r7,2
	jmpi	r0,0
	dexti	>lvTMapData	;		delay slot
	movei	r1,lvTMapData	;		delay slot
	nop			;		delay slot
	nop			;		delay slot
	
	;draw title	
	
	dexti	>introBobData	
	movei	r6,introBobData	
	
	dexti	>drawFrame
	movei	r7,drawFrame
	nop
	rqldi	r7,0
	rqldi	r7,1
	nop
	ld	r1	;high
	ld	r2	;low
	nop
	
	ssto	csDestAdrLow
	stwo	r6,r2
	ssto	csDestAdrHigh
	stwo	r6,r1
	
	dexti	>drawBob
	movei	r4,drawBob
	gpci	r7,2		;
	jmpi	r4,0		;
	or	r0,r6,r6	;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot	
	
	;set font
	
	dexti	>drawChar8x8
	movei	r2,drawChar8x8
	
	dexti	>setCharDrawer
	movei	r3,setCharDrawer
	gpci	r7,2
	jmpi	r3,0
	movei	r0,globalFontTwo8x8	;delay slot
	movei	r1,>>globalFontTwo8x8	;delay slot
	moveih	r0,>globalFontTwo8x8	;delay slot
	moveih	r1,>>>globalFontTwo8x8	;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText1	;delay slot
	movei	r1,13		;delay slot
	moveih	r0,>introText1	;delay slot
	movei	r2,15		;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText2	;delay slot
	movei	r1,10		;delay slot
	moveih	r0,>introText2	;delay slot
	movei	r2,17		;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText3	;delay slot
	movei	r1,12		;delay slot
	moveih	r0,>introText3	;delay slot
	movei	r2,18		;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText4	;delay slot
	movei	r1,14		;delay slot
	moveih	r0,>introText4	;delay slot
	movei	r2,19		;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText5	;delay slot
	movei	r1,17		;delay slot
	moveih	r0,>introText5	;delay slot
	movei	r2,21		;delay slot
	
	;text
	
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introText6	;delay slot
	movei	r1,14		;delay slot
	moveih	r0,>introText6	;delay slot
	movei	r2,22		;delay slot
	
	;draw text press enter
	
	dexti	>levelFlickerCounter
	movei	r3,levelFlickerCounter
	nop
	rqldi	r3,0
	nop
	nop
	ld	r0
	nop
	addi	r0,1
	nop
	st	r3,r0

	nop
	extri	r0,4
	brts	introSkipPressEnter
	nop				;delay slot
	nop				;delay slot
	dexti	>drawTextFormated	;delay slot
	movei	r3,drawTextFormated	;delay slot
	
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,introTextPE	;delay slot
	movei	r1,14		;delay slot
	moveih	r0,>introTextPE	;delay slot
	movei	r2,24		;delay slot
	
introSkipPressEnter
	
	;test against enter
	
	dexti	>OURL
	movei	r4,OURL
	nop
	rqldi	r4,0
	nop
	nop
	ld	r4
	nop
	
	extri	r4,5	;enter??
	brtc	introScreenLoop
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	;stop music
	
	dexti	>modStop
	movei	r1,modStop
	gpci	r7,2		;next 4 + X
	jmpi	r1,0		;start
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	;epilog
	
	rqpop
	rqpop
	rqpop
	poparqp	r7
	poparqp	r6
	poparqp	r5
	poparqp	r4
	pop	r3
	pop	r2
	pop	r1
	
	jmpi	r7,0
	nop		;delay slot
	nop		;delay slot	
	nop		;delay slot
	nop		;delay slot

introText1
	.stringz	"PROGRAMMING BY GOLDMOMO"	
introText2
	.stringz	"SFX BY TRACKER, KIVI/EFFECT AND"
introText3
	.stringz	"TWISTER (FOUND VIA INTERNET)"
introText4
	.stringz	"GFX FOUND VIA INTERNET"
introText5
	.stringz	"GREETINGS TO"
introText6
	.stringz	"JIM (FOR GAME IDEA)"		
	
introTextPE
	.stringz	"PRESS ENTER TO START"