1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#ifndef GUARD_SPRITE_H
#define GUARD_SPRITE_H
#define MAX_SPRITES 64
struct SpriteSheet
{
u8 *data;
u16 size;
u16 tag;
};
struct SpriteFrameImage
{
u8 *data;
u16 size;
};
struct SpritePalette
{
u16 *data;
u16 tag;
};
struct AnimFrameCmd
{
// If the sprite has an array of images, this is the array index.
// If the sprite has a sheet, this is the tile offset.
u32 imageValue:16;
u32 duration:6;
u32 hFlip:1;
u32 vFlip:1;
};
struct AnimLoopCmd
{
u32 type:16;
u32 count:6;
};
struct AnimJumpCmd
{
u32 type:16;
u32 target:6;
};
union AnimCmd
{
s16 type;
struct AnimFrameCmd frame;
struct AnimLoopCmd loop;
struct AnimJumpCmd jump;
};
struct AffineAnimFrameCmd
{
s16 xScale;
s16 yScale;
u8 rotation;
u8 duration;
};
struct AffineAnimLoopCmd
{
s16 type;
u16 count;
};
struct AffineAnimJumpCmd
{
s16 type;
u16 target;
};
union AffineAnimCmd
{
s16 type;
struct AffineAnimFrameCmd frame;
struct AffineAnimLoopCmd loop;
struct AffineAnimJumpCmd jump;
};
struct AffineAnimState
{
u8 animNum;
u8 animCmdIndex;
u8 delayCounter;
u8 loopCounter;
s16 xScale;
s16 yScale;
u16 rotation;
};
enum
{
SUBSPRITES_OFF,
SUBSPRITES_ON,
SUBSPRITES_IGNORE_PRIORITY, // on but priority is ignored
};
struct Subsprite
{
u16 x;
u16 y;
u16 shape:2;
u16 size:2;
u16 tileOffset:10;
u16 priority:2;
};
struct SubspriteTable
{
u8 subspriteCount;
struct Subsprite *subsprites;
};
struct Sprite;
struct SpriteTemplate
{
u16 tileTag;
u16 paletteTag;
struct OamData *oam;
union AnimCmd **anims;
struct SpriteFrameImage *images;
union AffineAnimCmd **affineAnims;
void (*callback)(struct Sprite *);
};
struct Sprite
{
struct OamData oam;
union AnimCmd **anims;
struct SpriteFrameImage *images;
union AffineAnimCmd **affineAnims;
const struct SpriteTemplate *template;
struct SubspriteTable *subspriteTables;
void (*callback)(struct Sprite *);
/*0x20*/ struct Coords16 pos1;
/*0x24*/ struct Coords16 pos2;
/*0x28*/ s8 centerToCornerVecX;
/*0x29*/ s8 centerToCornerVecY;
/*0x2A*/ u8 animNum;
/*0x2B*/ u8 animCmdIndex;
/*0x2C*/ u8 animDelayCounter:6;
u8 animPaused:1;
u8 affineAnimPaused:1;
/*0x2D*/ u8 animLoopCounter;
// general purpose data fields
/*0x2E*/ s16 data0;
/*0x30*/ s16 data1;
/*0x32*/ s16 data2;
/*0x34*/ s16 data3;
/*0x36*/ s16 data4;
/*0x38*/ s16 data5;
/*0x3A*/ s16 data6;
/*0x3C*/ s16 data7;
/*0x3E*/ u16 inUse:1;
u16 coordOffsetEnabled:1;
u16 invisible:1;
u16 flags_3:1;
u16 flags_4:1;
u16 flags_5:1;
u16 flags_6:1;
u16 flags_7:1;
/*0x3F*/ u16 hFlip:1;
u16 vFlip:1;
u16 animBeginning:1;
u16 affineAnimBeginning:1;
u16 animEnded:1;
u16 affineAnimEnded:1;
u16 usingSheet:1;
u16 flags_f:1;
/*0x40*/ u16 sheetTileStart;
u8 subspriteTableNum:6;
u8 subspriteMode:2;
u8 subpriority;
};
extern s16 gSpriteCoordOffsetX;
extern s16 gSpriteCoordOffsetY;
extern struct Sprite gSprites[];
void ResetSpriteData(void);
void AnimateSprites(void);
void BuildOamBuffer(void);
u8 CreateSprite(const struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
u8 CreateSpriteAtEnd(const struct SpriteTemplate *template, u16 x, u16 y, u8 subpriority);
u8 CreateInvisibleSprite(void (*callback)(struct Sprite *));
u8 CreateSpriteAndAnimate(struct SpriteTemplate *template, s16 x, s16 y, u8 subpriority);
void DestroySprite(struct Sprite *sprite);
void ResetOamRange(u8 a, u8 b);
void LoadOam(void);
void SetOamMatrix(u8 matrixNum, u16 a, u16 b, u16 c, u16 d);
void CalcCenterToCornerVec(struct Sprite *sprite, u8 shape, u8 size, u8 affineMode);
void SpriteCallbackDummy(struct Sprite *sprite);
void ProcessSpriteCopyRequests(void);
void RequestSpriteCopy(u8 *src, u8 *dest, u16 size);
void FreeSpriteTiles(struct Sprite *sprite);
void FreeSpritePalette(struct Sprite *sprite);
void FreeSpriteOamMatrix(struct Sprite *sprite);
void DestroySpriteAndFreeResources(struct Sprite *sprite);
void sub_800142C(u32 a1, u32 a2, u16 *a3, u16 a4, u32 a5);
void AnimateSprite(struct Sprite *sprite);
void StartSpriteAnim(struct Sprite *sprite, u8 animNum);
void StartSpriteAnimIfDifferent(struct Sprite *sprite, u8 animNum);
void SeekSpriteAnim(struct Sprite *sprite, u8 animCmdIndex);
void StartSpriteAffineAnim(struct Sprite *sprite, u8 animNum);
void StartSpriteAffineAnimIfDifferent(struct Sprite *sprite, u8 animNum);
void ChangeSpriteAffineAnim(struct Sprite *sprite, u8 animNum);
void ChangeSpriteAffineAnimIfDifferent(struct Sprite *sprite, u8 animNum);
void SetSpriteSheetFrameTileNum(struct Sprite *sprite);
u8 AllocOamMatrix(void);
void FreeOamMatrix(u8 matrixNum);
void InitSpriteAffineAnim(struct Sprite *sprite);
void SetOamMatrixRotationScaling(u8 matrixNum, s16 xScale, s16 yScale, u16 rotation);
u16 LoadSpriteSheet(struct SpriteSheet *sheet);
void LoadSpriteSheets(struct SpriteSheet *sheets);
u16 AllocTilesForSpriteSheet(struct SpriteSheet *sheet);
void AllocTilesForSpriteSheets(struct SpriteSheet *sheets);
void LoadTilesForSpriteSheet(struct SpriteSheet *sheet);
void LoadTilesForSpriteSheets(struct SpriteSheet *sheets);
void FreeSpriteTilesByTag(u16 tag);
void FreeSpriteTileRanges(void);
u16 GetSpriteTileStartByTag(u16 tag);
u16 GetSpriteTileTagByTileStart(u16 start);
void RequestSpriteSheetCopy(struct SpriteSheet *sheet);
u16 LoadSpriteSheetDeferred(struct SpriteSheet *sheet);
void FreeAllSpritePalettes(void);
u8 LoadSpritePalette(const struct SpritePalette *palette);
void LoadSpritePalettes(const struct SpritePalette *palettes);
u8 AllocSpritePalette(u16 tag);
u8 IndexOfSpritePaletteTag(u16 tag);
u16 GetSpritePaletteTagByPaletteNum(u8 paletteNum);
void FreeSpritePaletteByTag(u16 tag);
void SetSubspriteTables(struct Sprite *sprite, struct SubspriteTable *subspriteTables);
bool8 AddSpriteToOamBuffer(struct Sprite *object, u8 *oamIndex);
bool8 AddSubspritesToOamBuffer(struct Sprite *sprite, struct OamData *destOam, u8 *oamIndex);
#endif // GUARD_SPRITE_H
|