; ##-----------------------------LICENSE NOTICE------------------------------------
; ##  This file is part of Hacktank
; ##
; ##  Hacktank 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.
; ##
; ##  Hacktank 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 Hacktank.  If not, see <http://www.gnu.org/licenses/>.
; ##------------------------------------------------------------------------------

;.area _DATA
;.area _CODE
;.include "cpctelera.h.s"
;.include "pj.h.s"
.include "main.h.s"
.include "cpctelera.h.s"
.include "pj.h.s"
;.include "main.h.s"
;.include "bala.h.s"
;.include "render.h.s"
;;;;;;;;;;;;;;;hud;niveles;colision personaje;destruccion balas tiempo
m_front_buffer: .db 0xC0
m_back_buffer: .db 0x80
ren_newScene:
  call switch
  call ren_clarBackbuffer
ret
destroy:
call cleartotal
  ;call ren_clear1
  ;call ren_clearO
ret
cleartotal:



ld a,de_antx(ix)
ld c,a
cp a,de_x(ix)
jp c,yax
ld c,de_x(ix)
yax:
ld a,de_anty(ix)
ld b,a
cp a,de_y(ix)
jp c,yay
ld b,de_y(ix)
yay:

;ld a,(m_back_buffer)
;ld d,a
;ld e,#0      ;;Comienzo memoria de video
ld de,#0x8000
call cpct_getScreenPtr_asm


;gauntlet
ex    de, hl   ;; DE = Puntero a memoria

;ld  a, de_col(ix)   ;; Color
ld  a, #0x00   ;; Color
ld  b, de_h(ix)   ;; alto
inc b
inc b
inc b
inc b

ld  c, de_w(ix)    ;; Ancho
inc c
push de
push bc
call cpct_drawSolidBox_asm
pop bc
pop de
ld a,d
add a,#0x40
ld d,a
ld a,#0
call cpct_drawSolidBox_asm


;call ren_clear1
;call ren_clearO

ret
ren_clearO:

  ld a,(m_back_buffer)
  ld d,a
  ld e,#0      ;;Comienzo memoria de video
  ld     c, de_antx(ix)        ;; C = Entity Y
  ld     b, de_anty(ix)         ;; B = Entity X
  call cpct_getScreenPtr_asm

  ;gauntlet
  ex    de, hl   ;; DE = Puntero a memoria
  ;ld  a, de_col(ix)   ;; Color
  ld  a, #0x00   ;; Color
  ld  b, de_h(ix)   ;; alto
  ld  c, de_w(ix)    ;; Ancho

  call cpct_drawSolidBox_asm

  ;ld a,(m_back_buffer)
  ;ld d,a
  ;ld e,#0      ;;Comienzo memoria de video
  ;ld     c, de_x(ix)        ;; C = Entity Y
  ;ld     b, de_y(ix)         ;; B = Entity X
  ;call cpct_getScreenPtr_asm

  ;;gauntlet
  ;ex    de, hl   ;; DE = Puntero a memoria
  ;;ld  a, de_col(ix)   ;; Color
  ;ld  a, #0x00   ;; Color
  ;ld  b, de_h(ix)   ;; alto
  ;ld  c, de_w(ix)    ;; Ancho

  ;call cpct_drawSolidBox_asm
  ;call ren_clear1

  ld    a, de_y(ix)
  ld de_anty(ix),a
  ld    a, de_x(ix)
  ld de_antx(ix),a
ret
ren_clear1:

  ld a,(m_front_buffer)
  ld d,a
  ld e,#0      ;;Comienzo memoria de video
  ld     c, de_x(ix)        ;; C = Entity Y
  ld     b, de_y(ix)         ;; B = Entity X
  call cpct_getScreenPtr_asm

  ;gauntlet
  ex    de, hl   ;; DE = Puntero a memoria
  ;ld  a, de_col(ix)   ;; Color
  ld  a, #0x00   ;; Color
  ld  b, de_h(ix)   ;; alto
  ld  c, de_w(ix)    ;; Ancho

  call cpct_drawSolidBox_asm
  ;ld a,(m_front_buffer)
  ;ld d,a
  ;ld e,#0      ;;Comienzo memoria de video
  ;ld     c, de_antx(ix)        ;; C = Entity Y
  ;ld     b, de_anty(ix)         ;; B = Entity X
  ;call cpct_getScreenPtr_asm

  ;;gauntlet
  ;ex    de, hl   ;; DE = Puntero a memoria
  ;;ld  a, de_col(ix)   ;; Color
  ;ld  a, #0x00   ;; Color
  ;ld  b, de_h(ix)   ;; alto
  ;ld  c, de_w(ix)    ;; Ancho

  ;call cpct_drawSolidBox_asm

  ;call ren_clear1


ret
ren_clarBackbuffer:
  ld a,(m_back_buffer)
  ld h,a
  ld l,#0
  ld d,a
  ld hl,#0x8000
  ld (hl),#0

  ld de,#0x8000+1
  ld bc,#0x4000-1
  ldir
ret
switch:
  ld a,(m_back_buffer)
  ld b,a
  ld a,(m_front_buffer)
  ld (m_back_buffer),a
  ld a,b
  ld (m_front_buffer),a

  srl b
  srl b
  ld l,b
  jp cpct_setVideoMemoryPage_asm

reset_pantalla:
  ld   hl, #_level0
  push hl
  ld   hl, #0xC000
  push hl
  ld   bc, #0000
  ld   de, #0x3228
  ld    a, #40
  call cpct_etm_drawTileBox2x4_asm

  ld   hl, #_level0
  push hl
  ld   hl, #0x8000
  push hl
  ld   bc, #0000
  ld   de, #0x3228
  ld    a, #40
  call cpct_etm_drawTileBox2x4_asm

ret

ren_drawEntity:
   ;ld    de, #0xC000       ;;Comienzo memoria de video
   ld a,(m_back_buffer)
   ld d,a
   ld e,#0

   ld     c, de_x(ix)         ;; C = Entity Y
   ld     b, de_y(ix)         ;; B = Entity X
   call cpct_getScreenPtr_asm

   ex    de, hl   ;; DE = Puntero a memoria
   ld  b, de_h(ix)   ;; alto
   ld  c, de_w(ix)   ;; Ancho
   ;;ld bc, #0x0C04     ;;8x12
   ld l,sprite_l(ix)
   ld h,sprite_h(ix)

   ;ld hl, #_sprite_prueba
   ;;call cpct_drawSolidBox_asm
   call cpct_drawSprite_asm

 ret
 ;dale a ctr+F en el amin y donde ponga eso pones tu sucio y asqueroso codigo wee
 ;cancionjuego
 ;cancionmuerte
 ;cancionnivelpasado
 ;cancionjuegopasado

 efectosonidodisparomio:

 ex af, af';'
 exx
 push af
 push bc
 push de
 push hl
 push iy
 push ix


 ld l, #02
 ld h, #15
 ld e, #36
 ld d, #0
 ld bc, #0
 ld a, #2

 call cpct_akp_SFXPlay_asm

 pop ix
 pop iy
 pop hl
 pop de
 pop bc
 pop af
 exx
 ex af,af';'

 ret
 efectosonidodisparoenem:

 ex af, af';'
 exx
 push af
 push bc
 push de
 push hl
 push iy
 push ix

 ld l, #01
 ld h, #15
 ld e, #36
 ld d, #0
 ld bc, #0
 ld a, #2

 call cpct_akp_SFXPlay_asm

 pop ix
 pop iy
 pop hl
 pop de
 pop bc
 pop af
 exx
 ex af,af';'
 ret
