;;-----------------------------LICENSE NOTICE------------------------------------
;;  This file is part of Viking Hangover
;;  Copyright (C) 2021 Ahmed Begga / Érika Moreno / Adriana Morejón (@ComputosGame)
;;
;;  This program is free software: you can redistribute it and/or modify
;;  it under the terms of the GNU Lesser General Public License as published by
;;  the Free Software Foundation, either version 3 of the License, or
;;  (at your option) any later version.
;;
;;  This program is distributed in the hope that it will be useful,
;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;  GNU Lesser General Public License for more details.
;;
;;  You should have received a copy of the GNU Lesser General Public License
;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
;;-------------------------------------------------------------------------------

.include "cpctelera.h.s"
.include "menu.h.s"
.include "entity.h.s"
.include "sys/render.h.s"

man_menu_init::

    ;;call cpct_cleanScreen_asm
    call man_entity_init
    call sys_render_init

ret

man_menu_run::

    ;; Pantalla de inicio
    ld      hl, #_screenstart_z_end
    call descompress_image

_first_menu::
    call cpct_scanKeyboard_f_asm

    ld      hl, #Key_Space
    call    cpct_isKeyPressed_asm
    jr      z, _first_menu

_preplay_menu::

    ;; Pantalla de historia
    ld hl, #_screenintro_z_end
    call descompress_image

_wait_C_key:
    call cpct_scanKeyboard_f_asm

    ld hl, #Key_Space
    call cpct_isKeyPressed_asm
    jr nz, _controls_menu

    ld hl, #Key_C
    call cpct_isKeyPressed_asm
    jr z, _wait_C_key

_credits_menu:

    ;; Pantalla de creditos
    ld hl, #_screencredits_z_end
    call descompress_image

    call cpct_scanKeyboard_f_asm

    ld hl, #Key_Space
    call cpct_isKeyPressed_asm
    jr z, _credits_menu
    jp man_menu_run

_controls_menu:

    ;; Pantalla de controles
    ld hl, #_screencontrols_z_end
    call descompress_image

    call cpct_scanKeyboard_f_asm
    ld hl, #Key_Space
    call cpct_isKeyPressed_asm
    jr z, _controls_menu

descompress_image::
    ld de, #0xFFFF
    call cpct_zx7b_decrunch_s_asm
   ret
man_menu_pause::

    ld hl, #_screenpause_z_end
    call descompress_image
_press_key::
    call cpct_scanKeyboard_f_asm

    ;; Presionar espacio para seguir jugando
    ld hl, #Key_Space
    call cpct_isKeyPressed_asm
    jr nz, _pause_space

    ;ld hl, #Key_E
    ;call cpct_isKeyPressed_asm
    jr z, _press_key
    ;ld a, #1                               ;; Salir
    ret

_pause_space:
    ld a, #0                               ;; Continuar
    ret

man_menu_win::

    ld hl, #_screenganador_z_end
    call descompress_image

_wait_for_key_win:

    call cpct_scanKeyboard_f_asm

    ld hl, #Key_H
    call cpct_isKeyPressed_asm
    jr z, _wait_for_key_win
    ret

man_menu_lose::

    ld hl, #_screengameover_z_end
    call descompress_image

_wait_for_key_lose:

    call cpct_scanKeyboard_f_asm

    ld hl, #Key_H
    call cpct_isKeyPressed_asm
    jr z, _wait_for_key_lose
    ret

cpct_cleanScreen_asm::
   ld hl, #0xC000
   ld de, #0xC001
   ld bc, #0x4000    
   ld (hl), #0      
   ldir 
ret