git.y1.nz

gbdk-2020

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

commit 39ef74f65376dd127a33900d553d46886fe427f3
parent d6eb0d001c6dd61a54f367b960a26a1f6683965e
Author: Toxa <untoxa@mail.ru>
Date:   Tue,  8 Aug 2023 19:41:06 +0300

SMS: metasprite clipping on the screen edges by X coordinate; update functions to match the new calling convention

Diffstat:
Mgbdk-lib/include/sms/metasprites.h20++++++++++----------
Mgbdk-lib/libc/targets/z80/sms_metasprites.s103++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mgbdk-lib/libc/targets/z80/sms_metasprites_flip.s98+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mgbdk-lib/libc/targets/z80/sms_metasprites_hide_spr.s18++++++++----------
4 files changed, 136 insertions(+), 103 deletions(-)

diff --git a/gbdk-lib/include/sms/metasprites.h b/gbdk-lib/include/sms/metasprites.h @@ -44,10 +44,10 @@ extern uint8_t __current_base_tile; extern uint8_t __render_shadow_OAM; -static uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); -static uint8_t __move_metasprite_flipx(uint8_t id, uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); -static uint8_t __move_metasprite_flipy(uint8_t id, uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); -static uint8_t __move_metasprite_flipxy(uint8_t id, uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); +static uint8_t __move_metasprite(uint8_t id, uint16_t x, uint16_t y); +static uint8_t __move_metasprite_flipx(uint8_t id, uint16_t x, uint16_t y); +static uint8_t __move_metasprite_flipy(uint8_t id, uint16_t x, uint16_t y); +static uint8_t __move_metasprite_flipxy(uint8_t id, uint16_t x, uint16_t y); static void __hide_metasprite(uint8_t id) Z88DK_FASTCALL PRESERVES_REGS(iyh, iyl); /** @@ -55,7 +55,7 @@ static void __hide_metasprite(uint8_t id) Z88DK_FASTCALL PRESERVES_REGS(iyh, iyl * @param from start OAM index * @param to finish OAM index */ -void hide_sprites_range(UINT8 from, UINT8 to) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); +void hide_sprites_range(UINT8 from, UINT8 to) PRESERVES_REGS(iyh, iyl); /** Moves metasprite to the absolute position x and y @@ -77,7 +77,7 @@ void hide_sprites_range(UINT8 from, UINT8 to) Z88DK_CALLEE PRESERVES_REGS(iyh, i @return Number of hardware sprites used to draw this metasprite */ -inline uint8_t move_metasprite_ex(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint8_t x, uint8_t y) { +inline uint8_t move_metasprite_ex(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint16_t x, uint16_t y) { base_prop; __current_metasprite = metasprite; __current_base_tile = base_tile; @@ -86,7 +86,7 @@ inline uint8_t move_metasprite_ex(const metasprite_t * metasprite, uint8_t base_ /** Obsolete. This function has been replaced by move_metasprite_ex() */ -inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { +inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint16_t x, uint16_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; return __move_metasprite(base_sprite, x, y); @@ -114,7 +114,7 @@ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_til @see move_metasprite() */ -inline uint8_t move_metasprite_flipx(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint8_t x, uint8_t y) { +inline uint8_t move_metasprite_flipx(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint16_t x, uint16_t y) { base_prop; __current_metasprite = metasprite; __current_base_tile = base_tile; @@ -143,7 +143,7 @@ inline uint8_t move_metasprite_flipx(const metasprite_t * metasprite, uint8_t ba @see move_metasprite() */ -inline uint8_t move_metasprite_flipy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint8_t x, uint8_t y) { +inline uint8_t move_metasprite_flipy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint16_t x, uint16_t y) { base_prop; __current_metasprite = metasprite; __current_base_tile = base_tile; @@ -172,7 +172,7 @@ inline uint8_t move_metasprite_flipy(const metasprite_t * metasprite, uint8_t ba @see move_metasprite() */ -inline uint8_t move_metasprite_flipxy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint8_t x, uint8_t y) { +inline uint8_t move_metasprite_flipxy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, uint16_t x, uint16_t y) { base_prop; __current_metasprite = metasprite; __current_base_tile = base_tile; diff --git a/gbdk-lib/libc/targets/z80/sms_metasprites.s b/gbdk-lib/libc/targets/z80/sms_metasprites.s @@ -3,9 +3,11 @@ .title "Metasprites" .module Metasprites + .ez80 + .area _DATA -___current_metasprite:: +___current_metasprite:: .ds 0x02 ___current_base_tile:: .ds 0x01 @@ -13,70 +15,85 @@ ___current_base_tile:: .area _INITIALIZED ___render_shadow_OAM:: .ds 0x01 - + .area _INITIALIZER .db #>_shadow_OAM .area _CODE -; uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y) __z88dk_callee __preserves_regs(iyh,iyl); - +; uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y); +; a == id +; de == x +; (sp+2) == y ___move_metasprite:: - ld hl, #4 - add hl, sp + ld iyl, a - ld b, (hl) - dec hl - ld c, (hl) - dec hl - ld e, (hl) + pop hl + pop bc + push hl - ld hl, (___current_metasprite) + push af + push ix + + ld ix, (___current_metasprite) ld a, (___render_shadow_OAM) - ld d, a + ld iyh, a 1$: - ld a, (hl) ; dy - inc hl + ld a, 0(ix) ; dy cp #0x80 jp z, 2$ - add b - ld b, a - cp #0xD0 - jp nz, 3$ - ld a, #0xC0 -3$: - ld (de), a - push de + inc ix - ld a, e - add a - add #0x40 - ld e, a - - ld a, (hl) ; dx - inc hl add c ld c, a - ld (de), a - inc e + cp #0xD0 + jp z, 3$ + + ld 0(iy), a + + ld a, 0(ix) ; dx + add a, a + sbc a, a + ld h, a + ld l, 0(ix) + inc ix + add hl, de + ex de, hl + ld a, d + or a + jp nz, 4$ + + ld a, iyl + rlca + ld iyl, a + + ld 0x40(iy), e ld a, (___current_base_tile) - add (hl) ; tile - inc hl - ld (de), a + add 0(ix) ; tile + inc ix + ld 0x41(iy), a - pop de - inc e + ld a, iyl + rrca + inc a + ld iyl, a jp 1$ +3$: + inc ix +4$: + ld 0(iy), #0xC0 + inc ix + inc iyl + jp 1$ + 2$: - pop hl + pop ix pop bc - inc sp - push hl - ld a, e - sub c - ld l, a + + ld a, iyl + sub b ret diff --git a/gbdk-lib/libc/targets/z80/sms_metasprites_flip.s b/gbdk-lib/libc/targets/z80/sms_metasprites_flip.s @@ -3,6 +3,8 @@ .title "Metasprites" .module Metasprites + .ez80 + .area _DATA .globl ___current_metasprite, ___current_base_tile, ___render_shadow_OAM @@ -10,69 +12,85 @@ .area _CODE .macro MOVE_METASPRITE_BODY neg_dx neg_dy - ld hl, #4 - add hl, sp + ld iyl, a - ld b, (hl) - dec hl - ld c, (hl) - dec hl - ld e, (hl) + pop hl + pop bc + push hl - ld hl, (___current_metasprite) + push af + push ix + + ld ix, (___current_metasprite) ld a, (___render_shadow_OAM) - ld d, a + ld iyh, a 1$: - ld a, (hl) ; dy - inc hl + ld a, 0(ix) ; dy cp #0x80 jp z, 2$ .ifne neg_dy neg ; apply flipy (or no-op) .endif - add b - ld b, a - cp #0xD0 - jp nz, 3$ - ld a, #0xC0 -3$: - ld (de), a + inc ix - push de + add c + ld c, a + cp #0xD0 + jp z, 3$ - ld a, e - add a - add #0x40 - ld e, a + ld 0(iy), a - ld a, (hl) ; dx - inc hl + ld a, 0(ix) ; dx .ifne neg_dx neg ; apply flipx (or no-op) .endif - add c - ld c, a - ld (de), a - inc e + add a, a + sbc a, a + ld h, a + ld a, 0(ix) +.ifne neg_dx + neg ; apply flipx (or no-op) +.endif + ld l, a + inc ix + add hl, de + ex de, hl + ld a, d + or a + jp nz, 4$ + + ld a, iyl + rlca + ld iyl, a + + ld 0x40(iy), e ld a, (___current_base_tile) - add (hl) ; tile - inc hl - ld (de), a + add 0(ix) ; tile + inc ix + ld 0x41(iy), a - pop de - inc e + ld a, iyl + rrca + inc a + ld iyl, a jp 1$ +3$: + inc ix +4$: + ld 0(iy), #0xC0 + inc ix + inc iyl + jp 1$ + 2$: - pop hl + pop ix pop bc - inc sp - push hl - ld a, e - sub c - ld l, a + + ld a, iyl + sub b ret .endm diff --git a/gbdk-lib/libc/targets/z80/sms_metasprites_hide_spr.s b/gbdk-lib/libc/targets/z80/sms_metasprites_hide_spr.s @@ -7,15 +7,13 @@ .area _CODE -; void hide_sprites_range(UINT8 from, UINT8 to) __z88dk_callee __preserves_regs(iyh,iyl); +; void hide_sprites_range(UINT8 from, UINT8 to); _hide_sprites_range:: - pop hl - pop de - push hl + ld e, a - ld a, d - cp #(64+1) + ld a, l + cp #(64+1) ret nc sub e @@ -23,19 +21,19 @@ _hide_sprites_range:: ret z ld c, a - xor a - ld b, a + ld b, #0 ld hl, #___render_shadow_OAM ld h, (hl) ld l, e - ld d, h - inc e ld (hl), #0xC0 dec c ret z + ld d, h + inc e + ldir 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.