git.y1.nz

gbdk-2020

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

commit 1417f9909f6b0df99607b8b8578344aaa7dc382a
parent 68332b4a1b5ebd271516337c19eb3b482014f04c
Author: Toxa <untoxa@mail.ru>
Date:   Fri, 27 Aug 2021 11:50:44 +0300

SMS/GG: fill_rect()/fill_bkg_rect()/fill_win_rect()

Diffstat:
Mgbdk-lib/examples/cross-platform/metasprites/src/metasprites.c4+++-
Mgbdk-lib/include/sms/sms.h6++++++
Agbdk-lib/libc/targets/z80/fill_rect.s30++++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/fill_rect_compat.s30++++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/fill_rect_xy.s99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/fill_rect_xy_compat.s102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/z80/gg/Makefile1+
Mgbdk-lib/libc/targets/z80/sms/Makefile1+
8 files changed, 272 insertions(+), 1 deletion(-)

diff --git a/gbdk-lib/examples/cross-platform/metasprites/src/metasprites.c b/gbdk-lib/examples/cross-platform/metasprites/src/metasprites.c @@ -32,7 +32,9 @@ uint8_t idx; void main(void) { DISPLAY_OFF; // Fill the screen background with a single tile pattern -// fill_bkg_rect(0, 0, 20, 18, 0); + fill_bkg_rect(0, 0, 20, 18, 0); + + // set tile data for background set_bkg_data(0, 1, pattern); // Load metasprite tile data into VRAM diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -400,6 +400,12 @@ inline void set_win_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uin set_tile_submap_compat(x, y, w, h, map_w, map); } +void fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) __z88dk_callee __preserves_regs(iyh, iyl); + +void fill_rect_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) __z88dk_callee __preserves_regs(iyh, iyl); +#define fill_bkg_rect fill_rect_compat +#define fill_win_rect fill_rect_compat + /** Shadow OAM array in WRAM, that is transferred into the real OAM each VBlank */ extern volatile uint8_t shadow_OAM[]; diff --git a/gbdk-lib/libc/targets/z80/fill_rect.s b/gbdk-lib/libc/targets/z80/fill_rect.s @@ -0,0 +1,30 @@ + .include "global.s" + + .globl .fill_rect_xy + + .area _HOME + +; void fill_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) __z88dk_callee __preserves_regs(iyh, iyl); +_fill_rect:: + pop hl ; HL = ret + pop bc ; BC = YX + pop de ; DE = WH + ex (sp), hl ; HL = data + ex de, hl ; HL = WH, DE = data + + ld a, b + ld b, d + + add #.SCREEN_Y_OFS + ld d, a + xor a + FAST_MOD8 d #28 + ld d, a + + ld a, c + add #.SCREEN_X_OFS + and #0x1f + ld c, e + ld e, a ; BC = data, DE = YX + + jp .fill_rect_xy diff --git a/gbdk-lib/libc/targets/z80/fill_rect_compat.s b/gbdk-lib/libc/targets/z80/fill_rect_compat.s @@ -0,0 +1,30 @@ + .include "global.s" + + .globl .set_tile_map_xy + + .area _HOME + +; void set_tile_map(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint16_t tile) __z88dk_callee __preserves_regs(iyh, iyl); +_fill_rect_compat:: + pop hl ; HL = ret + pop bc ; BC = YX + pop de ; DE = WH + ex (sp), hl ; HL = data + ex de, hl ; HL = WH, DE = data + + ld a, b + ld b, d + + add #.SCREEN_Y_OFS + ld d, a + xor a + FAST_MOD8 d #28 + ld d, a + + ld a, c + add #.SCREEN_X_OFS + and #0x1f + ld c, e + ld e, a ; BC = data, DE = YX + + jp .set_tile_map_xy_compat diff --git a/gbdk-lib/libc/targets/z80/fill_rect_xy.s b/gbdk-lib/libc/targets/z80/fill_rect_xy.s @@ -0,0 +1,98 @@ + .include "global.s" + + .title "VRAM utilities" + .module VRAMUtils + + .ez80 + + .area _HOME + + ;; Set background tile table from (BC) at XY = DE of size WH = HL +.fill_rect_xy:: + push hl + ld hl, #.VDP_TILEMAP + + ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) +.fill_rect_xy_tt:: + push bc ; Store source + + ld a, d + rrca ; rrca(2) == rlca(6) + rrca + ld d, a + and #0x07 + add h + ld b, a + ld a, #0xC0 + and d + sla e + add e + ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) + + ld a, b + cp #>(.VDP_TILEMAP+0x0700) + jr c, 5$ + ld b, #>.VDP_TILEMAP +5$: + pop hl ; HL = source + pop de ; DE = HW + push ix ; save IX + push de ; store HW + + ld ixh, b + ld ixl, c + push ix ; store dest + + DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT + +1$: ; copy H rows + SMS_WRITE_VDP_CMD ixh, ixl + ld c, #.VDP_DATA +2$: ; copy W tiles + out (c), l + VDP_DELAY + out (c), h + + ld a, ixl + and #0x3F + inc a + inc a + bit 6, a + jp z, 3$ + and #0x3F + ld b, a + ld a, ixl + and #0xC0 + or b + ld ixl, a + SMS_WRITE_VDP_CMD ixh, ixl + dec e + jp nz, 2$ + jp 7$ +3$: + inc ixl + inc ixl + dec e + jp nz, 2$ +7$: + pop ix + pop de + + dec d + jr z, 6$ + + push de + + ld bc, #0x40 + add ix, bc + ld a, ixh + cp #>(.VDP_TILEMAP+0x0700) + jp c, 4$ + ld ixh, #>.VDP_TILEMAP +4$: + push ix + jp 1$ +6$: + ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + pop ix ; restore IX + ret + diff --git a/gbdk-lib/libc/targets/z80/fill_rect_xy_compat.s b/gbdk-lib/libc/targets/z80/fill_rect_xy_compat.s @@ -0,0 +1,101 @@ + .include "global.s" + + .globl .vdp_shift + + .title "VRAM utilities" + .module VRAMUtils + + .ez80 + + .area _HOME + + ;; Set background tile table from (BC) at XY = DE of size WH = HL +.fill_rect_xy_compat:: + push hl + ld hl, #.VDP_TILEMAP + + ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) +.fill_rect_xy_tt_compat:: + push bc ; Store source + + ld a, d + rrca ; rrca(2) == rlca(6) + rrca + ld d, a + and #0x07 + add h + ld b, a + ld a, #0xC0 + and d + sla e + add e + ld hl, #.vdp_shift + add (hl) + ld c, a ; dest BC = HL + ((0x20 * Y) * 2) + (X * 2) + + ld a, b + cp #>(.VDP_TILEMAP+0x0700) + jr c, 5$ + ld b, #>.VDP_TILEMAP +5$: + pop hl ; HL = source + pop de ; DE = HW + push ix ; save IX + push de ; store HW + ld ixh, b + ld ixl, c + push ix ; store dest + + DISABLE_VBLANK_COPY ; switch OFF copy shadow SAT + +1$: ; copy H rows + SMS_WRITE_VDP_CMD ixh, ixl + ld c, #.VDP_DATA +2$: ; copy W tiles + out (c), l + VDP_DELAY + in a, (c) ; skip next byte + + ld a, ixl + and #0x3F + inc a + inc a + bit 6, a + jp z, 3$ + and #0x3F + ld b, a + ld a, ixl + and #0xC0 + or b + ld ixl, a + SMS_WRITE_VDP_CMD ixh, ixl + dec e + jp nz, 2$ + jp 7$ +3$: + inc ixl + inc ixl + dec e + jp nz, 2$ +7$: + pop ix + pop de + + dec d + jr z, 6$ + + push de + + ld bc, #0x40 + add ix, bc + ld a, ixh + cp #>(.VDP_TILEMAP+0x0700) + jp c, 4$ + ld ixh, #>.VDP_TILEMAP +4$: + push ix + jp 1$ +6$: + ENABLE_VBLANK_COPY ; switch ON copy shadow SAT + pop ix ; restore IX + ret + diff --git a/gbdk-lib/libc/targets/z80/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -11,6 +11,7 @@ ASSRC = outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ + fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ font.s \ diff --git a/gbdk-lib/libc/targets/z80/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -11,6 +11,7 @@ ASSRC = outi.s vmemcpy.s \ set_data.s set_2bpp_data.s \ set_tile_map.s set_tile_map_xy.s set_tile_map_compat.s set_tile_map_xy_compat.s \ set_tile_submap.s set_tile_submap_compat.s \ + fill_rect.s fill_rect_xy.s fill_rect_compat.s fill_rect_xy_compat.s \ metasprites.s metasprites_hide.s metasprites_hide_spr.s \ f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ font.s \

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