; --------------------------------------------------------------------------------------------
;| File made by Paxl for ZC
;| Last Mod : 26 december 1999
;| Rem: Thx to tcpa for therse routine
; --------------------------------------------------------------------------------------------
;####################################
;#### Menu dns le jeu!!!
inGameMenu:
	ld	hl,plotsscreen		; \Turn all screen Black
	ld	(hl),11111111b		;  |
	ld	de,plotsscreen+1	;  |
	ld	bc,767			;  |
	ldir				; /
	
;	ld	hl,$0505
;	ld	de,$5B05
;	call	fastlinew
	
;	ld	hl,$5C06
;	ld	de,$5C3A
;	call	fastlinew
	
;	ld	hl,$053B
;	ld	de,$5B3B
;	call	fastlinew
	
;	ld	hl,$0406
;	ld	de,$043A
;	call	fastlinew

	call	fastcopy

	set	3,(iy+$05)
	
	ld	hl,YourCashStr
	ld	de,$0606
	call	setvputs
	
	ld	hl,$0635
	ld	(pencol),hl
	ld	hl,(cash)
	call	vputshl

	ld	hl,InGameMenuStr
	call	Text_Select_Menu
	or	a	\	jp	z,SaveGame
	dec	a	\	ret	z
	dec	a	\	jp	z,SaveGame
	
;#####################################
;#######Ouverture d'un petit menu oui/non
; Ver 1.0
; Input:
;	
;	DE -= Position de la boite du menu
; Output:  a =
;	0 (non)
;	1 (oui)
YesNoMenu:
	ld	(tmpaddr),hl
	ld	b,3
	call	delayb
	push	de
	ld	l,e
	ld	h,12
	bcall(_htimesl)
	ex	de,hl
	ld	hl,plotsscreen
	add	hl,de
	ld	b,6*12
YNLoop: 
	ld	a,%11111111
	ld	(hl),a
	inc	hl
	djnz 	YNLoop
	set	3,(iy+05h)		; Textinverse
	pop	de
	push	de
;	ld	hl,YesNoMenuStr
	ld	hl,(tmpaddr)		;tmp stored place
	ld	d,e
	ld	e,$00
	set	7,(iy+14h)		; TextWrite
	call	setvputs
	ld	e,$30
	call	setvputs
	res	3,(iy+05h)		; Textinverse
	call	Grbufbackup
	jr	YesHilithe
OptionHilithe:
	ld	hl,plotsscreen
	add	hl,de	
	ld	de,0006h
	ld	b,6
OptionHilitheOuterLop:	
	ld	c,b
	ld	b,6
OptionHilitheLop:
	ld	a,(hl)
	cpl
	ld	(hl),a
	inc	hl
	djnz	OptionHilitheLop

	ld	b,c
	add	hl,de
	djnz	OptionHilitheOuterLop		
YesNoMenuKeyLoop:
	call	fastcopy
	call	D_I_Waitkey
	cp	0FEh
	jr	z,YesNoMenuLeftRight
	cp	0BFh
	jr	z,YesNoMenu2nd
	cp	0FDh
	jr	z,YesNoMenuXit
	jr	YesNoMenuKeyLoop
YesNoMenuLeftRight:
	ld	a,c
	cp	0FDh
	jr	z,YesHilithe
	cp	0FBh
	jr	z,NoHilithe
	jr	YesNoMenuKeyLoop
YesHilithe:
	ld	a,1
	ld	(option),a
	call	Grbufresbackup
	pop	de
	push	de
	ld	l,e
	ld	h,12
	bcall(_htimesl)
	ld	de,0006h
	add	hl,de
	ex	de,hl
	jr	OptionHilithe
NoHilithe:
	xor	a
	ld	(option),a
	call	Grbufresbackup
	pop	de
	push	de
	ld	l,e
	ld	h,12
	bcall(_htimesl)
	ex	de,hl
	jr	OptionHilithe
YesNoMenuXit:
	ld	a,c
	cp	0BFh
	jp	z,quittoShell
	jr	YesNoMenuKeyLoop
YesNoMenu2nd:
	ld	a,c
	cp	$DF		; cp 2nd
	jr	z,YesNoMenu2ndPress
	jr	YesNoMenuKeyLoop
YesNoMenu2ndPress:
	pop	de
	res	7,(iy+14h)		; TextWrite
	ld	a,(option)
	ret		
;----------------Next routine are by TCPA	
Direct_Input:				; Thx to TCPA For this routine
        ld a, 0FFh
        out (1), a
       ld a, b
       out (1), a
        in a, (1)
        ret
D_I_Waitkey: ld a, 254
D_I_Loop: ld b, a \ ld c, a
       call Direct_Input
       cp 255 \ jr nz, D_I_Key
        ld a, c \ RLCA
        cp 127 \ jr z, D_I_Waitkey
        jr D_I_Loop
D_I_Key: EI \ ld c, a
D_I_Key_Loop:
        halt \ call Direct_Input
        cp c \ jr z, D_I_Key_Loop
        ld a, b \ ret

;----------------(Text_Select_Menu Routine v3.3)----------------;
; Input:  HL -> Data_Table. The Data Required is Located Below. ;
;         Arrow Keys Move Cursor, and Enter Selects the String. ;
; Output: D = Number Of Selections. A and E = Selection Number. ;
;         If Clear Was Pressed During this Routine, Then A = 0. ;
; Subroutines Required: D_I_Waitkey, and Direct_Input Routines. ;
; Registers Destroyed:  AF, BC, DE, & HL. Text Video is Normal. ;
;---------------------------------------------------------------;
; Data_Table:            ;Example of the Data for this Routine. ;
;    .db 2               ;Number of Strings Selections in Menu. ;
;    .db 20,20           ; (X,Y) Coordinates of the 1st String. ;
;    .db " String 1",0   ;1st Zero-Terminated String Selection. ;
;    .db 20,27           ; (X,Y) Coordinates of the 2nd String. ;
;    .db " String 2",0   ;2nd Zero-Terminated String Selection. ;
;     and so on...       ; Any Number of Strings Can Be Used... ;
;---------------------------------------------------------------;

Text_Select_Menu:
        ld c, (hl) \ ld e, c
Cont_Text_Select:
        ld c, e
        ld b, (hl) \ push bc
        push hl \ inc hl
Text_Select_Loop:
        ld a, c
        cp b \ jr nz, Text_Dont_Highlight
        RES textinverse, (IY+textflags)			; Set
Text_Dont_Highlight:
        ld e, (hl) \ inc hl
        ld d, (hl) \ inc hl
        ld (pencol), de
        push bc \ bcall(_vputs) \ pop bc
        SET textinverse, (IY+textflags)
        DJNZ Text_Select_Loop
        pop hl \ pop bc
        ld d, b \ ld e, c 
Text_Select_Getkey:
        call D_I_Waitkey
        cp 0FEh \ jr z, Text_Arrow_Keys
        cp 0FDh \ jr z, Text_Clear
        cp 0BFh \ jr z, Text_Enter
        jr Text_Select_Getkey
Text_Arrow_Keys: ld a, c
        cp 254 \ jr z, Text_Decrease_E
        cp 253 \ jr z, Text_Increase_E
        cp 251 \ jr z, Text_Decrease_E
        cp 247 \ jr z, Text_Increase_E
        jr Text_Select_Getkey
Text_Clear: ld a, c
        cp 191 \ jr nz, Text_Select_Getkey
        xor a \ ret
Text_Enter: ld a, c
        cp $DF \ jr z, Text_Selection_Made
	jr Text_Select_Getkey	
Text_Selection_Made:
        ld a, d \ sub e
        inc a \ ld e, a \ ret
Text_Increase_E:
        ld a, e \ cp d
        jr z, Text_Select_Getkey
        inc e \ jr Cont_Text_Select
Text_Decrease_E:
        ld a, e \ cp 1
        jr z, Text_Select_Getkey
        dec e \ jr Cont_Text_Select

; Example Of How To Use This Routine:
;
;       ld hl, Data_Table_1
;       call Text_Select_Menu
;       or a
;       jp z, Exit_Program
;       cp 1
;       jp z, First_Selection
;       cp 2
;       jp z, Second_Selection
;       ...
; Data_Table_1:
;       .db 2
;       .db 50,32
;       .db " ONE PLAYER",0
;       .db 50,39
;       .db " TWO PLAYERS",0
;
; NOTE: Some suggestions for this routine that do not affect its
; functionality is that you "SET textEraseBelow, (IY+textflags)"
; some time before the routine, because that will include the
; line below the text when it highlights the string in Reverse
; Video, and it just looks better. Remember to Reset that flag
; before exiting your program also. Another thing is that you
; put One space in front of the strings you want to be in the 
; Menu, because this also makes it look better when highlighting.
; This is demonstrated in the Example Data Table located above.
;
; --------------------------------------------------------------
;
; These routines were created and organized by Jason Kovacs, but
; Thanks go out to Dan Englender, Matthew Landry, David Clamage,
; Linus Akkeson, David Phillips, and Jeremy Goetsch for various
; contributions to the completion of these routines... =)
;
; These routines have been tested so we dont release Crap to the
; TI Community, but the TCPA and I take no responsibility for any
; Misuse of the routines, which may at most cause your calculator
; to crash and lose its programs temporarily. Also, please do not
; alter and redistribute these routines, but any suggestions for
; slightly improving their functionality are welcomed. Questions,
; Concerns, or any other Comments can be mailed to Jkhum98@aol.com
;
; ----------------------------------------------------------------
; June 12th, 1999 (c) TI-Calculator Programming Alliance [TCPA]
; ----------------------------------------------------------------
.end
