cscg22-gearboy

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

set_tile_map_xy.s (2069B)


      1        .include        "global.s"
      2
      3        .title  "VRAM utilities"
      4        .module VRAMUtils
      5
      6        .ez80
      7
      8        .area   _HOME
      9
     10        ;; Set background tile table from (BC) at XY = DE of size WH = HL
     11.set_tile_map_xy::
     12        push hl
     13        ld hl, #.VDP_TILEMAP
     14
     15        ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     16.set_tile_map_xy_tt::
     17        push bc                 ; Store source
     18
     19        ld a, d
     20        rrca                    ; rrca(2) == rlca(6)
     21        rrca
     22        ld d, a
     23        and #0x07
     24        add h
     25        ld b, a
     26        ld a, #0xC0
     27        and d
     28        sla e
     29        add e
     30        ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
     31
     32        ld a, b
     33        cp #>(.VDP_TILEMAP+0x0700)
     34        jr c, 5$
     35        ld b, #>.VDP_TILEMAP
     365$:
     37        pop hl                  ; HL = source
     38        pop de                  ; DE = HW
     39        push ix                 ; save IX
     40        push de                 ; store HW
     41
     42        ld ixh, b
     43        ld ixl, c
     44        push ix                 ; store dest
     45
     46        DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     47
     481$:                             ; copy H rows
     49        VDP_WRITE_CMD ixh, ixl
     50        ld c, #.VDP_DATA
     512$:                             ; copy W tiles
     52        outi
     53        VDP_DELAY
     54        outi
     55
     56        ld a, ixl
     57        and #0x3F
     58        inc a
     59        inc a
     60        bit 6, a
     61        jp z, 3$
     62        and #0x3F
     63        ld b, a
     64        ld a, ixl
     65        and #0xC0
     66        or b
     67        ld ixl, a
     68        VDP_WRITE_CMD ixh, ixl
     69        dec e
     70        jp nz, 2$
     71        jp 7$
     723$:
     73        inc ixl
     74        inc ixl
     75        dec e
     76        jp nz, 2$
     777$:
     78        pop ix
     79        pop de
     80
     81        dec d
     82        jr z, 6$
     83
     84        push de
     85
     86        ld bc, #0x40
     87        add ix, bc
     88        ld a, ixh
     89        cp #>(.VDP_TILEMAP+0x0700)
     90        jp c, 4$
     91        ld ixh, #>.VDP_TILEMAP
     924$:        
     93        push ix
     94        jp 1$
     956$:
     96        ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
     97        pop ix                  ; restore IX
     98        ret