git.y1.nz

gbdk-2020

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

commit be8dbcb50c1bdcdee7cf66802cc78bd2e8519d4b
parent 35433ab344502647cc52bafee6424537ee9c5051
Author: Toxa <untoxa@mail.ru>
Date:   Wed, 25 Aug 2021 19:19:35 +0300

SMS/GG: set_tile_submap() and set_*_submap() todo: modulus by Y

Diffstat:
Mgbdk-lib/include/sms/sms.h10++++++++++
Mgbdk-lib/libc/targets/z80/gg/Makefile1+
Mgbdk-lib/libc/targets/z80/gg/global.s23+++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/set_tile_submap.s141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/libc/targets/z80/set_tile_submap_compat.s148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mgbdk-lib/libc/targets/z80/sms/Makefile1+
Mgbdk-lib/libc/targets/z80/sms/global.s23+++++++++++++++++++++++
7 files changed, 347 insertions(+), 0 deletions(-)

diff --git a/gbdk-lib/include/sms/sms.h b/gbdk-lib/include/sms/sms.h @@ -367,6 +367,16 @@ void set_tile_map(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *til #define set_win_tiles set_tile_map_compat void set_tile_map_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles) __z88dk_callee __preserves_regs(iyh, iyl); +void set_tile_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl); + +void set_tile_submap_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl); +inline void set_bkg_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) { + set_tile_submap_compat(x, y, w, h, map_w, map); +} +inline void set_win_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *map, uint8_t map_w) { + set_tile_submap_compat(x, y, w, h, map_w, map); +} + /** 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/gg/Makefile b/gbdk-lib/libc/targets/z80/gg/Makefile @@ -10,6 +10,7 @@ CSRC = 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 \ 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/gg/global.s b/gbdk-lib/libc/targets/z80/gg/global.s @@ -249,3 +249,26 @@ lbl: xor a ld (__shadow_OAM_OFF), a .endm + +.macro ADD_A_REG16 regH regL + add regL + ld regL, a + adc regH + sub regL + ld regH, a +.endm + +.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 + ; Multiply DE by A, return result in HL; preserves: BC + ld hl, #0 +lbl1: + srl a + jp nc, lbl2 + add hl, de +lbl2: + jp z, lbl3 + sla e + rl d + jp lbl1 +lbl3: +.endm diff --git a/gbdk-lib/libc/targets/z80/set_tile_submap.s b/gbdk-lib/libc/targets/z80/set_tile_submap.s @@ -0,0 +1,140 @@ + .include "global.s" + + .title "VRAM utilities" + .module VRAMUtils + + .ez80 + + .area _HOME + +; void set_tile_submap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl); +_set_tile_submap:: + pop hl ; HL = ret + pop bc ; BC = YX + pop de ; DE = WH + + dec sp + pop af + sub d + ld (.image_tile_width), a ; .image_tile_width contains corrected width + + ex (sp), hl ; HL = data + ex de, hl ; HL = WH, DE = data + + push hl + push de + + add h + ld e, a + ld d, #0 + ld a, b + MUL_DE_BY_A_RET_HL + ld a, c + ADD_A_REG16 h, l + + pop de + add hl, de + ex de, hl + + pop hl + + ld a, b + ld b, d + ld d, a + ld a, c + and #0x1f + ld c, e + ld e, a ; BC = data, DE = YX + + ;; Set background tile table from (BC) at XY = DE of size WH = HL +.set_tile_submap_xy:: + push hl + ld hl, #.VDP_TILEMAP + + ;; Set background tile from (BC) at YX = DE, size WH on stack, to VRAM from address (HL) +.set_tile_submap_map_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 + outi + VDP_DELAY + outi + + 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 a, (.image_tile_width) + ADD_A_REG16 h, l + + 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/set_tile_submap_compat.s b/gbdk-lib/libc/targets/z80/set_tile_submap_compat.s @@ -0,0 +1,147 @@ + .include "global.s" + + .title "VRAM utilities" + .module VRAMUtils + + .ez80 + + .area _BSS + +.image_tile_width:: + .ds 0x01 + + .area _HOME + +; void set_tile_submap_compat(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t map_w, const uint8_t *map) __z88dk_callee __preserves_regs(iyh, iyl); +_set_tile_submap_compat:: + pop hl ; HL = ret + pop bc ; BC = YX + pop de ; DE = WH + + dec sp + pop af + sub e + ld (.image_tile_width), a ; .image_tile_width contains corrected width + + ex (sp), hl ; HL = data + ex de, hl ; HL = WH, DE = data + + push hl + push de + + add l + ld e, a + ld d, #0 + ld a, b + MUL_DE_BY_A_RET_HL + ld a, c + ADD_A_REG16 h, l + + pop de + add hl, de + ex de, hl + + pop hl + + ld a, b + ld b, d + ld d, a + ld a, c + and #0x1f + ld c, e + ld e, a ; BC = data, DE = YX + + ;; Set background tile table from (BC) at XY = DE of size WH = HL +.set_tile_submap_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) +.set_tile_submap_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 + outi + 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 a, (.image_tile_width) + ADD_A_REG16 h, l + + 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/sms/Makefile b/gbdk-lib/libc/targets/z80/sms/Makefile @@ -10,6 +10,7 @@ CSRC = 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 \ 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/global.s b/gbdk-lib/libc/targets/z80/sms/global.s @@ -249,3 +249,26 @@ lbl: xor a ld (__shadow_OAM_OFF), a .endm + +.macro ADD_A_REG16 regH regL + add regL + ld regL, a + adc regH + sub regL + ld regH, a +.endm + +.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 + ; Multiply DE by A, return result in HL; preserves: BC + ld hl, #0 +lbl1: + srl a + jp nc, lbl2 + add hl, de +lbl2: + jp z, lbl3 + sla e + rl d + jp lbl1 +lbl3: +.endm

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