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_set_tile_map_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 .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
     36 5$:
     37         DISABLE_VBLANK_COPY     ; switch OFF copy shadow SAT
     38 
     39         pop hl                  ; HL = source
     40         pop de                  ; DE = HW
     41         push ix                 ; save IX
     42         push de                 ; store HW
     43         ld ixh, b
     44         ld ixl, c
     45         push ix                 ; store dest
     46 
     47 1$:                             ; copy H rows
     48         VDP_WRITE_CMD ixh, ixl
     49         ld c, #.VDP_DATA
     50 2$:                             ; 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$
     72 3$:
     73         inc ixl
     74         dec e
     75         jp nz, 2$
     76 7$:
     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
     91 4$:        
     92         push ix
     93         jp 1$
     94 6$:
     95         ENABLE_VBLANK_COPY      ; switch ON copy shadow SAT
     96 
     97         pop ix                  ; restore IX
     98         ret
     99 
    100 __map_tile_offset::
    101         .db 0x00

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