;******************************
;*
;* youHaveWon
;*

youHaveWon

	;prolog

	push	r1
	push	r2
	push	r3
	push	r4
	push	r5
	push	r6
	push	r7

youHaveWonLoop

	;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
	
	;testKeys
	
	dexti	>testKeys
	movei	r4,testKeys
	gpci	r7,2
	jmpi	r4,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot	
		
	;clear draw frame
	
	;draw image	
	
	dexti	>wonBobData	
	movei	r6,wonBobData	
	
	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
	
	;setup char drawer
	
	dexti	>drawChar16x16
	movei	r2,drawChar16x16
	
	dexti	>setCharDrawer
	movei	r3,setCharDrawer
	gpci	r7,2
	jmpi	r3,0
	movei	r0,globalFont16x16	;delay slot
	movei	r1,>>globalFont16x16	;delay slot
	moveih	r0,>globalFont16x16	;delay slot
	moveih	r1,>>>globalFont16x16	;delay slot
		
	;draw text 1	
				
	dexti	>drawTextFormated
	movei	r3,drawTextFormated
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,wonText1		;delay slot
	movei	r1,0			;delay slot
	moveih	r0,>wonText1		;delay slot
	movei	r2,2			;delay slot
	
	;draw text 2	
				
	dexti	>drawTextFormated
	movei	r3,drawTextFormated
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,wonText2		;delay slot
	movei	r1,0			;delay slot
	moveih	r0,>wonText2		;delay slot
	movei	r2,3			;delay slot
	
	;draw text 3	
				
	dexti	>drawTextFormated
	movei	r3,drawTextFormated
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,wonText3		;delay slot
	movei	r1,0			;delay slot
	moveih	r0,>wonText3		;delay slot
	movei	r2,4			;delay slot
	
	;draw text 4	
				
	dexti	>drawTextFormated
	movei	r3,drawTextFormated
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,wonText4		;delay slot
	movei	r1,0			;delay slot
	moveih	r0,>wonText4		;delay slot
	movei	r2,5			;delay slot
	
	;draw text 4	
				
	dexti	>drawTextFormated
	movei	r3,drawTextFormated
	gpci	r7,2		;next 4 + X
	jmpi	r3,0
	movei	r0,wonText5		;delay slot
	movei	r1,0			;delay slot
	moveih	r0,>wonText5		;delay slot
	movei	r2,7			;delay slot
	
	;draw text press space
	
	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	skipTextWon
	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,textPressEnter	;delay slot
	movei	r1,0		;delay slot
	moveih	r0,>textPressEnter	;delay slot
	movei	r2,9		;delay slot
	
skipTextWon	
		
	;test against enter
	
	dexti	>OURL
	movei	r4,OURL
	nop
	rqldi	r4,0
	nop
	nop
	ld	r4
	nop
	
	extri	r4,5	;enter??
	brtc	youHaveWonLoop
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	nop		;delay slot
	
	;wait for release enter
	
	
wonWaitForReleaseEnter
	
	;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
	
	;testKeys
	
	dexti	>testKeys
	movei	r4,testKeys
	gpci	r7,2
	jmpi	r4,0
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	nop			;delay slot
	
	;test against enter
	
	dexti	>OURL
	movei	r4,OURL
	nop
	rqldi	r4,0
	nop
	nop
	ld	r4
	nop
	
	extri	r4,5	;enter??
	brts	wonWaitForReleaseEnter
	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
	
; ;******************************
; ;*
; ;* youLoose
; ;*

; youLoose

	; ;prolog

	; push	r1
	; push	r2
	; push	r3
	; push	r4
	; push	r5
	; push	r6
	; push	r7

; youLooseLoop

	; ;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
	
	; ;testKeys
	
	; dexti	>testKeys
	; movei	r4,testKeys
	; gpci	r7,2
	; jmpi	r4,0
	; nop			;delay slot
	; nop			;delay slot
	; nop			;delay slot
	; nop			;delay slot	
		
	; ;clear draw frame
	
	; dexti	>drawFrame
	; movei	r4,drawFrame
	; nop
	; rqldi	r4,1
	; rqldi	r4,0
	; nop
	; ld	r2	;low
	; ld	r3	;high
	
	; dexti	>efill8
	; movei	r4,efill8
	; gpci	r7,2
	; jmpi	r4,0
	; dexti	$2b		;delay slot
	; movei	r0,$10		;delay slot
	; movei	r1,0		;delay slot
	; nop			;delay slot
	
	; ;setup char drawer
	
	; dexti	>drawChar16x16
	; movei	r2,drawChar16x16
	
	; dexti	>setCharDrawer
	; movei	r3,setCharDrawer
	; gpci	r7,2
	; jmpi	r3,0
	; movei	r0,globalFont16x16	;delay slot
	; movei	r1,>>globalFont16x16	;delay slot
	; moveih	r0,>globalFont16x16	;delay slot
	; moveih	r1,>>>globalFont16x16	;delay slot
		
	; ;draw text 1	
				
	; dexti	>drawTextFormated
	; movei	r3,drawTextFormated
	; gpci	r7,2		;next 4 + X
	; jmpi	r3,0
	; movei	r0,looseText1		;delay slot
	; movei	r1,0			;delay slot
	; moveih	r0,>looseText1		;delay slot
	; movei	r2,2			;delay slot
	
	; ;draw text 2	
				
	; dexti	>drawTextFormated
	; movei	r3,drawTextFormated
	; gpci	r7,2		;next 4 + X
	; jmpi	r3,0
	; movei	r0,looseText2		;delay slot
	; movei	r1,0			;delay slot
	; moveih	r0,>looseText2		;delay slot
	; movei	r2,3			;delay slot
	
	; ;draw text 3	
				
	; dexti	>drawTextFormated
	; movei	r3,drawTextFormated
	; gpci	r7,2		;next 4 + X
	; jmpi	r3,0
	; movei	r0,looseText3		;delay slot
	; movei	r1,0			;delay slot
	; moveih	r0,>looseText3		;delay slot
	; movei	r2,4			;delay slot
	
	; ;draw text 4				
				
	; dexti	>drawTextFormated
	; movei	r3,drawTextFormated
	; gpci	r7,2		;next 4 + X
	; jmpi	r3,0
	; movei	r0,looseText4		;delay slot
	; movei	r1,0			;delay slot
	; moveih	r0,>looseText4		;delay slot
	; movei	r2,7			;delay slot
	
	; ;draw text press space
	
	; 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	skipTextLoose
	; 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,textPressEnter	;delay slot
	; movei	r1,0		;delay slot
	; moveih	r0,>textPressEnter	;delay slot
	; movei	r2,9		;delay slot
	
; skipTextLoose	
		
	; ;test against space
	
	; dexti	>OURL
	; movei	r4,OURL
	; nop
	; rqldi	r4,0
	; nop
	; nop
	; ld	r4
	; nop
	
	; extri	r4,5	;enter??
	; brtc	youLooseLoop
	; 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	

	;WON
	
wonText1
	.stringz	"        YOU WON!"	
wonText2
	.stringz	"  THAT WAS IMPOSSIBLE"
wonText3
	.stringz	"     BUT YOU! HAVE"
wonText4
	.stringz	"  KILLED ALL BAD GUYS!"
wonText5
	.stringz	" NOW YOU RULE THE WORLD!"
	
	;YOU LOOSE
	
; looseText1
	; .stringz	"      YOU ARE DEAD!"	
; looseText2
	; .stringz	"   YOU CANT STOP THE"
; looseText3
	; .stringz	"  CRIME ON THIS PLANET"

; looseText4
	; .stringz	"       TRY AGAIN"
	
textPressEnter	
	.stringz	"      PRESS ENTER"