gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 252ca411850c487b1a210e83566588a11632f660 parent fa05104a5ee7b04415c0b49249501d59ce19e821 Author: Toxa <untoxa@mail.ru> Date: Wed, 12 May 2021 22:57:39 +0300 set_tile_data() allows to load tile data not taking into account LCDC bit 4 state Diffstat:
| M | gbdk-lib/include/gb/gb.h | 11 | +++++++++++ |
| M | gbdk-lib/libc/gb/set_data.s | 96 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
2 files changed, 61 insertions(+), 46 deletions(-)
diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -1332,6 +1332,17 @@ void set_tiles(UINT8 x, unsigned char *vram_addr, const unsigned char *tiles) NONBANKED __preserves_regs(b, c); +/** Sets VRAM Tile Pattern data starting from given base address + + @param first_tile Index of the first tile to write + @param nb_tiles Number of tiles to write + @param data Pointer to (2 bpp) source Tile Pattern data. + @param base MSB of the destination address in VRAM (usually 0x80 or 0x90 which gives 0x8000 or 0x9000) +*/ +void set_tile_data(UINT8 first_tile, + UINT8 nb_tiles, + const unsigned char *data, + UINT8 base) NONBANKED __preserves_regs(b, c); /** Copies a rectangular region of Tile Map entries from a given VRAM Address into a buffer. diff --git a/gbdk-lib/libc/gb/set_data.s b/gbdk-lib/libc/gb/set_data.s @@ -1,55 +1,59 @@ - .include "global.s" + .include "global.s" - ;; BANKED: checked - .area _BASE + ;; BANKED: checked + .area _BASE +_set_tile_data:: + ldhl sp, #6 + ld d,(hl) + jr .copy_tiles _set_bkg_data:: _set_win_data:: - ld d, #0x90 - ldh a, (.LCDC) - bit 4, a - jr z, .copy_tiles + ld d, #0x90 + ldh a, (.LCDC) + bit 4, a + jr z, .copy_tiles _set_sprite_data:: - ld d, #0x80 + ld d, #0x80 .copy_tiles: - push bc - lda hl, 4(sp) - ld a, (hl+) ; ID of 1st tile - ld e, a - ld a, (hl+) ; Nb of tiles - ld c, a - ld a, (hl+) ; Src ptr - ld h, (hl) - ld l, a - - ; Compute dest ptr - swap e ; *16 (size of a tile) - ld a, e - and #0x0F ; Get high bits - add d ; Add base offset of target tile "block" - ld d, a - ld a, e - and #0xF0 ; Get low bits only - ld e, a + push bc + ldhl sp, #4 + ld a, (hl+) ; ID of 1st tile + ld e, a + ld a, (hl+) ; Nb of tiles + ld c, a + ld a, (hl+) ; Src ptr + ld h, (hl) + ld l, a + + ; Compute dest ptr + swap e ; *16 (size of a tile) + ld a, e + and #0x0F ; Get high bits + add d ; Add base offset of target tile "block" + ld d, a + ld a, e + and #0xF0 ; Get low bits only + ld e, a 2$: - ; Wrap from past $97FF to $8800 onwards - ; This can be reduced to "bit 4 must be clear if bit 3 is set" - bit 3, d - jr z, 1$ - res 4, d + ; Wrap from past $97FF to $8800 onwards + ; This can be reduced to "bit 4 must be clear if bit 3 is set" + bit 3, d + jr z, 1$ + res 4, d 1$: - ld b, #16 + ld b, #16 3$: - WAIT_STAT - ld a, (hl+) - ld (de), a - inc de - - dec b - jr nz, 3$ + WAIT_STAT + ld a, (hl+) + ld (de), a + inc de + + dec b + jr nz, 3$ - dec c - jr nz, 2$ - - pop bc - ret - + dec c + jr nz, 2$ + + pop bc + 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.