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/sms_fill_rect_xy.s

      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 .fill_rect_xy::
     12         push hl
     13         ld a, (_shadow_VDP_R2)
     14         rlca
     15         rlca
     16         and #0b01111000
     17         ld h, a
     18         ld l, #0
     19 
     20         ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     21 .fill_rect_xy_tt::
     22         ld a, h
     23         ld iyh, a
     24         push bc                 ; Store source
     25 
     26         ld a, d
     27         rrca                    ; rrca(2) == rlca(6)
     28         rrca
     29         ld d, a
     30         and #0x07
     31         add h
     32         ld b, a
     33         ld a, #0xC0
     34         and d
     35         sla e
     36         add e
     37         ld c, a                 ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2)
     38 
     39         ld a, b
     40         and #0b00000111
     41         or iyh
     42         ld b, a
     43 
     44         DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     45 
     46         pop hl                  ; HL = source
     47         pop de                  ; DE = HW
     48         push ix                 ; save IX
     49         push de                 ; store HW
     50 
     51         ld ixh, b
     52         ld ixl, c
     53         push ix                 ; store dest
     54 
     55 1$:                             ; copy H rows
     56         VDP_WRITE_CMD ixh, ixl
     57         ld c, #.VDP_DATA
     58 2$:                             ; copy W tiles
     59         out (c), l
     60         VDP_DELAY
     61         out (c), h
     62 
     63         ld a, ixl
     64         and #0x3F
     65         inc a
     66         inc a
     67         bit 6, a
     68         jp z, 3$
     69         and #0x3F
     70         ld b, a
     71         ld a, ixl
     72         and #0xC0
     73         or b
     74         ld ixl, a
     75         VDP_WRITE_CMD ixh, ixl
     76         dec e
     77         jp nz, 2$
     78         jp 7$
     79 3$:
     80         inc ixl
     81         inc ixl
     82         dec e
     83         jp nz, 2$
     84 7$:
     85         pop ix
     86         pop de
     87 
     88         dec d
     89         jr z, 6$
     90 
     91         push de
     92 
     93         ld bc, #0x40
     94         add ix, bc
     95 
     96         ld a, ixh
     97         and #0b00000111
     98         cp #0x07
     99         jp nz, 8$
    100         xor a
    101 8$:
    102         or iyh
    103         ld ixh, a
    104 
    105         push ix
    106         jp 1$
    107 6$:
    108         ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
    109         pop ix                  ; restore IX
    110         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.