gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/sms/metasprites.h
1 /** @file sms/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 <sms/sms.h>
18 #include <sms/hardware.h>
19 #include <types.h>
20 #include <stdint.h>
21
22 /** Metasprite sub-item structure
23 @param dy (int8_t) Y coordinate of the sprite relative to the metasprite origin (pivot)
24 @param dx (int8_t) X coordinate of the sprite relative to the metasprite origin (pivot)
25 @param dtile (uint8_t) Start tile relative to the metasprites own set of tiles
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 } metasprite_t;
38
39 #define metasprite_end -128
40 #define METASPR_ITEM(dy,dx,dt,a) {(dy),(dx),(dt)}
41 #define METASPR_TERM {metasprite_end}
42
43 extern const void * __current_metasprite;
44 extern uint8_t __current_base_tile;
45 extern uint8_t __render_shadow_OAM;
46
47
48 static uint8_t __move_metasprite(uint8_t id, int16_t x, int16_t y);
49 static uint8_t __move_metasprite_flipx(uint8_t id, int16_t x, int16_t y);
50 static uint8_t __move_metasprite_flipy(uint8_t id, int16_t x, int16_t y);
51 static uint8_t __move_metasprite_flipxy(uint8_t id, int16_t x, int16_t y);
52 static void __hide_metasprite(uint8_t id) Z88DK_FASTCALL PRESERVES_REGS(iyh, iyl);
53
54 /**
55 * Hides all hardware sprites in range from <= X < to
56 * @param from start OAM index
57 * @param to finish OAM index
58 */
59 void hide_sprites_range(uint8_t from, uint8_t to) PRESERVES_REGS(iyh, iyl);
60
61 /** Moves metasprite to the absolute position x and y
62
63 @param metasprite Pointer to the first struct of the metasprite (for the desired frame)
64 @param base_tile Number of the first tile where the metasprite's tiles start
65 @param base_prop Base sprite property flags (unused on this platform)
66 @param base_sprite Number of the first hardware sprite to be used by the metasprite
67 @param x Absolute x coordinate of the sprite
68 @param y Absolute y coordinate of the sprite
69
70 Moves __metasprite__ to the absolute position __x__ and __y__
71 (with __no flip__ on the X or Y axis). Hardware sprites are
72 allocated starting from __base_sprite__, using tiles
73 starting from __base_tile__.
74
75 Sets:
76 \li __current_metasprite = metasprite;
77 \li __current_base_tile = base_tile;
78
79 @return Number of hardware sprites used to draw this metasprite
80 */
81 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) {
82 base_prop;
83 __current_metasprite = metasprite;
84 __current_base_tile = base_tile;
85 return __move_metasprite(base_sprite, x, y);
86 }
87
88 /** Obsolete. This function has been replaced by move_metasprite_ex()
89 */
90 inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, int16_t x, int16_t y) {
91 __current_metasprite = metasprite;
92 __current_base_tile = base_tile;
93 return __move_metasprite(base_sprite, x, y);
94 }
95
96 /** Moves metasprite to the absolute position x and y, __flipped by X (horizontally)__
97
98 @param metasprite Pointer to the first struct of the metasprite (for the desired frame)
99 @param base_tile Number of the first tile where the metasprite's tiles start
100 @param base_prop Base sprite property flags (unused on this platform)
101 @param base_sprite Number of the first hardware sprite to be used by the metasprite
102 @param x Absolute x coordinate of the sprite
103 @param y Absolute y coordinate of the sprite
104
105 Same as @ref move_metasprite(), but with the metasprite flipped by X (horizontally).
106
107 Sets:
108 \li __current_metasprite = metasprite;
109 \li __current_base_tile = base_tile;
110
111 Note: Overwrites OAM sprite properties (such as palette), see
112 @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
113
114 @return Number of hardware sprites used to draw this metasprite
115
116 @see move_metasprite()
117 */
118 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) {
119 base_prop;
120 __current_metasprite = metasprite;
121 __current_base_tile = base_tile;
122 return __move_metasprite_flipx(base_sprite, x - 8, y);
123 }
124
125 /** Moves metasprite to the absolute position x and y, __flipped by Y (vertically)__
126
127 @param metasprite Pointer to the first struct of the metasprite (for the desired frame)
128 @param base_tile Number of the first tile where the metasprite's tiles start
129 @param base_prop Base sprite property flags (unused on this platform)
130 @param base_sprite Number of the first hardware sprite to be used by the metasprite
131 @param x Absolute x coordinate of the sprite
132 @param y Absolute y coordinate of the sprite
133
134 Same as @ref move_metasprite(), but with the metasprite flipped by Y (vertically).
135
136 Sets:
137 \li __current_metasprite = metasprite;
138 \li __current_base_tile = base_tile;
139
140 Note: Overwrites OAM sprite properties (such as palette), see
141 @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
142
143 @return Number of hardware sprites used to draw this metasprite
144
145 @see move_metasprite()
146 */
147 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) {
148 base_prop;
149 __current_metasprite = metasprite;
150 __current_base_tile = base_tile;
151 return __move_metasprite_flipy(base_sprite, x, y - ((__READ_VDP_REG(VDP_R1) & R1_SPR_8X16) ? 16 : 8) );
152 }
153
154 /** Moves metasprite to the absolute position x and y, __flipped by X and Y (horizontally and vertically)__
155
156 @param metasprite Pointer to the first struct of the metasprite (for the desired frame)
157 @param base_tile Number of the first tile where the metasprite's tiles start
158 @param base_prop Base sprite property flags (unused on this platform)
159 @param base_sprite Number of the first hardware sprite to be used by the metasprite
160 @param x Absolute x coordinate of the sprite
161 @param y Absolute y coordinate of the sprite
162
163 Same as @ref move_metasprite(), but with the metasprite flipped by X and Y (horizontally and vertically).
164
165 Sets:
166 \li __current_metasprite = metasprite;
167 \li __current_base_tile = base_tile;
168
169 Note: Overwrites OAM sprite properties (such as palette), see
170 @ref metasprite_and_sprite_properties "Metasprites and sprite properties".
171
172 @return Number of hardware sprites used to draw this metasprite
173
174 @see move_metasprite()
175 */
176 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) {
177 base_prop;
178 __current_metasprite = metasprite;
179 __current_base_tile = base_tile;
180 return __move_metasprite_flipxy(base_sprite, x - 8, y - ((__READ_VDP_REG(VDP_R1) & R1_SPR_8X16) ? 16 : 8));
181 }
182
183 /** Hides a metasprite from the screen
184
185 @param metasprite Pointer to first struct of the desired metasprite frame
186 @param base_sprite Number of hardware sprite to start with
187
188 Sets:
189 \li __current_metasprite = metasprite;
190
191 **/
192 inline void hide_metasprite(const metasprite_t * metasprite, uint8_t base_sprite) {
193 __current_metasprite = metasprite;
194 __hide_metasprite(base_sprite);
195 }
196
197 #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.