cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

set_tile_submap_compat.s (3586B)


      1        .include        "global.s"
      2
      3        .title  "VRAM utilities"
      4        .module VRAMUtils
      5
      6        .ez80
      7
      8        .area   _DATA
      9
     10.image_tile_width_compat::
     11        .ds     0x01
     12
     13        .area   _INITIALIZED
     14
     15__submap_tile_offset::
     16        .ds     0x01
     17
     18        .area   _INITIALIZER
     19
     20        .db     0x00
     21
     22        .area   _HOME
     23
     24; void set_tile_submap_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl);
     25_set_tile_submap_compat::
     26        pop hl                  ; HL = ret
     27        pop bc                  ; BC = YX
     28        pop de                  ; DE = WH
     29
     30        dec sp
     31        pop af
     32        sub e
     33        ld (.image_tile_width_compat), a ; .image_tile_width_compat contains corrected width
     34
     35        ex (sp), hl             ; HL = data
     36        ex de, hl               ; HL = WH, DE = data
     37
     38        push hl
     39        push de
     40
     41        add l
     42        ld e, a
     43        ld d, #0
     44        ld a, b
     45        MUL_DE_BY_A_RET_HL
     46        ld a, c
     47        ADD_A_REG16 h, l
     48
     49        pop de
     50        add hl, de
     51        ex de, hl
     52
     53        pop hl
     54
     55        ld a, b
     56        ld b, d
     57
     58        add #.SCREEN_Y_OFS
     59        ld d, a
     60        xor a
     61        FAST_MOD8 d #28
     62        ld d, a
     63
     64        ld a, c
     65        add #.SCREEN_X_OFS
     66        and #0x1f
     67        ld c, e
     68        ld e, a                 ; BC = data, DE = YX
     69
     70        ;; Set background tile table from (BC) at XY = DE of size WH = HL
     71.set_tile_submap_xy_compat::
     72        push hl
     73        ld hl, #.VDP_TILEMAP
     74
     75        ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     76.set_tile_submap_xy_tt_compat::
     77        push bc                 ; Store source
     78
     79        ld a, d
     80        rrca                    ; rrca(2) == rlca(6)
     81        rrca
     82        ld d, a
     83        and #0x07
     84        add h
     85        ld b, a
     86        ld a, #0xC0
     87        and d
     88        sla e
     89        add e
     90        ld hl, #.vdp_shift
     91        add (hl)
     92        ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
     93
     94        ld a, b
     95        cp #>(.VDP_TILEMAP+0x0700)
     96        jr c, 5$
     97        ld b, #>.VDP_TILEMAP
     985$:
     99        pop hl                  ; HL = source
    100        pop de                  ; DE = HW
    101        push ix                 ; save IX
    102        push de                 ; store HW
    103
    104        ld ixh, b
    105        ld ixl, c
    106        push ix                 ; store dest
    107
    108        DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
    109
    1101$:                             ; copy H rows
    111        VDP_WRITE_CMD ixh, ixl
    112        ld c, #.VDP_DATA
    1132$:                             ; copy W tiles
    114        ld a, (__map_tile_offset)
    115        add (hl)
    116        out (c), a
    117        inc hl
    118        dec b
    119        jr 8$                   ; delay
    1208$:
    121        in a, (c)               ; skip next byte
    122
    123        ld a, ixl
    124        and #0x3F
    125        inc a
    126        inc a
    127        bit 6, a
    128        jp z, 3$
    129        and #0x3F
    130        ld b, a
    131        ld a, ixl
    132        and #0xC0
    133        or b
    134        ld ixl, a
    135        VDP_WRITE_CMD ixh, ixl
    136        dec e
    137        jp nz, 2$
    138        jp 7$
    1393$:
    140        inc ixl
    141        inc ixl
    142        dec e
    143        jp nz, 2$
    1447$:
    145        pop ix
    146        pop de
    147
    148        dec d
    149        jr z, 6$
    150
    151        push de
    152
    153        ld a, (.image_tile_width_compat)
    154        ADD_A_REG16 h, l
    155
    156        ld bc, #0x40
    157        add ix, bc
    158        ld a, ixh
    159        cp #>(.VDP_TILEMAP+0x0700)
    160        jp c, 4$
    161        ld ixh, #>.VDP_TILEMAP
    1624$:        
    163        push ix
    164        jp 1$
    1656$:
    166        ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
    167        pop ix                  ; restore IX
    168        ret