git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 0fa82be14d6e9bb7c02211dba42e9134cfca3fa7
parent 6a41699223e8728a74d9564fee5a3c3bf79abbfb
Author: toxa <untoxa@mail.ru>
Date:   Sun, 11 Oct 2020 21:48:53 +0300

functions for loading 1bpp tile data

Diffstat:
Mgbdk-lib/include/gb/gb.h12++++++++++++
Mgbdk-lib/libc/gb/Makefile1+
Agbdk-lib/libc/gb/set_1bit_data.s81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/gbdk-lib/include/gb/gb.h b/gbdk-lib/include/gb/gb.h @@ -454,6 +454,10 @@ void set_bkg_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); +void set_bkg_1bit_data(UINT8 first_tile, + UINT8 nb_tiles, + unsigned char *data) NONBANKED __preserves_regs(b, c); + void get_bkg_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); @@ -513,6 +517,10 @@ void set_win_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); +void set_win_1bit_data(UINT8 first_tile, + UINT8 nb_tiles, + unsigned char *data) NONBANKED __preserves_regs(b, c); + void get_win_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); @@ -592,6 +600,10 @@ void set_sprite_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); +void set_sprite_1bit_data(UINT8 first_tile, + UINT8 nb_tiles, + unsigned char *data) NONBANKED __preserves_regs(b, c); + void get_sprite_data(UINT8 first_tile, UINT8 nb_tiles, unsigned char *data) NONBANKED __preserves_regs(b, c); diff --git a/gbdk-lib/libc/gb/Makefile b/gbdk-lib/libc/gb/Makefile @@ -14,6 +14,7 @@ ASSRC = cgb.s cpy_data.s drawing.s f_ibm_sh.s \ pad.s sample.s \ serial.s set_bk_t.s \ set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ + set_1bit_data.s \ sgb.s font.s delay.s \ rand.s arand.s \ bgb_emu.s \ diff --git a/gbdk-lib/libc/gb/set_1bit_data.s b/gbdk-lib/libc/gb/set_1bit_data.s @@ -0,0 +1,80 @@ + .include "global.s" + + .globl .copy_vram + + .area _BASE + +.macro WAIT_STAT ?lbl +lbl: ldh a, (.STAT) + and #2 ; Check if in LCD modes 0 or 1 + jr nz, lbl +.endm + +_set_bkg_1bit_data:: +_set_win_1bit_data:: + ld d, #0x90 + ldh a, (.LCDC) + bit 4, a + jr z, .copy_1bit_tiles +_set_sprite_1bit_data:: + ld d, #0x80 +.copy_1bit_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 a, d ; Add base offset of target tile "block" + ld d, a + ld a, e + and #0xF0 ; Get low bits only + ld e, a + +1$: + ; 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, 2$ + res 4, d +2$: + .rept 3 ; Repeat this 4 more times to copy 16 bytes... + WAIT_STAT + ; We have 16 cycles free to access VRAM, during which we can copy 3 bytes + ld a, (hl+) + ld (de), a + inc e ; inc de + ld (de), a + inc e ; inc de + ld a, (hl+) + ld (de), a + inc e ; inc de + ld (de), a + inc e ; inc de + .endm + WAIT_STAT + ; We have 16 cycles free to access VRAM, during which we can copy 3 bytes + ld a, (hl+) + ld (de), a + inc e ; inc de + ld (de), a + inc e ; inc de + ld a, (hl+) + ld (de), a + inc e ; inc de + ld (de), a + inc de ; This actually can overflow into the high byte + + dec c + jr nz, 1$ + + 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.