SelectLevel:
// GRAPHICS 0
        LDA        #16 // Mode graphique 5 + 16
        JSR GRAPHICS

// Effacement du curseur
        lda        560
	clc
	adc 	   #32
        sta        $e6
        lda        561
	adc	   #0
        sta        $e7

	lda	#0
	sta	($e6),y

// Puis affichage du menu
	jsr PrintMenuPrinc

	jmp DrawSelect

waitSelect:
	lda	753
	cmp	#0
	beq tsttouchespe
	jmp trtclavier

tsttouchespe:
	lda	53279
	cmp	#7
	beq waitSelect

	cmp 	#6
	bne tSelect
	jmp FinSelect

tSelect:
	cmp	#5
	beq DrawSelect
 	jmp waitSelect
DrawSelect
	ldx	level
	cpx	#1
	bne tstlevel2
	jmp level2
tstlevel2:
	cpx	#2	
	bne tstlevel3
	jmp level3
tstlevel3:
	cpx	#3
	bne tstlevel4
	jmp level4
tstlevel4:
	jmp level1

level2:
	lda        560
	clc
	adc 	   #57+87
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message2&255
        sta        $e8
        lda        #message2/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #184
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message3&255
        sta        $e8
        lda        #message3/256
        sta        $e9

	jsr printinv
	jmp levelX1

level3:
       lda        560
	clc
	adc 	   #184
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message3&255
        sta        $e8
        lda        #message3/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #224
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message4&255
        sta        $e8
        lda        #message4/256
        sta        $e9

	jsr printinv
	jmp levelX1

level4:
        lda        560
	clc
	adc 	   #224
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message4&255
        sta        $e8
        lda        #message4/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #8
        sta        $e6
        lda        561
	adc	   #2
        sta        $e7 

        lda        #message5&255
        sta        $e8
        lda        #message5/256
        sta        $e9

	jsr printinv
	jmp levelX1

level1:
        lda        560
	clc
	adc 	   #8
        sta        $e6
        lda        561
	adc	   #2
        sta        $e7 

        lda        #message5&255
        sta        $e8
        lda        #message5/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #57+87
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message2&255
        sta        $e8
        lda        #message2/256
        sta        $e9

	jsr printinv

	ldx	#1
	stx	level
	jmp waitlevelX

levelX1:
	ldx	level
	inx
	stx	level

waitlevelX:
	lda	53279
	cmp	#7
	bne waitlevelX
	jmp waitSelect

FinSelect:
	lda	53279
	cmp	#7
	bne FinSelect

	jsr initlevel

	rts

trtclavier:
	lda	764
	cmp	#31
	beq	cllevel1
	cmp	#30
	beq 	cllevel2
	cmp	#26
	beq	cllevel3
	cmp	#24
	bne	finTrtclLevel
	jmp cllevel4
finTrtclLevel
	jmp waitSelect

cllevel1:
	lda	level
	cmp	#1
	bne cltrtlevel1
	jmp waitSelect
cltrtlevel1:
	jsr PrintMenuPrinc
        lda        560
	clc
	adc 	   #57+87
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message2&255
        sta        $e8
        lda        #message2/256
        sta        $e9

	jsr printinv

	ldx	#1
	stx	level
	jmp waitSelect

cllevel2:
	lda	level
	cmp	#2
	bne cltrtlevel2
	jmp waitSelect
cltrtlevel2:
	jsr PrintMenuPrinc

        lda        560
	clc
	adc 	   #184
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message3&255
        sta        $e8
        lda        #message3/256
        sta        $e9

	jsr printinv

	ldx	#2
	stx	level
	jmp waitSelect

cllevel3:
	lda	level
	cmp	#3
	bne cltrtlevel3
	jmp waitSelect
cltrtlevel3:
	jsr PrintMenuPrinc

        lda        560
	clc
	adc 	   #224
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message4&255
        sta        $e8
        lda        #message4/256
        sta        $e9

	jsr printinv

	ldx	#3
	stx	level
	jmp waitSelect

cllevel4:
	lda	level
	cmp	#4
	bne cltrtlevel4
	jmp waitSelect
cltrtlevel4:
	jsr PrintMenuPrinc

        lda        560
	clc
	adc 	   #8
        sta        $e6
        lda        561
	adc	   #2
        sta        $e7 

        lda        #message5&255
        sta        $e8
        lda        #message5/256
        sta        $e9

	jsr printinv

	ldx	#4
	stx	level
	jmp waitSelect

PrintMenuPrinc:
// Puis affichage du menu
        lda        560
	clc
	adc 	   #57 
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message1&255
        sta        $e8
        lda        #message1/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #57+87
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message2&255
        sta        $e8
        lda        #message2/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #184
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message3&255
        sta        $e8
        lda        #message3/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #224
        sta        $e6
        lda        561
	adc	   #1
        sta        $e7

        lda        #message4&255
        sta        $e8
        lda        #message4/256
        sta        $e9

	jsr print

        lda        560
	clc
	adc 	   #8
        sta        $e6
        lda        561
	adc	   #2
        sta        $e7 

        lda        #message5&255
        sta        $e8
        lda        #message5/256
        sta        $e9

	jsr print
	rts

/******************************************************/
/* Imprime un texte dont la fin est indiquee par 0    */
/* e6,e7 pointe sur l'ecran			      */
/* e8,e9 pointe sur le debut du texte                 */
/******************************************************/

print:
	ldy	#0
bclprint:
	lda	($e8),y
	cmp	#0
	beq fprint
	sec
	sbc	#32
	sta	($e6),y
	iny
	jmp bclprint
fprint:
	rts

printinv:
	ldy	#0
bclprintinv:
	lda	($e8),y
	cmp	#0
	beq fprintinv
	clc
	adc	#96
	sta	($e6),y
	iny
	jmp bclprintinv
fprintinv:
	rts

initlevel:
	ldx	level
	cpx	#1
	beq initlevel1
	cpx	#2
	beq initlevel2
	cpx	#3
	beq initlevel3
	jmp initlevel4

initlevel1:
	ldx #5
	stx levDrwCptG
	ldx #6
	stx levDrwCptD
	ldx	#7
	stx levTailleRoute
	ldx	#0
	stx levVoituresadv
	rts

initlevel2:
	ldx #5
	stx levDrwCptG
	ldx #6
	stx levDrwCptD
	ldx	#7
	stx levTailleRoute
	ldx	#1
	stx levVoituresadv
	rts

initlevel3:
	ldx #6
	stx levDrwCptG
	ldx #7
	stx levDrwCptD
	ldx	#5
	stx levTailleRoute
	ldx	#1
	stx levVoituresadv
	rts

initlevel4:
	ldx #5
	stx levDrwCptG
	ldx #6
	stx levDrwCptD
	ldx	#7
	stx levTailleRoute
	ldx	#1
	stx levVoituresadv
	rts


level   db 4

levDrwCptG		db 5
// Taille de la pelouse a droite de la route
levDrwCptD		db 6
// Taille de la route
levTailleRoute	db 7
levVoituresadv  db 0

message1 db "SELECTIONNEZ LE NIVEAU DE DIFFICULTE:", 0
message2 db "- 1 - PROMENADE PEPERE...", 0
message3 db "- 2 - QUELQUES VOITURES...", 0
message4 db "- 3 - ROUTES ETROITES.", 0
message5 db "- 4 - PONTS COUPES !", 0