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_compat.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_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, const uint8_t *map, uint8_t map_w) __z88dk_callee;
     25 _set_tile_submap_compat::
     26         pop iy                  ; IY = ret
     27         pop bc                  ; BC = XY
     28         pop hl                  ; HL = HW
     29         pop de                  ; DE = data
     30 
     31         dec sp
     32         pop af
     33         sub l
     34         ld (.image_tile_width_compat), a ; .image_tile_width_compat contains corrected width
     35 
     36         push iy
     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 a, (_shadow_VDP_R2)
     74         rlca
     75         rlca
     76         and #0b01111000
     77         ld h, a
     78         ld l, #0
     79 
     80         ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     81 .set_tile_submap_xy_tt_compat::
     82         ld a, h
     83         ld iyh, a
     84         push bc                 ; Store source
     85 
     86         ld a, d
     87         rrca                    ; rrca(2) == rlca(6)
     88         rrca
     89         ld d, a
     90         and #0x07
     91         add h
     92         ld b, a
     93         ld a, #0xC0
     94         and d
     95         sla e
     96         add e
     97         ld hl, #.vdp_shift
     98         add (hl)
     99         ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
    100 
    101         ld a, b
    102         and #0b00000111
    103         or iyh
    104         ld b, a
    105 
    106         DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
    107 
    108         pop hl                  ; HL = source
    109         pop de                  ; DE = HW
    110         push ix                 ; save IX
    111         push de                 ; store HW
    112 
    113         ld ixh, b
    114         ld ixl, c
    115         push ix                 ; store dest
    116 
    117 1$:                             ; copy H rows
    118         VDP_WRITE_CMD ixh, ixl
    119         ld c, #.VDP_DATA
    120 2$:                             ; copy W tiles
    121         ld a, (__map_tile_offset)
    122         add (hl)
    123         out (c), a
    124         inc hl
    125         dec b
    126         jr 8$                   ; delay
    127 8$:
    128         in a, (c)               ; skip next byte
    129 
    130         ld a, ixl
    131         and #0x3F
    132         inc a
    133         inc a
    134         bit 6, a
    135         jp z, 3$
    136         and #0x3F
    137         ld b, a
    138         ld a, ixl
    139         and #0xC0
    140         or b
    141         ld ixl, a
    142         VDP_WRITE_CMD ixh, ixl
    143         dec e
    144         jp nz, 2$
    145         jp 7$
    146 3$:
    147         inc ixl
    148         inc ixl
    149         dec e
    150         jp nz, 2$
    151 7$:
    152         pop ix
    153         pop de
    154 
    155         dec d
    156         jr z, 6$
    157 
    158         push de
    159 
    160         ld a, (.image_tile_width_compat)
    161         ADD_A_REG16 h, l
    162 
    163         ld bc, #0x40
    164         add ix, bc
    165 
    166         ld a, ixh
    167         and #0b00000111
    168         cp #0x07
    169         jp nz, 9$
    170         xor a
    171 9$:
    172         or iyh
    173         ld ixh, a
    174 
    175         push ix
    176         jp 1$
    177 6$:
    178         ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
    179         pop ix                  ; restore IX
    180         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.