git.y1.nz

gbdk-2020

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

gbdk-lib/include/nes/metasprites.h

      1 /** @file nes/metasprites.h
      2 
      3     # Metasprite support
      4 
      5     A metasprite is a larger sprite made up from a
      6     collection of smaller individual hardware sprites.
      7     Different frames of the same metasprites can share
      8     tile data.
      9 
     10     See the main @ref metasprite_main_docs "metasprite docs"
     11     under the game Boy platform for additional details.
     12 */
     13 
     14 #ifndef _METASPRITES_H_INCLUDE
     15 #define _METASPRITES_H_INCLUDE
     16 
     17 #include <nes/hardware.h>
     18 #include <types.h>
     19 #include <stdint.h>
     20 
     21 /** Metasprite sub-item structure
     22     @param dy        (int8_t)  Y coordinate of the sprite relative to the metasprite origin (pivot)
     23     @param dx        (int8_t)  X coordinate of the sprite relative to the metasprite origin (pivot)
     24     @param dtile     (uint8_t) Start tile relative to the metasprites own set of tiles
     25     @param props     (uint8_t) Property Flags
     26 
     27     Metasprites are built from multiple metasprite_t items (one for each sub-sprite)
     28     and a pool of tiles they reference. If a metasprite has multiple frames then each
     29     frame will be built from some number of metasprite_t items (which may vary based
     30     on how many sprites are required for that particular frame).
     31 
     32     A metasprite frame is terminated with a {metasprite_end} entry.
     33 */
     34 typedef struct metasprite_t {
     35     int8_t  dy, dx;
     36     uint8_t dtile;
     37     uint8_t props;
     38 } metasprite_t;
     39 
     40 #define metasprite_end -128
     41 #define METASPR_ITEM(dy,dx,dt,a) {(dy),(dx),(dt),(a)}
     42 #define METASPR_TERM {metasprite_end}
     43 
     44 extern const void * __current_metasprite;
     45 extern uint8_t __current_base_tile;
     46 extern uint8_t __current_base_prop;
     47 extern uint8_t __render_shadow_OAM;
     48 
     49 
     50 static uint8_t __move_metasprite(uint8_t id, int16_t x, int16_t y) OLDCALL;
     51 static uint8_t __move_metasprite_flipx(uint8_t id, int16_t x, int16_t y) OLDCALL;
     52 static uint8_t __move_metasprite_flipy(uint8_t id, int16_t x, int16_t y) OLDCALL;
     53 static uint8_t __move_metasprite_flipxy(uint8_t id, int16_t x, int16_t y) OLDCALL;
     54 static uint8_t __move_metasprite_vflip(uint8_t id, int16_t x, int16_t y) OLDCALL;
     55 static uint8_t __move_metasprite_hflip(uint8_t id, int16_t x, int16_t y) OLDCALL;
     56 static uint8_t __move_metasprite_hvflip(uint8_t id, int16_t x, int16_t y) OLDCALL;
     57 static void __hide_metasprite(uint8_t id) OLDCALL;
     58 
     59 /**
     60  * Hides all hardware sprites in range from <= X < to
     61  * @param from start OAM index
     62  * @param to finish OAM index
     63  */
     64 void hide_sprites_range(uint8_t from, uint8_t to) OLDCALL;
     65 
     66 /** Moves metasprite to the absolute position x and y
     67 
     68     @param metasprite   Pointer to the first struct of the metasprite (for the desired frame)
     69     @param base_tile    Number of the first tile where the metasprite's tiles start
     70     @param base_prop    Base sprite property flags
     71     @param base_sprite  Number of the first hardware sprite to be used by the metasprite
     72     @param x            Absolute x coordinate of the sprite
     73     @param y            Absolute y coordinate of the sprite
     74 
     75     Moves __metasprite__ to the absolute position __x__ and __y__
     76     (with __no flip__ on the X or Y axis). Hardware sprites are
     77     allocated starting from __base_sprite__, using tiles
     78     starting from __base_tile__.
     79 
     80     Sets:
     81     \li __current_metasprite = metasprite;
     82     \li __current_base_tile = base_tile;
     83 
     84     Note: Overwrites OAM sprite properties (such as palette), see
     85           @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
     86 
     87     @return Number of hardware sprites used to draw this metasprite
     88  */
     89 inline uint8_t move_metasprite_ex(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, int16_t x, int16_t y) {
     90     base_prop;
     91     __current_metasprite = metasprite;
     92     __current_base_tile = base_tile;
     93     __current_base_prop = base_prop;
     94     return __move_metasprite(base_sprite, x, y);
     95 }
     96 
     97 /** Obsolete. Replaced by move_metasprite_ex()
     98 */
     99 inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, int16_t x, int16_t y) {
    100     __current_metasprite = metasprite;
    101     __current_base_tile = base_tile;
    102     __current_base_prop = 0;
    103     return __move_metasprite(base_sprite, x, y);
    104 }
    105 
    106 /** Moves metasprite to the absolute position x and y, __flipped by X (horizontally)__
    107 
    108     @param metasprite   Pointer to the first struct of the metasprite (for the desired frame)
    109     @param base_tile    Number of the first tile where the metasprite's tiles start
    110     @param base_prop    Base sprite property flags
    111     @param base_sprite  Number of the first hardware sprite to be used by the metasprite
    112     @param x            Absolute x coordinate of the sprite
    113     @param y            Absolute y coordinate of the sprite
    114 
    115     Same as @ref move_metasprite(), but with the metasprite flipped by X (horizontally).
    116 
    117     Sets:
    118     \li __current_metasprite = metasprite;
    119     \li __current_base_tile = base_tile;
    120 
    121     Note: Overwrites OAM sprite properties (such as palette), see
    122           @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
    123 
    124     @return Number of hardware sprites used to draw this metasprite
    125 
    126     @see move_metasprite()
    127 */
    128 inline uint8_t move_metasprite_flipx(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, int16_t x, int16_t y) {
    129     base_prop;
    130     __current_metasprite = metasprite;
    131     __current_base_tile = base_tile;
    132     __current_base_prop = base_prop;
    133     return __move_metasprite_flipx(base_sprite, x - 8, y);
    134 }
    135 
    136 /** Obsolete. Replaced by move_metasprite_flipx()
    137 */
    138 inline uint8_t move_metasprite_vflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, int16_t x, int16_t y) {
    139     __current_metasprite = metasprite;
    140     __current_base_tile = base_tile;
    141     __current_base_prop = 0;
    142     return __move_metasprite_vflip(base_sprite, x - 8, y);
    143 }
    144 
    145 
    146 /** Moves metasprite to the absolute position x and y, __flipped by Y (vertically)__
    147 
    148     @param metasprite   Pointer to the first struct of the metasprite (for the desired frame)
    149     @param base_tile    Number of the first tile where the metasprite's tiles start
    150     @param base_prop    Base sprite property flags
    151     @param base_sprite  Number of the first hardware sprite to be used by the metasprite
    152     @param x            Absolute x coordinate of the sprite
    153     @param y            Absolute y coordinate of the sprite
    154 
    155     Same as @ref move_metasprite(), but with the metasprite flipped by Y (vertically).
    156 
    157     Sets:
    158     \li __current_metasprite = metasprite;
    159     \li __current_base_tile = base_tile;
    160 
    161     Note: Overwrites OAM sprite properties (such as palette), see
    162           @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
    163 
    164     @return Number of hardware sprites used to draw this metasprite
    165 
    166     @see move_metasprite()
    167 */
    168 inline uint8_t move_metasprite_flipy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, int16_t x, int16_t y) {
    169     base_prop;
    170     __current_metasprite = metasprite;
    171     __current_base_tile = base_tile;
    172     __current_base_prop = base_prop;
    173     return __move_metasprite_flipy(base_sprite, x, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8) );
    174 }
    175 
    176 /** Obsolete. Replaced by move_metasprite_flipy()
    177 */
    178 inline uint8_t move_metasprite_hflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, int16_t x, int16_t y) {
    179     __current_metasprite = metasprite;
    180     __current_base_tile = base_tile;
    181     __current_base_prop = 0;
    182     return __move_metasprite_hflip(base_sprite, x, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8) );
    183 }
    184 
    185 /** Moves metasprite to the absolute position x and y, __flipped by X and Y (horizontally and vertically)__
    186 
    187     @param metasprite   Pointer to the first struct of the metasprite (for the desired frame)
    188     @param base_tile    Number of the first tile where the metasprite's tiles start
    189     @param base_prop    Base sprite property flags
    190     @param base_sprite  Number of the first hardware sprite to be used by the metasprite
    191     @param x            Absolute x coordinate of the sprite
    192     @param y            Absolute y coordinate of the sprite
    193 
    194     Same as @ref move_metasprite(), but with the metasprite flipped by X and Y (horizontally and vertically).
    195 
    196     Sets:
    197     \li __current_metasprite = metasprite;
    198     \li __current_base_tile = base_tile;
    199 
    200     Note: Overwrites OAM sprite properties (such as palette), see
    201           @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
    202 
    203     @return Number of hardware sprites used to draw this metasprite
    204 
    205     @see move_metasprite()
    206 */
    207 inline uint8_t move_metasprite_flipxy(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_prop, uint8_t base_sprite, int16_t x, int16_t y) {
    208     base_prop;
    209     __current_metasprite = metasprite;
    210     __current_base_tile = base_tile;
    211     __current_base_prop = base_prop;
    212     return __move_metasprite_flipxy(base_sprite, x - 8, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8));
    213 }
    214 
    215 /** Obsolete. Replaced by move_metasprite_flipxy()
    216 */
    217 inline uint8_t move_metasprite_hvflip(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, int16_t x, int16_t y) {
    218     __current_metasprite = metasprite;
    219     __current_base_tile = base_tile;
    220     __current_base_prop = 0;
    221     return __move_metasprite_hvflip(base_sprite, x - 8, y - ((shadow_PPUCTRL & PPUCTRL_SPR_8X16) ? 16 : 8));
    222 }
    223 
    224 /** Hides a metasprite from the screen
    225 
    226     @param metasprite    Pointer to first struct of the desired metasprite frame
    227     @param base_sprite   Number of hardware sprite to start with
    228 
    229     Sets:
    230     \li __current_metasprite = metasprite;
    231 
    232  **/
    233 inline void hide_metasprite(const metasprite_t * metasprite, uint8_t base_sprite) {
    234     __current_metasprite = metasprite;
    235     __hide_metasprite(base_sprite);
    236 }
    237 
    238 #endif

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