gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 585b1e3cdbc33a3b860954aef64fde917c6b7f65 parent b0d77a5cd1d0a31ecc75c729da0f09d2530714e1 Author: Toxa <untoxa@mail.ru> Date: Tue, 29 Nov 2022 22:46:45 +0300 refactor metasprite functions, add offset for the sprite properties Diffstat:
| M | gbdk-lib/examples/cross-platform/metasprites/src/metasprites.c | 8 | ++++---- |
| M | gbdk-lib/include/gb/metasprites.h | 56 | ++++++++++++++++++++++++++++++++++++++++++++++++++------ |
| M | gbdk-lib/include/msx/metasprites.h | 10 | ++++++++++ |
| M | gbdk-lib/include/nes/metasprites.h | 48 | ++++++++++++++++++++++++++++++++++++++++++------ |
| M | gbdk-lib/include/sms/metasprites.h | 11 | ++++++++++- |
| M | gbdk-lib/libc/targets/mos6502/nes/metasprites.s | 3 | +++ |
| M | gbdk-lib/libc/targets/sm83/metasprites.s | 6 | +++++- |
| M | gbdk-lib/libc/targets/sm83/metasprites_flip.s | 17 | +++++++++++++---- |
8 files changed, 137 insertions(+), 22 deletions(-)
diff --git a/gbdk-lib/examples/cross-platform/metasprites/src/metasprites.c b/gbdk-lib/examples/cross-platform/metasprites/src/metasprites.c @@ -127,15 +127,15 @@ void main(void) { else switch (rot) { #if HARDWARE_SPRITE_CAN_FLIP_V - case 1: hiwater = move_metasprite_hflip(sprite_metasprites[idx], TILE_NUM_START, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; + case 1: hiwater = move_metasprite_flipy(sprite_metasprites[idx], TILE_NUM_START, 0, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; #endif #if HARDWARE_SPRITE_CAN_FLIP_H && HARDWARE_SPRITE_CAN_FLIP_V - case 2: hiwater = move_metasprite_hvflip(sprite_metasprites[idx], TILE_NUM_START, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; + case 2: hiwater = move_metasprite_flipxy(sprite_metasprites[idx], TILE_NUM_START, 0, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; #endif #if HARDWARE_SPRITE_CAN_FLIP_H - case 3: hiwater = move_metasprite_vflip(sprite_metasprites[idx], TILE_NUM_START, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; + case 3: hiwater = move_metasprite_flipx(sprite_metasprites[idx], TILE_NUM_START, 0, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; #endif - default: hiwater = move_metasprite(sprite_metasprites[idx], TILE_NUM_START, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; + default: hiwater = move_metasprite_ex(sprite_metasprites[idx], TILE_NUM_START, 0, SPR_NUM_START, (PosX >> 4), (PosY >> 4)); break; }; // Hide rest of the hardware sprites, because amount of sprites differ between animation frames. diff --git a/gbdk-lib/include/gb/metasprites.h b/gbdk-lib/include/gb/metasprites.h @@ -96,10 +96,14 @@ typedef struct metasprite_t { extern const void * __current_metasprite; extern uint8_t __current_base_tile; +extern uint8_t __current_base_prop; extern uint8_t __render_shadow_OAM; static uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y) OLDCALL; +static uint8_t __move_metasprite_flipx(uint8_t id, uint8_t x, uint8_t y) OLDCALL; +static uint8_t __move_metasprite_flipy(uint8_t id, uint8_t x, uint8_t y) OLDCALL; +static uint8_t __move_metasprite_flipxy(uint8_t id, uint8_t x, uint8_t y) OLDCALL; static uint8_t __move_metasprite_vflip(uint8_t id, uint8_t x, uint8_t y) OLDCALL; static uint8_t __move_metasprite_hflip(uint8_t id, uint8_t x, uint8_t y) OLDCALL; static uint8_t __move_metasprite_hvflip(uint8_t id, uint8_t x, uint8_t y) OLDCALL; @@ -136,13 +140,23 @@ void hide_sprites_range(UINT8 from, UINT8 to) OLDCALL PRESERVES_REGS(b, c); @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) { + __current_metasprite = metasprite; + __current_base_tile = base_tile; + __current_base_prop = base_prop; + return __move_metasprite(base_sprite, x, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; + __current_base_prop = 0; return __move_metasprite(base_sprite, x, y); } -/** Moves metasprite to the absolute position x and y, __flipped on the Y axis__ +/** Moves metasprite to the absolute position x and y, __flipped by X__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -150,7 +164,7 @@ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_til @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on the Y axis only. + Same as @ref move_metasprite(), but with the metasprite flipped by X. Sets: \li __current_metasprite = metasprite; @@ -165,14 +179,24 @@ 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) { + __current_metasprite = metasprite; + __current_base_tile = base_tile; + __current_base_prop = base_prop; + return __move_metasprite_flipx(base_sprite, x - 8, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; + __current_base_prop = 0; return __move_metasprite_vflip(base_sprite, x - 8, y); } -/** Moves metasprite to the absolute position x and y, __flipped on the X axis__ +/** Moves metasprite to the absolute position x and y, __flipped by Y__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -180,7 +204,7 @@ inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t ba @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on the X axis only. + Same as @ref move_metasprite(), but with the metasprite flipped by Y. Sets: \li __current_metasprite = metasprite; @@ -195,13 +219,23 @@ inline uint8_t move_metasprite_vflip(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) { + __current_metasprite = metasprite; + __current_base_tile = base_tile; + __current_base_prop = base_prop; + return __move_metasprite_flipy(base_sprite, x, y - ((LCDC_REG & 0x04U) ? 16 : 8) ); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_hflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; + __current_base_prop = 0; return __move_metasprite_hflip(base_sprite, x, y - ((LCDC_REG & 0x04U) ? 16 : 8) ); } -/** Moves metasprite to the absolute position x and y, __flipped on the X and Y axis__ +/** Moves metasprite to the absolute position x and y, __flipped by X and Y__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -209,7 +243,7 @@ inline uint8_t move_metasprite_hflip(const metasprite_t * metasprite, uint8_t ba @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on both the X and Y axis. + Same as @ref move_metasprite(), but with the metasprite flipped by X and Y. Sets: \li __current_metasprite = metasprite; @@ -224,9 +258,19 @@ inline uint8_t move_metasprite_hflip(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) { + __current_metasprite = metasprite; + __current_base_tile = base_tile; + __current_base_prop = base_prop; + return __move_metasprite_flipxy(base_sprite, x - 8, y - ((LCDC_REG & 0x04U) ? 16 : 8)); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_hvflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; + __current_base_prop = 0; return __move_metasprite_hvflip(base_sprite, x - 8, y - ((LCDC_REG & 0x04U) ? 16 : 8)); } diff --git a/gbdk-lib/include/msx/metasprites.h b/gbdk-lib/include/msx/metasprites.h @@ -95,12 +95,22 @@ 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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite(base_sprite, x, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; return __move_metasprite(base_sprite, x, y); } + /** Hides a metasprite from the screen @param metasprite Pointer to first struct of the desired metasprite frame diff --git a/gbdk-lib/include/nes/metasprites.h b/gbdk-lib/include/nes/metasprites.h @@ -125,13 +125,22 @@ void hide_sprites_range(UINT8 from, UINT8 to) OLDCALL; @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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite(base_sprite, x, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; return __move_metasprite(base_sprite, x, y); } -/** Moves metasprite to the absolute position x and y, __flipped on the Y axis__ +/** Moves metasprite to the absolute position x and y, __flipped by X__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -139,7 +148,7 @@ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_til @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on the Y axis only. + Same as @ref move_metasprite(), but with the metasprite flipped by X. Sets: \li __current_metasprite = metasprite; @@ -152,6 +161,15 @@ 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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite_vflip(base_sprite, x - 8, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; @@ -159,7 +177,7 @@ inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t ba } -/** Moves metasprite to the absolute position x and y, __flipped on the X axis__ +/** Moves metasprite to the absolute position x and y, __flipped by Y__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -167,7 +185,7 @@ inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t ba @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on the X axis only. + Same as @ref move_metasprite(), but with the metasprite flipped by Y. Sets: \li __current_metasprite = metasprite; @@ -180,13 +198,22 @@ inline uint8_t move_metasprite_vflip(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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite_hflip(base_sprite, x, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8) ); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_hflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; return __move_metasprite_hflip(base_sprite, x, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8) ); } -/** Moves metasprite to the absolute position x and y, __flipped on the X and Y axis__ +/** Moves metasprite to the absolute position x and y, __flipped by X and Y__ @param metasprite Pointer to the first struct of the metasprite (for the desired frame) @param base_tile Number of the first tile where the metasprite's tiles start @@ -194,7 +221,7 @@ inline uint8_t move_metasprite_hflip(const metasprite_t * metasprite, uint8_t ba @param x Absolute x coordinate of the sprite @param y Absolute y coordinate of the sprite - Same as @ref move_metasprite(), but with the metasprite flipped on both the X and Y axis. + Same as @ref move_metasprite(), but with the metasprite flipped by X and Y. Sets: \li __current_metasprite = metasprite; @@ -207,6 +234,15 @@ inline uint8_t move_metasprite_hflip(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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite_hvflip(base_sprite, x - 8, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8)); +} + +/** Obsolete +*/ inline uint8_t move_metasprite_hvflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; diff --git a/gbdk-lib/include/sms/metasprites.h b/gbdk-lib/include/sms/metasprites.h @@ -92,7 +92,16 @@ void hide_sprites_range(UINT8 from, UINT8 to) Z88DK_CALLEE PRESERVES_REGS(iyh, i \li __current_base_tile = base_tile; @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) { + base_prop; + __current_metasprite = metasprite; + __current_base_tile = base_tile; + return __move_metasprite(base_sprite, x, y); +} + +/** Obsolete +*/ inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { __current_metasprite = metasprite; __current_base_tile = base_tile; diff --git a/gbdk-lib/libc/targets/mos6502/nes/metasprites.s b/gbdk-lib/libc/targets/mos6502/nes/metasprites.s @@ -86,6 +86,7 @@ ___move_metasprite_end: jmp .move_metasprite_epilogue ; uint8_t __move_metasprite_vflip(uint8_t id, uint8_t x, uint8_t y) +___move_metasprite_flipx:: ___move_metasprite_vflip:: jsr .move_metasprite_prologue ___move_metasprite_vflip_loop: @@ -121,6 +122,7 @@ ___move_metasprite_vflip_end: jmp .move_metasprite_epilogue ; uint8_t __move_metasprite_hflip(uint8_t id, uint8_t x, uint8_t y) +___move_metasprite_flipy:: ___move_metasprite_hflip:: jsr .move_metasprite_prologue ___move_metasprite_hflip_loop: @@ -157,6 +159,7 @@ ___move_metasprite_hflip_end: jmp .move_metasprite_epilogue ; uint8_t __move_metasprite_hvflip(uint8_t id, uint8_t x, uint8_t y) +___move_metasprite_flipxy:: ___move_metasprite_hvflip:: jsr .move_metasprite_prologue ___move_metasprite_hvflip_loop: diff --git a/gbdk-lib/libc/targets/sm83/metasprites.s b/gbdk-lib/libc/targets/sm83/metasprites.s @@ -9,6 +9,8 @@ ___current_metasprite:: .ds 0x02 ___current_base_tile:: .ds 0x01 +___current_base_prop:: + .ds 0x01 .area _INITIALIZED ___render_shadow_OAM:: @@ -63,7 +65,9 @@ ___move_metasprite:: ld (de), a inc e - ld a, (hl+) ; props + ld a, (___current_base_prop) + add (hl) ; props + inc hl ld (de), a inc e diff --git a/gbdk-lib/libc/targets/sm83/metasprites_flip.s b/gbdk-lib/libc/targets/sm83/metasprites_flip.s @@ -5,12 +5,13 @@ .area _DATA - .globl ___current_metasprite, ___current_base_tile, ___render_shadow_OAM + .globl ___current_metasprite, ___current_base_tile, ___current_base_prop, ___render_shadow_OAM .area _CODE ; uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y) +___move_metasprite_flipy:: ___move_metasprite_hflip:: ldhl sp, #4 ld a, (hl-) @@ -55,7 +56,9 @@ ___move_metasprite_hflip:: ld (de), a inc e - ld a, (hl+) ; props + ld a, (___current_base_prop) + add (hl) ; props + inc hl xor #0x40 ld (de), a inc e @@ -74,6 +77,7 @@ ___move_metasprite_hflip:: ret +___move_metasprite_flipx:: ___move_metasprite_vflip:: ldhl sp, #4 ld a, (hl-) @@ -118,7 +122,9 @@ ___move_metasprite_vflip:: ld (de), a inc e - ld a, (hl+) ; props + ld a, (___current_base_prop) + add (hl) ; props + inc hl xor #0x20 ld (de), a inc e @@ -137,6 +143,7 @@ ___move_metasprite_vflip:: ret +___move_metasprite_flipxy:: ___move_metasprite_hvflip:: ldhl sp, #4 ld a, (hl-) @@ -183,7 +190,9 @@ ___move_metasprite_hvflip:: ld (de), a inc e - ld a, (hl+) ; props + ld a, (___current_base_prop) + add (hl) ; props + inc hl xor #0x60 ld (de), a inc e
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.