git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/targets/z80/set_tile_submap.s

      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, const uint8_t *map, uint8_t map_w) __z88dk_callee;
     16 _set_tile_submap::
     17         pop iy                  ; IY = ret
     18         pop bc                  ; BC = XY
     19         pop hl                  ; HL = HW
     20         pop de                  ; DE = data
     21 
     22         dec sp
     23         pop af
     24         sub l
     25         ld (.image_tile_width), a ; .image_tile_width contains corrected width
     26 
     27         push iy
     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 a, (_shadow_VDP_R2)
     66         rlca
     67         rlca
     68         and #0b01111000
     69         ld h, a
     70         ld l, #0
     71 
     72         ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     73 .set_tile_submap_xy_tt::
     74         ld a, h
     75         ld iyh, a
     76         push bc                 ; Store source
     77 
     78         ld a, d
     79         rrca                    ; rrca(2) == rlca(6)
     80         rrca
     81         ld d, a
     82         and #0x07
     83         add h
     84         ld b, a
     85         ld a, #0xC0
     86         and d
     87         sla e
     88         add e
     89         ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
     90 
     91         ld a, b
     92         and #0b00000111
     93         or iyh
     94         ld b, a
     95 
     96         DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     97 
     98         pop hl                  ; HL = source
     99         pop de                  ; DE = HW
    100         push ix                 ; save IX
    101         push de                 ; store HW
    102 
    103         ld ixh, b
    104         ld ixl, c
    105         push ix                 ; store dest
    106 
    107 1$:                             ; copy H rows
    108         VDP_WRITE_CMD ixh, ixl
    109         ld c, #.VDP_DATA
    110 2$:                             ; copy W tiles
    111         outi
    112         VDP_DELAY
    113         outi
    114 
    115         ld a, ixl
    116         and #0x3F
    117         inc a
    118         inc a
    119         bit 6, a
    120         jp z, 3$
    121         and #0x3F
    122         ld b, a
    123         ld a, ixl
    124         and #0xC0
    125         or b
    126         ld ixl, a
    127         VDP_WRITE_CMD ixh, ixl
    128         dec e
    129         jp nz, 2$
    130         jp 7$
    131 3$:
    132         inc ixl
    133         inc ixl
    134         dec e
    135         jp nz, 2$
    136 7$:
    137         pop ix
    138         pop de
    139 
    140         dec d
    141         jr z, 6$
    142 
    143         push de
    144 
    145         ld b, #0
    146         ld a, (.image_tile_width)
    147         ld c, a
    148         add hl, bc
    149         add hl, bc
    150 
    151         ld bc, #0x40
    152         add ix, bc
    153 
    154         ld a, ixh
    155         and #0b00000111
    156         cp #0x07
    157         jp nz, 8$
    158         xor a
    159 8$:
    160         or iyh
    161         ld ixh, a
    162 
    163         push ix
    164         jp 1$
    165 6$:
    166         ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
    167         pop ix                  ; restore IX
    168         ret

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.