;;-----------------------------LICENSE NOTICE------------------------------------
;;  This file is part of CPCtelera: An Amstrad CPC Game Engine 
;;  Copyright (C) 2018 ronaldo / Fremos / Cheesetea / ByteRealms (@FranGallegoBR)
;;
;;  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_functions.h.s"
.include "cpctelera.h.s"
.include "man/entity_manager.h.s"
.include "sys/render_system.h.s"
.include "sys/input_system.h.s"
.include "sys/physics_system.h.s"
.include "man/game_manager.h.s"
.include "man/interrupciones.h.s"


.area _DATA




.area _CODE

uncontador: .db 06
int_handler:
      push  af
      push  bc
      push  de
      push  hl

      ld    a, (uncontador)
      dec   a
      jr    nz, _cont
_zero:
      ;;cpctm_setBorder_asm HW_BRIGHT_WHITE
      call  cpct_akp_musicPlay_asm
      ld    a, #6
_cont:
      ld    (uncontador), a

      ld    h, a
      ld    l, #16
      ;;call cpct_setPALColour_asm

      pop  hl
      pop  de
      pop  bc
      pop  af

      ei
      reti

set_int_handlerMain:
      call cpct_waitVSYNC_asm
      halt
      halt
      call cpct_waitVSYNC_asm

      ld    hl, #0x38
      ld    (hl), #0xC3
      inc   hl
      ld    (hl), #<int_handler
      inc   hl
      ld    (hl), #>int_handler
      inc   hl
      ld    (hl), #0xC9


      ret   

.globl _menu_song


;; Definimos las entidades que vamos a usar

_main::

      ;;ld    sp, #0x8000
      call     set_int_handlerMain

      ;;call     render_system_initBuffers
      ;;call    set_int_handler
      ld    de, #_menu_song
      call cpct_akp_musicInit_asm
      call    render_system_menu
      ;; Inicializamos los sistemas de render
      
      call    game_manager_init_systems
      call    game_manager_init_entities

      ;; Inicializamos las entidades
      call   game_manager_playGame
