Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bit macros from SA3 #172

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we doing widescreen by default now? ;)

#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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this one?

#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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change, but obviously makes sense to keep

gUnknown_03002878 = (void *)&REG_WIN0H;

gFlags |= FLAGS_4;
Expand Down