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/sm83/set_data.s

      1         .include        "global.s"
      2 
      3         .area   _HOME
      4 
      5 _set_tile_data::
      6         ldhl sp, #6
      7         ld d,(hl)
      8         jr .copy_tiles
      9 _set_bkg_data::
     10 _set_win_data::
     11         ld d, #0x90
     12         ldh a, (.LCDC)
     13 	and #LCDCF_BG8000
     14         jr z, .copy_tiles
     15 _set_sprite_data::
     16         ld d, #0x80
     17 .copy_tiles:
     18         push bc
     19         ldhl sp, #4
     20         ld a, (hl+) ; ID of 1st tile
     21         ld e, a
     22         ld a, (hl+) ; Nb of tiles
     23         ld c, a
     24         ld a, (hl+) ; Src ptr
     25         ld h, (hl)
     26         ld l, a
     27         
     28         ; Compute dest ptr
     29         swap e ; *16 (size of a tile)
     30         ld a, e
     31         and #0x0F ; Get high bits
     32         add d ; Add base offset of target tile "block"
     33         ld d, a
     34         ld a, e
     35         and #0xF0 ; Get low bits only
     36         ld e, a
     37 2$:
     38         ; Wrap from past $97FF to $8800 onwards
     39         ; This can be reduced to "bit 4 must be clear if bit 3 is set"
     40         bit 3, d
     41         jr z, 1$
     42         res 4, d
     43 1$:
     44         ld b, #16
     45 3$:
     46         WAIT_STAT
     47         ld a, (hl+)
     48         ld (de), a
     49         inc de
     50         
     51         dec b
     52         jr nz, 3$
     53 
     54         dec c
     55         jr nz, 2$
     56         
     57         pop bc
     58         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.