.include "cpctelera.h.s"

;; PANTALLAS MENU 

;; 0 PANTALLA MUERTE
;; 1 START

;; 3 PANTALLA CON OPCIONES

;; 5 CONTROLES
;; 6 CREDITOS


;; MOVIMIENTO  1,-1 solo para pantallas 1,2,3  ;;puls 1arriba, 2abajo

;; ENTER      enter                 ;;puls 3 
;; GO BACK    retroceso             ;;puls 4


pulsacion:: .db 0
salir_menu:: .db 0
pantalla_menu:: .db 1




;;; INPUT PARA EL MENU
keyboard_menu::
    ld a, #0
    ld (pulsacion), a


    call cpct_scanKeyboard_f_asm


    ld a, (pantalla_menu)
    ld b, #2
    cp a,b 
    jr nc, otros_botones

    ld hl, #Key_Return                    ;; EL ENTER SOLO PARA LA PANTALLA PRIMERA
    call cpct_isKeyPressed_asm
    jr z, Enter_not_pressed 

    Enter_pressed:   
        ld a, #4
        ld (pulsacion), a
        ret
    Enter_not_pressed:
    ret


    otros_botones:
    ld a, (pantalla_menu)               ;; COMPROBAR QUE SE ESTA EN UNA DE LAS DE OPCIONES
    ld b, #4
    cp a,b 
    jr nc, op3_not_pressed


    

    call cpct_scanKeyboard_f_asm                                 ;; PANTALLA MENU 
    ld hl, #Key_1
    call cpct_isKeyPressed_asm
    jr z, op1_not_pressed 

    op1_pressed:   
        ld a, #1
        ld (pulsacion), a
        ret
    op1_not_pressed:

    call cpct_scanKeyboard_f_asm
    ld hl, #Key_2
    call cpct_isKeyPressed_asm
    jr z, op2_not_pressed 

    op2_pressed:   
        ld a, #2
        ld (pulsacion), a
        ret
    op2_not_pressed:

    call cpct_scanKeyboard_f_asm
    ld hl, #Key_3                  
    call cpct_isKeyPressed_asm
    jr z, op3_not_pressed 

    op3_pressed:   
        ld a, #3
        ld (pulsacion), a
        ret
    op3_not_pressed:




    call cpct_scanKeyboard_f_asm
    ld hl, #Key_Esc                     ;; EL ESC
    call cpct_isKeyPressed_asm
    jr z, Esc_not_pressed 

    Esc_pressed:   
        ld a, #4
        ld (pulsacion), a
        ret
    Esc_not_pressed:
  

ret



;;; SELECCION DE PANTALLA / O INICIO DE JUEGO

Menu_updt::

    call keyboard_menu  ;; CHEKEAR INPUT

    ld a, (pulsacion)  ;; NO HAY CAMBIOS
    or a
    ret z

    pantallas_arriba_abajo:
    ld a,(pulsacion)
    dec a 
    jr z, star_puls ;; ES 1
    dec a
    jr z, controles_puls  ;; ES 2
    dec a
    jr z, creditos_puls  ;; ES 3
    dec a 
    jr z, volver_menu   ;;; ES 4
    ret

    star_puls:
    ;;; START GAME
    ld a, #1
    ld (salir_menu), a
    call reset_pantalla
    ret

    controles_puls:
    ;;; PAGINA CONTROLES 
    call carga_pantalla_controles
    ret

    creditos_puls:
    ;;; PAGINA CREDITOS
    call carga_pantalla_creditos
    ret
    
    volver_menu:
    ;;; PAGINA MENU
    call carga_pantalla_opciones
    ret





ret





;;;; DIBUJADO DE LAS PANTALLAS DEL MENU


carga_pantalla_victoria::
    ld a, #0
    ld (pantalla_menu),a
    call reset_pantalla
	ld de, #0xFFFF
	ld hl, #_victoria_end	

	call cpct_zx7b_decrunch_s_asm
    ld a, #0
    ld (salir_menu), a
    jp loop_menu



ret



carga_pantalla_opciones::
    ld a, #3
    ld (pantalla_menu),a
    call reset_pantalla
	ld de, #0xFFFF
	ld hl, #_menu_end	

	call cpct_zx7b_decrunch_s_asm


ret


carga_pantalla_controles::
    ld a, #5
    ld (pantalla_menu),a
    call reset_pantalla
	ld de, #0xFFFF
	ld hl, #_controles_end	

	call cpct_zx7b_decrunch_s_asm


ret


carga_pantalla_creditos::
    ld a, #6
    ld (pantalla_menu),a
    call reset_pantalla
	ld de, #0xFFFF
	ld hl, #_creditos_end	

	call cpct_zx7b_decrunch_s_asm


ret



menu_init::
    ld a, #0
    ld (salir_menu), a
    inc a
    ld (pantalla_menu),a
	call reset_pantalla
	ld de, #0xFFFF
	ld hl, #_prinicpal_end

	call cpct_zx7b_decrunch_s_asm
ret



;;; BORRADO DE LA PANTALLA

reset_pantalla::
	;;borro pantalla
  ld de, #0xC000
  ld  a, #0x00
  ld  c, #40
  ld  b, #200

  call cpct_drawSolidBox_asm

  ld de, #0xC028
  ld  a, #0x00
  ld  c, #40
  ld  b, #200

  call cpct_drawSolidBox_asm

   cpctm_setBorder_asm HW_WHITE
  
ret 





