cscg22-gearboy

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

msx_set_tile_map_xy.s (2122B)


      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(3) == rlca(5)
     21        rrca 
     22        rrca 
     23        ld d, a
     24        and #0x07
     25        add h
     26        ld b, a
     27        ld a, #0xE0
     28        and d
     29        add e
     30        ld c, a                 ; dest BC = HL + ((0x20 * Y) + X
     31
     32        ld a, b
     33        cp #>(.VDP_TILEMAP+0x0300)
     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        ld ixh, b
     42        ld ixl, c
     43        push ix                 ; store dest
     44
     45        DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     46
     471$:                             ; copy H rows
     48        VDP_WRITE_CMD ixh, ixl
     49        ld c, #.VDP_DATA
     502$:                             ; copy W tiles
     51        ld a, (__map_tile_offset)
     52        add (hl)
     53        out (c), a
     54        inc hl
     55        dec b
     56
     57        ld a, ixl
     58        and #0x1F
     59        inc a
     60        bit 5, a
     61        jp z, 3$
     62        and #0x1F
     63        ld b, a
     64        ld a, ixl
     65        and #0xE0
     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        dec e
     75        jp nz, 2$
     767$:
     77        pop ix
     78        pop de
     79
     80        dec d
     81        jr z, 6$
     82
     83        push de
     84
     85        ld bc, #0x20
     86        add ix, bc
     87        ld a, ixh
     88        cp #>(.VDP_TILEMAP+0x0300)
     89        jp c, 4$
     90        ld ixh, #>.VDP_TILEMAP
     914$:        
     92        push ix
     93        jp 1$
     946$:
     95        ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
     96        pop ix                  ; restore IX
     97        ret
     98
     99__map_tile_offset::
    100        .db 0x00