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/msxdos/msx_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 hl, #.VDP_TILEMAP
     14 
     15         ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL)
     16 .fill_rect_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
     36 5$:
     37 
     38         DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     39 
     40         pop hl                  ; HL = source
     41         pop de                  ; DE = HW
     42         push ix                 ; save IX
     43         push de                 ; store HW
     44         ld ixh, b
     45         ld ixl, c
     46         push ix                 ; store dest
     47 
     48 1$:                             ; copy H rows
     49         VDP_WRITE_CMD ixh, ixl
     50         ld c, #.VDP_DATA
     51 2$:                             ; copy W tiles
     52         out (c), l
     53 
     54         ld a, ixl
     55         and #0x1F
     56         inc a
     57         bit 5, a
     58         jp z, 3$
     59         and #0x1F
     60         ld b, a
     61         ld a, ixl
     62         and #0xE0
     63         or b
     64         ld ixl, a
     65         VDP_WRITE_CMD ixh, ixl
     66         dec e
     67         jp nz, 2$
     68         jp 7$
     69 3$:
     70         inc ixl
     71         dec e
     72         jp nz, 2$
     73 7$:
     74         pop ix
     75         pop de
     76 
     77         dec d
     78         jr z, 6$
     79 
     80         push de
     81 
     82         ld bc, #0x20
     83         add ix, bc
     84         ld a, ixh
     85         cp #>(.VDP_TILEMAP+0x0300)
     86         jp c, 4$
     87         ld ixh, #>.VDP_TILEMAP
     88 4$:        
     89         push ix
     90         jp 1$
     91 6$:
     92         ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
     93         pop ix                  ; restore IX
     94         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.