Skip to content

Commit

Permalink
Add bit macros from SA3 (#172)
Browse files Browse the repository at this point in the history
* Fix BriBaSA_ex not showing the correct animation for many entities
  • Loading branch information
JaceCear authored Nov 24, 2024
1 parent 5eda147 commit 3aca622
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
15 changes: 9 additions & 6 deletions include/constants/characters.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#ifndef GUARD_CONSTANTS_CHARACTERS_H
#define GUARD_CONSTANTS_CHARACTERS_H

#define CHARACTER_SHARED_ANIM 0
#define CHARACTER_SONIC 0
#define CHARACTER_CREAM 1
#define CHARACTER_TAILS 2
#define CHARACTER_KNUCKLES 3
#define CHARACTER_AMY 4
#define CHARACTER_SONIC 0
#define CHARACTER_CREAM 1
#define CHARACTER_TAILS 2
#define CHARACTER_KNUCKLES 3
#define CHARACTER_AMY 4

#define NUM_CHARACTERS 5

// NOTE: Put this after NUM_CHARACTERS, to allow BriBaSA_ex to parse this file properly.
// Naming it CHARACTER_<something> before NUM_CHARACTERS confuses it.
#define CHARACTER_SHARED_ANIM 0

#define CHARACTER_BIT(character) (1 << (character))

#define MAIN_CHARACTERS \
Expand Down
4 changes: 2 additions & 2 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#define OAM_ENTRY_COUNT 128
#if PORTABLE
// NOTE: Used in gba/types.h, so they have to be defined before the #include
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 160
#define DISPLAY_WIDTH 426
#define DISPLAY_HEIGHT 240

//#include "gba/types.h"
// TODO: Fix #define OAM_SIZE (OAM_ENTRY_COUNT*sizeof(OamData))
Expand Down
46 changes: 43 additions & 3 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,49 @@ typedef void (*VoidFn)(void);

#define RECT_DISTANCE(aXA, aYA, aXB, aYB) (ABS((aXA) - (aXB)) + ABS((aYA) - (aYB)))

#define GetBit(x, y) (((x) >> (y)) & 1)
#define SetBit(x, y) (x) |= (1 << (y))
#define ClearBit(x, y) (x) &= ~(1 << (y))
#define BitValue(y) (1 << (y))
#define CheckBit(x, y) ((x) & (BitValue(y)))
#define GetBit(x, y) (((x) >> (y)) & 1)
#define SetBit(x, y) (x) |= BitValue(y)
#define SetSoleBit(x, y) (x) = BitValue(y)
#define ClearBit(x, y) (x) &= ~BitValue(y)

// TODO: Use instrinsics for these, on platforms that support it!
// Like GetFirstSetBitIndex, but an external iterator can be passed.
#define GetFirstSetBitIndexExt(value, max, it) \
({ \
s32 res; \
\
for (it = 0; it < (max); it++) { \
if (GetBit(value, it)) { \
break; \
} \
} \
\
res = it; \
})

// Get the index to the first set bit in a given value.
#define GetFirstSetBitIndex(value, max) \
({ \
s16 bit; \
\
bit = GetFirstSetBitIndexExt(value, max, bit); \
})

// Like GetFirstSetBitIndex, but expects input value to only have 1 bit set.
#define GetSoleSetBitIndex(value, max) \
({ \
s16 bit; \
\
for (bit = 0; bit < (max); bit++) { \
if ((value) == (1 << bit)) { \
break; \
} \
} \
\
bit; \
})

// 60 is not exactly true as the GBA's FPS, but it's what they went
// with for the calculation
Expand Down
2 changes: 1 addition & 1 deletion src/game/stage/intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ static void Task_IntroColorAnimation(void)
}
}

gUnknown_03002A80 = 2;
gUnknown_03002A80 = 2 * sizeof(int_vcount);
gUnknown_03002878 = (void *)&REG_WIN0H;

gFlags |= FLAGS_4;
Expand Down

0 comments on commit 3aca622

Please sign in to comment.