;; MIT License
;; 
;; Copyright (c) 2021 capAI / Aitana Devis  Ávila (@AitanaDevis) / Carlos Peñarrubia Morcillo  (@carlospm12) / Pablo Ruiz Ponce (@pabloruizp)
;; 
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; 
;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.
;; 
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.

.include "man/interrupt.h.s"

.globl cpct_disableFirmware_asm
.globl _man_game_logic
.globl cpct_setVideoMode_asm
.globl cpct_setPALColour_asm
.globl _pal_main
.globl _pal_main2
.globl cpct_setPalette_asm
.globl cpct_setInterruptHandler_asm

.area _CODE

_main::
   
   ld sp, #0x8000    ;; CAMBIAMOS LA POSICION DEL STACK
   
   call cpct_disableFirmware_asm    ;; DESABILITAMOS EL FIRMWARE

   ld c, #0
   call cpct_setVideoMode_asm       ;; CAMBIAMOS A MODO 0

   ld hl, #0x1400
   call cpct_setPALColour_asm       ;; SETEAMOS EL FONDO NEGRO
   
   ld hl, #0x1410
   call cpct_setPALColour_asm       ;; PINTAMOS EL BORDE DE NEGRO

   ld hl, #_pal_main2
   ld de, #16                    ;;TAMAÑO DE LA PALETA 
   call cpct_setPalette_asm    ;;SETEAMOS LA PALETA DEL SPRITE DOGGO

  
   ld hl, #0x8000
   ld de, #0x8001
   ld bc, #0x4000-1
   ld (hl), #0
   ldir

   ;;;;;; MUSIC MANAGER ;;;;;;;;
   ld hl, #man_interrupt ;;function that will handle interrupts from now on
   call cpct_setInterruptHandler_asm ;;destroys A, HL
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

   call _man_game_logic
   jr .
   
