; ; ; ; MIT License
; ; ; ; 
; ; ; ; Copyright (c) 2021 Ramiro Hernán García Iten / Raúl Ripoll Pérez / Alexandru Marius Cozma
; ; ; ; 
; ; ; ; 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.

; ; ; ; ----------------- AUTHORS ------------------
; ; ; ;     Ramiro Hernán García Iten: rhgi1@alu.ua.es
; ; ; ;     Raúl Ripoll Pérez: rrp42@alu.ua.es
; ; ; ;     Alexandru Marius Cozma: amc246@alu.ua.es
; ; ; ; 
; ; ; ; Art by Sara Alfosea - IG: @Slinfir
; ; ; ; ---------------------------------------------

; ; ; ; Third Party source code used
; ; ; ; ----------------------------
; ; ; ; CPCtelera - owned by ronaldo / (Cheesetea, Fremos, ByteRealms) - GNU Lesser General Public License.


;;-----------------------------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.h.s"

;;; ==========================================
;;; ==========================================
;;; TRANSITIONS COMPONENT
;;; ==========================================
;;; ==========================================

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FUNCIONES QUE HACEN TRANSICIONES A OTRO COLOR O PALETA ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Vacía la memoria de vídeo (la pone a 0)
; Modifica: HL
clearVideoMemory:
   ld    de, #1
   ld    hl, #0xC000
 loop_vm:
   ld    (hl), #0
   adc   hl, de      ; Usamos adc para forzar el valor del bit Z
   jr    nz, loop_vm
   ret

; Cambia el color del borde
; Parámetros de entrada
;     C: Color (Hard+Command = Color original + 64)
;
; Modifica: HL
setBorder:
   ld    l, #0x10
   ld    h, c
   call  cpct_setPALColour_asm
   ret

; Cambia TODA la pantalla a un color concreto
; Parámetros de entrada
;     C: Color (Hard+Command = Color original)
;
; Modifica: AF, BC, HL 
transition_inmediate::
   call  setBorder
   
   ; Cambiamos la paleta para hacer una transición inmediata
   ld    a, #4
 loop_i:
      dec   a
      out   (c), a
      out   (c), c
   jr    nz, loop_i

   ; Vaciamos la memoria de vídeo para luego escribir en ella
   call  clearVideoMemory

   ret

; Cambia TODA la pantalla a un color concreto por capas
; Parámetros de entrada
;     C: Color (Hard+Command = Color original + 64)
;
; Modifica: AF, BC, HL 
transition_layers::
   ; Cambiamos el color del borde
   call  setBorder

   ; Cambiamos la paleta progresivamente
   ld    d, #0     ; Contador colores paleta modo 0
   ld    b, #0x4B  ; Contador de halts | 0x4B = 0,25s
 loop_l:
      out   (c), d
      out   (c), c
      inc   d

      ; Llamamos a tantos halts como B indique
      call  cpct_waitHalts_asm
      ld    b, #0x4B  ; Restablecemos el contador de halt's

      ld    a, #4   ; Comprobamos si hemos llegado a 4
      sub   d
   jr    nz, loop_l

   ; Vaciamos la memoria de vídeo para luego escribir en ella
   call  clearVideoMemory
   ret

; Cambia la paleta de forma gradual
; Parámetros de entrada
;     HL: Puntero a la paleta
;
; Modifica: AF, BC, HL 
transition_layers_toPallete::
   ld    d, #0     ; Contador colores paleta modo 0
   ld    b, #0x4B  ; Contador de halts | 0x4B = 0,25s

 loop_ltp:
      out   (c), d     ; Mandamos la posición que actualizar
      ld    a, (hl)    ; Cargamos el color
      add   #0x40      ; Le sumamos el comando (0x40 == 64)
      out   (c), a     
      inc   hl         ; Apuntamos a +1 en el array

      call  cpct_waitHalts_asm
      ld    b, #0x4B  ; Restablecemos el contador de halt's

      inc   d
      ld    a, #4     ; Comprobamos si hemos cargado los 4 números
      sub   d
   jr    nz, loop_ltp

   ret

; Cambia TODA la pantalla a un color concreto por barras (aprovechando el dibujado por pantalla)
; Parámetros de entrada
;     C: Color (Hard+Command = Color original + 64)
; Modifica: HL
transition_bars::
   ; Cambiamos el color del borde
   call  setBorder
   ; Vaciamos la memoria de vídeo para luego escribir en ella
   call  clearVideoMemory
   ret
