cscg22-gearboy

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

set_tile_submap.s (3276B)


      1        .include        "global.s"
      2
      3        .title  "VRAM utilities"
      4        .module VRAMUtils
      5
      6        .ez80
      7
      8        .area   _DATA
      9
     10.image_tile_width::
     11        .ds     0x01
     12
     13        .area   _HOME
     14
     15; void set_tile_submap(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);
     16_set_tile_submap::
     17        pop hl                  ; HL = ret
     18        pop bc                  ; BC = YX
     19        pop de                  ; DE = WH
     20
     21        dec sp
     22        pop af
     23        sub e
     24        ld (.image_tile_width), a ; .image_tile_width contains corrected width
     25
     26        ex (sp), hl             ; HL = data
     27        ex de, hl               ; HL = WH, DE = data
     28
     29        push hl
     30        push de
     31
     32        add l
     33        ld e, a
     34        ld d, #0
     35        ld a, b
     36        MUL_DE_BY_A_RET_HL
     37        ld a, c
     38        ADD_A_REG16 h, l
     39        add hl, hl
     40
     41        pop de
     42        add hl, de
     43        ex de, hl
     44
     45        pop hl
     46
     47        ld a, b
     48        ld b, d
     49
     50        add #.SCREEN_Y_OFS
     51        ld d, a
     52        xor a
     53        FAST_MOD8 d #28
     54        ld d, a
     55
     56        ld a, c
     57        add #.SCREEN_X_OFS
     58        and #0x1f
     59        ld c, e
     60        ld e, a                 ; BC = data, DE = YX
     61
     62        ;; Set background tile table from (BC) at XY = DE of size WH = HL
     63.set_tile_submap_xy::
     64        push hl
     65        ld hl, #.VDP_TILEMAP
     66
     67        ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     68.set_tile_submap_xy_tt::
     69        push bc                 ; Store source
     70
     71        ld a, d
     72        rrca                    ; rrca(2) == rlca(6)
     73        rrca
     74        ld d, a
     75        and #0x07
     76        add h
     77        ld b, a
     78        ld a, #0xC0
     79        and d
     80        sla e
     81        add e
     82        ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
     83
     84        ld a, b
     85        cp #>(.VDP_TILEMAP+0x0700)
     86        jr c, 5$
     87        ld b, #>.VDP_TILEMAP
     885$:
     89        pop hl                  ; HL = source
     90        pop de                  ; DE = HW
     91        push ix                 ; save IX
     92        push de                 ; store HW
     93
     94        ld ixh, b
     95        ld ixl, c
     96        push ix                 ; store dest
     97
     98        DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     99
    1001$:                             ; copy H rows
    101        VDP_WRITE_CMD ixh, ixl
    102        ld c, #.VDP_DATA
    1032$:                             ; copy W tiles
    104        outi
    105        VDP_DELAY
    106        outi
    107
    108        ld a, ixl
    109        and #0x3F
    110        inc a
    111        inc a
    112        bit 6, a
    113        jp z, 3$
    114        and #0x3F
    115        ld b, a
    116        ld a, ixl
    117        and #0xC0
    118        or b
    119        ld ixl, a
    120        VDP_WRITE_CMD ixh, ixl
    121        dec e
    122        jp nz, 2$
    123        jp 7$
    1243$:
    125        inc ixl
    126        inc ixl
    127        dec e
    128        jp nz, 2$
    1297$:
    130        pop ix
    131        pop de
    132
    133        dec d
    134        jr z, 6$
    135
    136        push de
    137
    138        ld b, #0
    139        ld a, (.image_tile_width)
    140        ld c, a
    141        add hl, bc
    142        add hl, bc
    143
    144        ld bc, #0x40
    145        add ix, bc
    146        ld a, ixh
    147        cp #>(.VDP_TILEMAP+0x0700)
    148        jp c, 4$
    149        ld ixh, #>.VDP_TILEMAP
    1504$:        
    151        push ix
    152        jp 1$
    1536$:
    154        ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
    155        pop ix                  ; restore IX
    156        ret