.include "cpctelera.h.s"
.include "man/entity.h.s"
.include "cmp/entity.h.s"
.include "cpct_functions.h.s"

.include "assets/assets.h.s"
.include "tilemap/2-11.h.s"
.module sys_entity_render

_pal_main : 
	.db HW_BLACK,  	HW_BLUE,	HW_BRIGHT_BLUE,	HW_RED
	.db HW_BRIGHT_RED,	HW_GREEN,	HW_SKY_BLUE,	HW_YELLOW
	.db HW_WHITE,	HW_ORANGE,	HW_PINK,	HW_BRIGHT_GREEN
	.db HW_BRIGHT_CYAN,	HW_BRIGHT_YELLOW,	HW_PASTEL_YELLOW,	HW_BRIGHT_WHITE	

screen_start=0xC000


sys_eren_init::
	ld c, #0
	call cpct_setVideoMode_asm
	ld hl, #_pal_main
	ld de, #16
	call cpct_setPalette_asm
	cpctm_setBorder_asm HW_BLACK

	ld hl, #0xC000
	ld de, #0xC001
	ld bc, #0x4000-1
	ld (hl), #0
	ldir



	ret

;;sys_eren_update_one::
;;
;;	
;;	ld a, e_cmp_type(ix)
;;	xor #e_cmp_Invalid
;;	call man_entity_getArray
;;	call nz, sys_eren_render_entities
;;
;;	;;call sys_eren_render_entities
;;
;;	ret



sys_eren_render_entities::

;;call man_entity_getArray

	ld 	a,e_cmp_type(ix)
	or a
	ret z

	call man_entity_getArray
	ld (_ent_counterr), a

_render_update_loop:

	ld e, e_lastVP_l(ix)
	ld d, e_lastVP_h(ix)
	;;xor a
	ld  a,#0x3c
	ld c, e_w(ix)
	ld b, e_h(ix)
	push bc
	call cpct_drawSolidBox_asm

	ld de, #screen_start
	ld c, e_x(ix)
	ld b, e_y(ix)
	call cpct_getScreenPtr_asm

	ld e_lastVP_l(ix), l
	ld e_lastVP_h(ix), h

	ex de, hl
	ld l, e_pspr_l(ix)
	ld h, e_pspr_h(ix)
	pop bc
	call cpct_drawSprite_asm

;;	ret

_ent_counterr = .+1
	ld a, #0
	dec a
	ret z

	ld (_ent_counterr), a

_another:
	ld bc, #sizeof_e
	add ix, bc

	ld 	a,e_cmp_type(ix)
	or a
	ret z
	ld a,(_ent_counterr) 
;;ret
	jr _render_update_loop


sys_tilemap_init::

	ld c,  #20
	ld b,  #25
	ld de, #20
	ld hl, #_tiles_00
	call cpct_etm_setDrawTilemap4x8_ag_asm

	ld hl, #0xC000
	ld de, #_nivel1
	call cpct_etm_drawTilemap4x8_ag_asm

	ret