diff --git a/include/structs/sprite_oam.h b/include/structs/sprite_oam.h index 644e8e6c..b1e1c6e9 100644 --- a/include/structs/sprite_oam.h +++ b/include/structs/sprite_oam.h @@ -179,6 +179,13 @@ typedef struct SpriteOAM (spritePtr)->attrib1 |= _shapeVal; \ } +#define SpriteGetTileNum_LocalVar(spritePtr, _tileNum) \ +{ \ + _tileNum = (spritePtr)->attrib3; \ + _tileNum >>= SPRITEOAM_SHIFT_TILENUM; \ + _tileNum &= SPRITEOAM_MAX_TILENUM; \ +} + #define SpriteSetTileNum(spritePtr, _tileNum) \ { \ u32 _tileNumVal = _tileNum; \ @@ -188,6 +195,14 @@ typedef struct SpriteOAM (spritePtr)->attrib3 |= _tileNumVal; \ } +#define SpriteAddTileNum(spritePtr, addVal) \ +{ \ + u32 _tileNumValAdd; \ + SpriteGetTileNum_LocalVar(spritePtr, _tileNumValAdd); \ + _tileNumValAdd += (addVal); \ + SpriteSetTileNum(spritePtr, _tileNumValAdd); \ +} + #define SpriteSetPriority(spritePtr, _priority) \ { \ u32 _priorityVal = _priority; \ @@ -233,6 +248,8 @@ typedef struct SpriteOAM (spritePtr)->attrib2 |= _sizeVal; \ } +#define SpriteGetX(spritePtr)(((spritePtr)->attrib2 >> SPRITEOAM_SHIFT_X) & SPRITEOAM_MAX_X) + #define SpriteSetX(spritePtr, _x) \ { \ u32 _xSpriteVal = _x; \ @@ -252,7 +269,9 @@ typedef struct SpriteOAM (spritePtr)->attrib2 = _xSpriteVal; \ } -#define SpriteGetY(spritePtr, _y) \ +#define SpriteGetY(spritePtr)(((spritePtr)->unk6 >> SPRITEOAM_SHIFT_WORKING_Y) & SPRITEOAM_MAX_WORKING_Y) + +#define SpriteGetY_LocalVar(spritePtr, _y) \ { \ _y = (spritePtr)->unk6; \ _y >>= SPRITEOAM_SHIFT_WORKING_Y; \ @@ -271,7 +290,7 @@ typedef struct SpriteOAM #define SpriteAddY(spritePtr, addVal) \ { \ u32 _yVal; \ - SpriteGetY(spritePtr, _yVal); \ + SpriteGetY_LocalVar(spritePtr, _yVal); \ _yVal += (addVal); \ SpriteSetY(spritePtr, _yVal); \ } @@ -285,6 +304,8 @@ typedef struct SpriteOAM (spritePtr)->unk6 |= _unk6_0Val; \ } +#define SpriteGetUnk6_1(spritePtr)(((spritePtr)->unk6 >> SPRITEOAM_SHIFT_UNK6_1) & SPRITEOAM_MAX_UNK6_1) + #define SpriteSetUnk6_1(spritePtr, _unk6_1) \ { \ u32 _unk6_1Val = _unk6_1; \ diff --git a/src/sprite.c b/src/sprite.c index a500e12d..5b6f433d 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -218,14 +218,10 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * } else { // Animations add to existing tileNum - s32 tileNum = sprite->attrib3; - tileNum &= SPRITEOAM_MAX_TILENUM; - tileNum >>= SPRITEOAM_SHIFT_TILENUM; - - SpriteSetTileNum(sprite, tileNum + a1->vramTileOrMaybeAnimTimer); + SpriteAddTileNum(sprite, a1->vramTileOrMaybeAnimTimer); } - pos = ((sprite->attrib2 >> SPRITEOAM_SHIFT_X) & SPRITEOAM_MAX_X) ; + pos = SpriteGetX(sprite); pos += a1->pos.x - 0x100; if (pos < -64) @@ -235,7 +231,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * SpriteSetX(sprite, pos); - pos = ((sprite->unk6 >> SPRITEOAM_SHIFT_WORKING_Y) & SPRITEOAM_MAX_WORKING_Y); + pos = SpriteGetY(sprite); pos += a1->pos.y - 0x200; if (pos < -64) return; @@ -245,7 +241,7 @@ void AddAxSprite(ax_pose *a0, axdata1 *a1, UnkSpriteMem *a2, unkStruct_2039DB0 * SpriteSetOamY(sprite, pos); // Set paletteNum - if (!((sprite->unk6 >> SPRITEOAM_SHIFT_UNK6_1) & SPRITEOAM_MAX_UNK6_1)) { + if (!SpriteGetUnk6_1(sprite)) { SpriteSetPalNum(sprite, a1->paletteNum); }