;;-----------------------------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 "render.h.s"
.include "man/entity.h.s"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;      Init the render                                  ;;
;;Required:                                              ;;
;;     -                                                 ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_render_init::
    ld c, #0
    call cpct_setVideoMode_asm
    cpctm_setBorder_asm HW_WHITE

    ld l, #0
    ld h, #HW_BLACK
    call cpct_setPALColour_asm

    ld   hl, #_main_palette
    ld   de, #16
    call cpct_setPalette_asm

    ld hl, #0x000F
    call cpct_setDrawCharM0_asm
    cpctm_clearScreen_asm 0

   ld de, #0xC000
   ld c, #32
   ld b, #185
   call cpct_getScreenPtr_asm

ret


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;      Create the array of  entities                    ;;
;;Required:                                              ;;
;;     IX -> Initial position of the first entity        ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_render_update_one::
    ld b, #type_static
    ld a, e_subType(ix)
    and b

    jp nz, _notdel
    call sys_render_delete

    _notdel:
    ld h, e_currentpos1(ix)
    ld l, e_currentpos2(ix)
    ex de, hl
    
    ld b, e_h(ix)
    ld c, e_w(ix)
    ld h, e_sprite1(ix)
    ld l, e_sprite2(ix)
    call cpct_drawSprite_asm
    

ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;      Draw some entities that can be draw and clean the;;
;;      previous pos                                     ;;
;;Required:                                              ;;
;;     IX -> Initial position of the first entity        ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_render_draw_once::
    ld c, e_x(ix)
    ld b, e_y(ix)
    ld de, #0xC000
    call cpct_getScreenPtr_asm
    ex de, hl
    ld h, e_sprite1(ix)
    ld l, e_sprite2(ix)
    ld b, e_h(ix)
    ld c, e_w(ix)
    

    call cpct_drawSprite_asm

ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;      Draws the score                                  ;;
;;Required:                                              ;;
;;     -                                                 ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_render_update::
    ld a, #e_cmp_render
    ld hl, #sys_render_update_one
    call man_entity_forall
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Description:                                           ;;                                                          
;;      Draws a square to delete                         ;;
;;Required:                                              ;;
;;     IX -> Position of the entity                      ;;  
;; Return:                                               ;;                                                  
;;     -                                                 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
sys_render_delete::
    ld a, #0
    ld b, e_h2rmv(ix)
    ld c, e_w2rmv(ix)
    ld d, e_prevPos1(ix)
    ld e, e_prevPos2(ix)
    call cpct_drawSolidBox_asm
ret