ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 1.
Hexadecimal [16-Bits]



                              1 .include "render.h.s"
                              1 .globl render_update
                              2 .globl cpct_setVideoMode_asm
                              3 .globl cpct_getScreenPtr_asm
                              4 .globl cpct_drawSolidBox_asm
                              5 .globl cpct_drawSprite_asm
                              6 ;.globl cpct_drawSpriteMasked_asm
                              7 .globl cpct_setPalette_asm
                              8 .globl cpct_setPALColour_asm
                              9 .globl cpct_etm_setDrawTilemap4x8_ag_asm
                             10 .globl cpct_etm_drawTilemap4x8_ag_asm
                             11 .globl render_tilemap
                             12 .globl cpct_drawCharM0_asm
                             13 .globl cpct_setDrawCharM0_asm
                             14 .globl cpct_drawSpriteMaskedAlignedTable_asm
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 2.
Hexadecimal [16-Bits]



                              2 .include "man/entity.h.s"
                              1 .globl entity_create
                              2 .globl entity_copy
                              3 .globl entity_doForAll
                              4 .globl entity_doForAll_matching
                              5 .globl entity_doForAll_pairs_matching
                              6 .globl entity_update
                              7 .globl entity_vector
                              8 .globl entity_set4destruction
                              9 .globl entity_set4creation
                             10 .globl entity_register
                             11 .globl num_entities
                             12 .globl getEntity2
                             13 
                             14 
                             15 ; Constantes
                     0000    16 e_tipo            = 0
                     0001    17 e_cmps            = 1
                     0002    18 e_x               = 2
                     0003    19 e_y               = 3
                     0004    20 e_vx              = 4
                     0005    21 e_vy              = 5
                     0006    22 e_w               = 6
                     0007    23 e_h               = 7
                     0008    24 e_spriteL         = 8
                     0009    25 e_spriteH         = 9
                     000A    26 e_iaL             = 10
                     000B    27 e_iaH             = 11
                     000C    28 e_animL           = 12
                     000D    29 e_animH           = 13
                     000E    30 e_anim_st         = 14
                     000F    31 e_animCounter     = 15
                     0010    32 e_collidesAgainst = 16
                     0011    33 e_last_dir        = 17
                     0012    34 e_last_dirY       = 18
                     0013    35 e_player_shot     = 19
                     0014    36 e_actualizaMove   = 20
                     0015    37 e_contMove        = 21
                     0016    38 e_aim_X           = 22
                     0017    39 e_aim_Y           = 23
                     0018    40 e_hp              = 24
                     0019    41 e_perteneceL      = 25
                     001A    42 e_perteneceH      = 26
                     001B    43 e_tablaAnimL      = 27
                     001C    44 e_tablaAnimH      = 28
                     001D    45 e_anim_especial   = 29
                     001E    46 e_invencibilidad  = 30
                     001F    47 e_atacando        = 31
                             48 
                             49 
                             50 ;; Tipos
                     0000    51 e_type_invalid  = 0x00 
                     0001    52 e_type_player   = 0x01
                     0002    53 e_type_zombie   = 0x02  ;; realmente no es para el zombie, es para todos los enemigos
                     0004    54 e_type_shot     = 0x04
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 3.
Hexadecimal [16-Bits]



                     0008    55 e_type_arcoiris = 0x08
                     0010    56 e_type_vida     = 0x10
                     0080    57 e_type_dead     = 0x80
                     007F    58 e_type_default  = 0x7F
                             59 
                             60 ;; Components
                     0001    61 e_cmp_render   = 0x01
                     0002    62 e_cmp_movable  = 0x02
                     0004    63 e_cmp_input    = 0x04
                     0008    64 e_cmp_ia       = 0x08
                     0010    65 e_cmp_animated = 0x10
                     0020    66 e_cmp_collider = 0x20
                     0040    67 e_cmp_vidaextra = 0x40
                             68 
                     0010    69 k_max_num_entities = 16
                     0020    70 k_size_entity      = 32
                             71 
                             72 
                             73 
                             74 ;; Define an entity 
                             75 .macro DefineEntity _name, _tipo, _cmps, _x, _y, _vx, _vy, _w, _h, _sprite, _ia, _anim, _anim_st,_animCounter, _collides, _lastdir, _lastdirY , _playerShot, _actualizaMove, _contMove, _aimX, _aimY, _hp, _pertenece, _tablaAnim, _animEspecial, _invencible, _atacando
                             76    _name:
                             77       .db _tipo      ;; (Invalid 00, Player 01, Enemigo 02, Dead 80, Default 7F)
                             78       .db _cmps      ;; ()
                             79       .db _x,  _y    ;; x, y
                             80       .db _vx, _vy   ;; Vx, Vy
                             81       .db _w, _h     ;; Width, Height
                             82       .dw _sprite    ;; sprite (puntero al sprite)
                             83       .dw _ia        ;; IA     (puntero a funcion)
                             84       .dw _anim      ;; puntero a la animacion
                             85       .db _anim_st
                             86       .db _animCounter  ;; contador de animacion
                             87       .db _collides  ;; Collides Against
                             88       .db _lastdir, _lastdirY   ;; Ultima direccion a la que apunta la entidad (solo para ver hacia donde dispara el player)
                             89       .db _playerShot ;; 1 si la entidad ya ha disparado, 0 si no
                             90       .db _actualizaMove
                             91       .db _contMove
                             92       .db _aimX, _aimY
                             93       .db _hp
                             94       .dw _pertenece
                             95       .dw _tablaAnim    ;; puntero a la tabla que le corresponde de animaciones
                             96       .db _animEspecial ;; indica si es normal (0) o especial (1)
                             97       .db _invencible
                             98       .db _atacando
                             99 .endm
                            100 
                            101 ;; Define an entity with default values
                            102 .macro DefineEntityDefault _name, _suf
                            103                         ;;  Tipo  cmps  x     y      vx   vy   width height  sprite   ia     anim  status counter  collides  last_dir last_dir  player_shot actualizaMove contMove aimX, aimY    HP   pertenece tablaAnim especial invencibile atacando
                            104    DefineEntity _name'_suf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000, 0x0000, 0x0000, 0x00, 0x00,    0x00,    0x00,    0x00,       0x00,       0x00,       0x00,     0x00, 0x00,  0x00,  0x0000,  0x0000,   0x00,        0xDE,     0xAD;;
                            105 .endm
                            106 
                            107 ;; Define N default entities (changing the names)
                            108 .macro DefineNEntities _name, _n
                            109    _c = 0
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 4.
Hexadecimal [16-Bits]



                            110    .rept _n
                            111       DefineEntityDefault _name, \_c
                            112       _c = _c + 1 
                            113    .endm
                            114 .endm
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 5.
Hexadecimal [16-Bits]



                              3 .include "tilemaps/level1.h.s"
                              1 ;;
                              2 ;; File assets/level1.tmx converted to csv using cpct_tmx2data [Mon Nov  1 20:58:08 2021]
                              3 ;;   * Visible Layers:  1
                              4 ;;   * Layer Width:     20
                              5 ;;   * Layer Height:    25
                              6 ;;   * Bits per tile:   8
                              7 ;;   * Layer Bytes:     500 (20 x 25 items, 8 bits per item)
                              8 ;;   * Total Bytes:     500 (500 x 1, bytes per layer times layers)
                              9 ;;
                             10 ;;#### Width and height constants ####
                     0014    11 _tilemap1_W = 20
                     0019    12 _tilemap1_H = 25
                             13 
                             14 ;;#### Converted layer tilemaps ####
                             15 ;;   Visible layers: 1
                             16 ;;
                             17 .globl _tilemap1
                     01F4    18 _tilemap1_SIZE = 500
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 6.
Hexadecimal [16-Bits]



                              4 
                              5 .globl _main_palette
                              6 .globl _spr_vidasboss_5
                              7 .globl _spr_vidasboss_4
                              8 .globl _spr_vidasboss_3
                              9 .globl _spr_vidasboss_2
                             10 .globl _spr_vidasboss_1
                             11 .globl _spr_vidasboss_0
                             12 
                             13 ;; ===============================
                             14 ;; INICIALIZA LA PNTALLA
                             15 ;; Destroy: AF, DE, BC, HL
                             16 ;; Input: IX --> Pointers to the entity
                             17 ;; ===============================
   A9DC                      18 render_init:
                             19 
                             20     ;; Establecemos el Modo de video
   A9DC 0E 00         [ 7]   21     ld c, #0
   A9DE CD 3C B5      [17]   22     call cpct_setVideoMode_asm
                             23 
                             24     ;; Establecemos la paleta
   A9E1 21 12 65      [10]   25     ld hl, #_main_palette
   A9E4 11 10 00      [10]   26     ld de, #16
   A9E7 CD 9C AA      [17]   27     call cpct_setPalette_asm
                             28 
                             29     ;; Ponemos el color del borde igual que el fondo
   A9EA 2E 10         [ 7]   30     ld l, #16    ;; color del borde en la paleta
   A9EC 26 14         [ 7]   31     ld h, #20     ;; color del fondo
   A9EE CD 25 AB      [17]   32     call cpct_setPALColour_asm
   A9F1 C9            [10]   33 ret
                             34 
   A9F2                      35 _tilemap1:
   A9F2                      36 _tilemap2:
   A9F2                      37 _tilemap3:
   A9F2                      38 _tilemap4:
   A9F2                      39 _tilemap5:
   A9F2                      40 _tilemap6:
   A9F2                      41 _tilemap7:
   A9F2                      42 _tilemap8:
   A9F2                      43 _tilemap9:
                             44 
                             45 
                             46 ;; ===============================
                             47 ;; INICIALIZA Y PINTA EL TILEMAP
                             48 ;; Destroy: AF, DE, BC, HL
                             49 ;; ===============================
                     04AA    50 tilset_ptr = 0x2b6 + 500
                     02B6    51 tilemap_ptr = 0x2b6
   A9F2                      52 render_tilemap:
                             53 
   A9F2 06 19         [ 7]   54     ld b, #_tilemap1_H ;;height en tiles de la ventana
   A9F4 0E 14         [ 7]   55     ld c, #_tilemap1_W
   A9F6 11 14 00      [10]   56     ld de, #_tilemap1_W
   A9F9 21 AA 04      [10]   57     ld hl, #tilset_ptr
   A9FC CD BC B6      [17]   58     call cpct_etm_setDrawTilemap4x8_ag_asm
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 7.
Hexadecimal [16-Bits]



                             59 ;;
                             60     ;;ld hl, #0xC000
                             61     ;;ld de, #_tilemapM
   A9FF 21 00 C0      [10]   62     ld hl, #0xC000
   AA02 11 B6 02      [10]   63     ld de, #tilemap_ptr
   AA05 CD 99 B4      [17]   64     call cpct_etm_drawTilemap4x8_ag_asm
   AA08 C9            [10]   65 ret
                             66 
                             67 ;; ===============================
                             68 ;; DIBUJA UNA ENTIDAD
                             69 ;; Destroy: AF, DE, BC, HL
                             70 ;; Input: IX --> Pointers to the entity
                             71 ;; ===============================
   AA09                      72 render_draw_one:
                             73     ;;si la entidad esta muerta pinto un cubo encima
   AA09 11 00 C0      [10]   74     ld    de, #0xC000      ;; Starting adrees of screen
   AA0C DD 4E 02      [19]   75     ld    c, e_x(ix)       ;; C = entity_X
   AA0F DD 46 03      [19]   76     ld    b, e_y(ix)       ;; B = entity_Y
   AA12 CD A8 B6      [17]   77     call  cpct_getScreenPtr_asm ;; returns the position in hl
   AA15 EB            [ 4]   78     ex de, hl
                             79 
                             80     
                             81 
                             82     ;; si esta en mitad de una animacion no miro el tipo
   AA16 DD 7E 1D      [19]   83     ld a, e_anim_especial(ix)
   AA19 FE 01         [ 7]   84     cp #1
   AA1B CA 26 AA      [10]   85     jp z, pinto
                             86     
   AA1E DD 7E 00      [19]   87     ld a, e_tipo(ix)
   AA21 FE 80         [ 7]   88     cp #e_type_dead
   AA23 CA 39 AA      [10]   89     jp z, noPinto
   AA26                      90         pinto:
                             91 
                             92         ;ex de, hl            ;; DrawSolidSprite needs the position in DE
   AA26 DD 6E 08      [19]   93         ld l, e_spriteL(ix)
   AA29 DD 66 09      [19]   94         ld h, e_spriteH(ix)
                             95 
   AA2C DD 46 07      [19]   96         ld b,  e_h(ix)       ;; Height
   AA2F DD 4E 06      [19]   97         ld c,  e_w(ix)       ;; Width
   AA32 CD E2 B3      [17]   98         call cpct_drawSprite_asm
                             99         
   AA35 CD 45 AA      [17]  100         call render_draw_boss
   AA38 C9            [10]  101         ret
                            102 
   AA39                     103     noPinto:
   AA39 3E 0C         [ 7]  104         ld a, #0x0C
   AA3B DD 46 07      [19]  105         ld b,  e_h(ix)       ;; Height
   AA3E DD 4E 06      [19]  106         ld c,  e_w(ix)       ;; Width
   AA41 CD BC B5      [17]  107         call cpct_drawSolidBox_asm
   AA44 C9            [10]  108 ret
                            109 
                            110 ;; ===============================
                            111 ;; RENDERIZAR VIDAS BOSS
                            112 ;; Input: IX-> entidad boss
                            113 ;; Destroy: bc, de, af, hl
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 8.
Hexadecimal [16-Bits]



                            114 ;; ===============================
   AA45                     115 render_draw_boss:
   AA45 06 40         [ 7]  116     ld b, #e_cmp_vidaextra ;para saber que es el boss
   AA47 DD 7E 01      [19]  117     ld a, e_cmps(ix) 
   AA4A A0            [ 4]  118     and b
   AA4B B8            [ 4]  119     cp b
   AA4C 20 44         [12]  120     jr nz, noBoss
                            121         ;; es el boss
   AA4E 11 00 C0      [10]  122         ld    de, #0xC000      ;; Starting adrees of screen
   AA51 DD 4E 02      [19]  123         ld    c, e_x(ix)       ;; C = entity_X
                            124 
   AA54 DD 7E 03      [19]  125         ld a, e_y(ix)
   AA57 D6 08         [ 7]  126         sub #0x08
   AA59 47            [ 4]  127         ld b, a
   AA5A CD A8 B6      [17]  128         call  cpct_getScreenPtr_asm ;; returns the position in hl
   AA5D EB            [ 4]  129         ex de, hl
                            130         
   AA5E DD 7E 18      [19]  131         ld a, e_hp(ix)
   AA61 FE 05         [ 7]  132         cp #5
   AA63 C2 6B AA      [10]  133         jp nz, no_es_5
   AA66 21 40 12      [10]  134             ld hl, #_spr_vidasboss_5
   AA69 18 21         [12]  135             jr pinto_vida
   AA6B                     136         no_es_5:
   AA6B FE 04         [ 7]  137         cp #4
   AA6D C2 75 AA      [10]  138         jp nz, no_es_4
   AA70 21 B0 11      [10]  139             ld hl, #_spr_vidasboss_4
   AA73 18 17         [12]  140             jr pinto_vida
   AA75                     141         no_es_4:
   AA75 FE 03         [ 7]  142         cp #3
   AA77 C2 7F AA      [10]  143         jp nz, no_es_3
   AA7A 21 20 11      [10]  144             ld hl, #_spr_vidasboss_3
   AA7D 18 0D         [12]  145             jr pinto_vida
   AA7F                     146         no_es_3:
   AA7F FE 02         [ 7]  147         cp #2
   AA81 C2 89 AA      [10]  148         jp nz, no_es_2
   AA84 21 90 10      [10]  149             ld hl, #_spr_vidasboss_2
   AA87 18 03         [12]  150             jr pinto_vida
   AA89                     151         no_es_2:
   AA89 21 00 10      [10]  152             ld hl, #_spr_vidasboss_1
                            153 
   AA8C                     154         pinto_vida:
   AA8C 01 0C 0C      [10]  155         ld bc, #0x0C0C
   AA8F CD E2 B3      [17]  156         call cpct_drawSprite_asm
   AA92                     157     noBoss:
   AA92 C9            [10]  158 ret
                            159 
                            160 
                            161 ;; ===============================
                            162 ;; EJECUTA PARA TODAS LAS ENTIDADES
                            163 ;; Input:
                            164 ;; Output:
                            165 ;; ===============================
   AA93                     166 render_update:
   AA93 21 09 AA      [10]  167     ld hl, #render_draw_one
   AA96 06 01         [ 7]  168     ld b, #e_cmp_render
ASxxxx Assembler V02.00 + NoICE + SDCC mods  (Zilog Z80 / Hitachi HD64180), page 9.
Hexadecimal [16-Bits]



   AA98 CD 4F 92      [17]  169     call entity_doForAll_matching
   AA9B C9            [10]  170 ret
                            171 
                            172 
