Skip to content

Commit

Permalink
Add format target to Makefile and run clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseurae committed Oct 6, 2024
1 parent c4b6613 commit 8ed40e2
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 86 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ all: $(OUTPUT)

$(OUTPUT): $(INPUT) build/linked_processed.o

format:
@find . -not -path "./tools/*" -name *.c -o -not -path "./tools/*" -name *.h | xargs clang-format -i
@echo "Done."

tools:
@$(MAKE) -C tools/elfedit
@$(MAKE) -C tools/preproc
Expand Down
4 changes: 2 additions & 2 deletions include/constants/gba.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@
#define REG_DMA3CNT_L (*(vu16 *)REG_ADDR_DMA3CNT_L)
#define REG_DMA3CNT_H (*(vu16 *)REG_ADDR_DMA3CNT_H)

#define REG_TMCNT(n) (*(vu16 *)(REG_ADDR_TMCNT + ((n)*4)))
#define REG_TMCNT(n) (*(vu16 *)(REG_ADDR_TMCNT + ((n) * 4)))
#define REG_TM0CNT (*(vu32 *)REG_ADDR_TM0CNT)
#define REG_TM0CNT_L (*(vu16 *)REG_ADDR_TM0CNT_L)
#define REG_TM0CNT_H (*(vu16 *)REG_ADDR_TM0CNT_H)
Expand Down Expand Up @@ -805,7 +805,7 @@
#define PLTT_SIZE_4BPP PLTT_SIZEOF(16)
#define PLTT_SIZE_8BPP PLTT_SIZEOF(256)

#define PLTT_OFFSET_4BPP(n) ((n)*PLTT_SIZE_4BPP)
#define PLTT_OFFSET_4BPP(n) ((n) * PLTT_SIZE_4BPP)

#define RGB(r, g, b) ((r) | ((g) << 5) | ((b) << 10))

Expand Down
28 changes: 14 additions & 14 deletions include/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ void LONG_CALL TransferPlttBuffer(void);

struct PaletteFadeControl
{
/*0x00*/ u32 multipurpose1;
/*0x04*/ u8 delayCounter:6;
/*0x05*/ u16 y:5; // blend coefficient
/*0x00*/ u32 multipurpose1;
/*0x04*/ u8 delayCounter:6;
/*0x05*/ u16 y:5; // blend coefficient
/*0x05-06*/ u16 targetY:5; // target blend coefficient
/*0x07*/ u16 blendColor:15;
/*0x07*/ u16 active:1;
/*0x08*/ u16 multipurpose2:6;
/*0x08*/ u16 yDec:1; // whether blend coefficient is decreasing
/*0x08*/ u16 bufferTransferDisabled:1;
/*0x09*/ u16 mode:2;
/*0x09*/ u16 shouldResetBlendRegisters:1;
/*0x09*/ u16 hardwareFadeFinishing:1;
/*0x07*/ u16 blendColor:15;
/*0x07*/ u16 active:1;
/*0x08*/ u16 multipurpose2:6;
/*0x08*/ u16 yDec:1; // whether blend coefficient is decreasing
/*0x08*/ u16 bufferTransferDisabled:1;
/*0x09*/ u16 mode:2;
/*0x09*/ u16 shouldResetBlendRegisters:1;
/*0x09*/ u16 hardwareFadeFinishing:1;
/*0x09-0a*/ u16 softwareFadeFinishingCounter:5;
/*0x0a*/ u16 softwareFadeFinishing:1;
/*0x0a*/ u16 objPaletteToggle:1;
/*0x0a*/ u8 deltaY:4; // rate of change of blend coefficient
/*0x0a*/ u16 softwareFadeFinishing:1;
/*0x0a*/ u16 objPaletteToggle:1;
/*0x0a*/ u8 deltaY:4; // rate of change of blend coefficient
};

extern struct PaletteFadeControl gPaletteFade;
2 changes: 1 addition & 1 deletion include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct PACKED BaseStats
/*0x17*/ u8 ability2;
/*0x18*/ u8 safariZoneFleeRate;
/*0x19*/ u8 bodyColor:7;
u8 noFlip:1;
u8 noFlip:1;
};

struct PACKED BoxPokemon
Expand Down
3 changes: 2 additions & 1 deletion include/script_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ extern u8 gRepelMenuChoices[3];
void LONG_CALL DrawMultichoiceMenu(
u8 left, u8 top, u8 count, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos);
u8 LONG_CALL CreateTrainerSprite(u8 trainerSpriteID, s16 x, s16 y, u8 subpriority, u8 *buffer);
void DrawListMenu(u8 left, u8 top, u8 displayCount, u8 totalCount, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos);
void DrawListMenu(
u8 left, u8 top, u8 displayCount, u8 totalCount, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos);
4 changes: 2 additions & 2 deletions src/field_control_avatar.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "types.h"
#include "event_object_movement.h"
#include "field_control_avatar.h"
#include "event_object_movement.h"
#include "field_message_box.h"
#include "field_player_avatar.h"
#include "flags.h"
Expand Down Expand Up @@ -29,7 +29,7 @@ int ProcessPlayerFieldInput_Rest(struct FieldInput *input)
#include "save_time_util.h"

static const u8 sText_DisabledAutorun[] = _("Autorun {COLOR RED}disabled{COLOR DARK_GREY}.");
static const u8 sText_EnabledAutorun[] =_("Autorun {COLOR GREEN}enabled{COLOR DARK_GREY}.");
static const u8 sText_EnabledAutorun[] = _("Autorun {COLOR GREEN}enabled{COLOR DARK_GREY}.");

static bool8 EnableAutoRun(void)
{
Expand Down
2 changes: 1 addition & 1 deletion src/field_message_box.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void PrintFieldMessageInstant(const u8 *message)
lo = (u16 *)(&gTasks[taskId].data[2]);

*hi = (u32)(message) >> 16;
*lo = (u32)(message)&0xffff;
*lo = (u32)(message) & 0xffff;
}

static void Task_FieldMessageBoxInstant(u8 taskId)
Expand Down
3 changes: 2 additions & 1 deletion src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void CheckIfPartyHasMoveForElevator(void)

u8 GetNature_(struct Pokemon *mon)
{
if (mon->box.nature == 0) return GetNatureFromPersonality(GetMonData(mon, MON_DATA_PERSONALITY));
if (mon->box.nature == 0)
return GetNatureFromPersonality(GetMonData(mon, MON_DATA_PERSONALITY));
return mon->box.nature - 1;
}
96 changes: 49 additions & 47 deletions src/pokemon_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,61 +94,61 @@ void OpenPokemonContextMenu(void)
}
}

static const u8 sNatureName_Hardy[] = _("HARDY");
static const u8 sNatureName_Lonely[] = _("LONELY");
static const u8 sNatureName_Brave[] = _("BRAVE");
static const u8 sNatureName_Hardy[] = _("HARDY");
static const u8 sNatureName_Lonely[] = _("LONELY");
static const u8 sNatureName_Brave[] = _("BRAVE");
static const u8 sNatureName_Adamant[] = _("ADAMANT");
static const u8 sNatureName_Naughty[] = _("NAUGHTY");
static const u8 sNatureName_Bold[] = _("BOLD");
static const u8 sNatureName_Docile[] = _("DOCILE");
static const u8 sNatureName_Bold[] = _("BOLD");
static const u8 sNatureName_Docile[] = _("DOCILE");
static const u8 sNatureName_Relaxed[] = _("RELAXED");
static const u8 sNatureName_Impish[] = _("IMPISH");
static const u8 sNatureName_Lax[] = _("LAX");
static const u8 sNatureName_Timid[] = _("TIMID");
static const u8 sNatureName_Hasty[] = _("HASTY");
static const u8 sNatureName_Impish[] = _("IMPISH");
static const u8 sNatureName_Lax[] = _("LAX");
static const u8 sNatureName_Timid[] = _("TIMID");
static const u8 sNatureName_Hasty[] = _("HASTY");
static const u8 sNatureName_Serious[] = _("SERIOUS");
static const u8 sNatureName_Jolly[] = _("JOLLY");
static const u8 sNatureName_Naive[] = _("NAIVE");
static const u8 sNatureName_Modest[] = _("MODEST");
static const u8 sNatureName_Mild[] = _("MILD");
static const u8 sNatureName_Quiet[] = _("QUIET");
static const u8 sNatureName_Jolly[] = _("JOLLY");
static const u8 sNatureName_Naive[] = _("NAIVE");
static const u8 sNatureName_Modest[] = _("MODEST");
static const u8 sNatureName_Mild[] = _("MILD");
static const u8 sNatureName_Quiet[] = _("QUIET");
static const u8 sNatureName_Bashful[] = _("BASHFUL");
static const u8 sNatureName_Rash[] = _("RASH");
static const u8 sNatureName_Calm[] = _("CALM");
static const u8 sNatureName_Gentle[] = _("GENTLE");
static const u8 sNatureName_Sassy[] = _("SASSY");
static const u8 sNatureName_Rash[] = _("RASH");
static const u8 sNatureName_Calm[] = _("CALM");
static const u8 sNatureName_Gentle[] = _("GENTLE");
static const u8 sNatureName_Sassy[] = _("SASSY");
static const u8 sNatureName_Careful[] = _("CAREFUL");
static const u8 sNatureName_Quirky[] = _("QUIRKY");
static const u8 sNatureName_Quirky[] = _("QUIRKY");

extern const u8 gOtherText_CancelNoTerminator[];

const struct MenuAction sNatureMenuActions[] = {
{sNatureName_Hardy, NULL},
{sNatureName_Lonely, NULL},
{sNatureName_Brave, NULL},
{sNatureName_Adamant, NULL},
{sNatureName_Naughty, NULL},
{sNatureName_Bold, NULL},
{sNatureName_Docile, NULL},
{sNatureName_Relaxed, NULL},
{sNatureName_Impish, NULL},
{sNatureName_Lax, NULL},
{sNatureName_Timid, NULL},
{sNatureName_Hasty, NULL},
{sNatureName_Serious, NULL},
{sNatureName_Jolly, NULL},
{sNatureName_Naive, NULL},
{sNatureName_Modest, NULL},
{sNatureName_Mild, NULL},
{sNatureName_Quiet, NULL},
{sNatureName_Bashful, NULL},
{sNatureName_Rash, NULL},
{sNatureName_Calm, NULL},
{sNatureName_Gentle, NULL},
{sNatureName_Sassy, NULL},
{sNatureName_Careful, NULL},
{sNatureName_Quirky, NULL},
{gOtherText_CancelNoTerminator, NULL}
{ sNatureName_Hardy, NULL },
{ sNatureName_Lonely, NULL },
{ sNatureName_Brave, NULL },
{ sNatureName_Adamant, NULL },
{ sNatureName_Naughty, NULL },
{ sNatureName_Bold, NULL },
{ sNatureName_Docile, NULL },
{ sNatureName_Relaxed, NULL },
{ sNatureName_Impish, NULL },
{ sNatureName_Lax, NULL },
{ sNatureName_Timid, NULL },
{ sNatureName_Hasty, NULL },
{ sNatureName_Serious, NULL },
{ sNatureName_Jolly, NULL },
{ sNatureName_Naive, NULL },
{ sNatureName_Modest, NULL },
{ sNatureName_Mild, NULL },
{ sNatureName_Quiet, NULL },
{ sNatureName_Bashful, NULL },
{ sNatureName_Rash, NULL },
{ sNatureName_Calm, NULL },
{ sNatureName_Gentle, NULL },
{ sNatureName_Sassy, NULL },
{ sNatureName_Careful, NULL },
{ sNatureName_Quirky, NULL },
{ gOtherText_CancelNoTerminator, NULL }
};

void DrawNaturesWindow(void)
Expand All @@ -158,7 +158,8 @@ void DrawNaturesWindow(void)

void BufferNatureName(void)
{
if (gSpecialVar_Result >= 25) return;
if (gSpecialVar_Result >= 25)
return;
StringCopy(gStringVar1, gNatureNames[gSpecialVar_Result]);
}

Expand Down Expand Up @@ -190,5 +191,6 @@ void ChangePartyMonAbility(void)
void BufferAlternateAbilityName(void)
{
struct Pokemon *mon = &gPlayerParty[gSpecialVar_0x8004];
StringCopy(gStringVar1, gAbilityNames[GetAbilityBySpecies(GetMonData(mon, MON_DATA_SPECIES), !GetMonData(mon, MON_DATA_ALT_ABILITY))]);
StringCopy(gStringVar1,
gAbilityNames[GetAbilityBySpecies(GetMonData(mon, MON_DATA_SPECIES), !GetMonData(mon, MON_DATA_ALT_ABILITY))]);
}
54 changes: 37 additions & 17 deletions src/script_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "main.h"
#include "menu.h"
#include "palette.h"
#include "sound.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "task.h"
#include "vars.h"
Expand All @@ -20,7 +20,8 @@ static const u16 sRepelItems[3] = { ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL
static void Task_TrainerPicWindow(u8 taskId);
static bool8 (*ScriptMenu_GetTrainerPicboxWaitFunc(void))(void);
static bool8 IsPicboxClosed(void);
static void StartListMenuTask(const struct MenuAction *list, u8 left, u8 top, u8 right, u8 bottom, u8 ignoreBPress, u8 displayCount, u8 totalCount);
static void StartListMenuTask(const struct MenuAction *list, u8 left, u8 top, u8 right, u8 bottom, u8 ignoreBPress,
u8 displayCount, u8 totalCount);
static void Task_HandleListMenuInput(u8 taskId);

u16 LONG_CALL GetStringWidthInTilesForScriptMenu(const u8 *str);
Expand Down Expand Up @@ -154,7 +155,8 @@ static bool8 IsPicboxClosed(void)
#undef tWindowX
#undef tWindowY

void DrawListMenu(u8 left, u8 top, u8 displayCount, u8 totalCount, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos)
void DrawListMenu(
u8 left, u8 top, u8 displayCount, u8 totalCount, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos)
{
u16 width = GetStringWidthInTilesForScriptMenu(list[0].text);
u16 newWidth;
Expand Down Expand Up @@ -199,13 +201,14 @@ void DrawListMenu(u8 left, u8 top, u8 displayCount, u8 totalCount, const struct
#define tDisplayCount data[10]
#define tTotalCount data[11]

static void StartListMenuTask(const struct MenuAction *list, u8 left, u8 top, u8 right, u8 bottom, u8 ignoreBPress, u8 displayCount, u8 totalCount)
static void StartListMenuTask(const struct MenuAction *list, u8 left, u8 top, u8 right, u8 bottom, u8 ignoreBPress,
u8 displayCount, u8 totalCount)
{
u8 taskId = CreateTask(Task_HandleListMenuInput, 80);

gTasks[taskId].tListPtrHi = (u32)list >> 16;
gTasks[taskId].tListPtrLo = (u32)list;

gTasks[taskId].tLeft = left;
gTasks[taskId].tTop = top;
gTasks[taskId].tRight = right;
Expand Down Expand Up @@ -235,17 +238,22 @@ static void Task_HandleListMenuInput(u8 taskId)
s16 *data = gTasks[taskId].data;
struct MenuAction *list = (struct MenuAction *)((u16)tListPtrHi << 16 | (u16)tListPtrLo);

if (gPaletteFade.active) return;
if (gMain.newKeys & A_BUTTON) {
if (gPaletteFade.active)
return;
if (gMain.newKeys & A_BUTTON)
{
gSpecialVar_Result = tCursor + tScrollOffset;
Menu_DestroyCursor();
Menu_EraseWindowRect(gTasks[taskId].tLeft, gTasks[taskId].tTop, gTasks[taskId].tRight, gTasks[taskId].tBottom);
DestroyTask(taskId);
EnableBothScriptContexts();
DestroyVerticalScrollIndicator(TOP_ARROW);
DestroyVerticalScrollIndicator(BOTTOM_ARROW);
} else if (gMain.newKeys & B_BUTTON) {
if (tIgnoreBPress) return;
}
else if (gMain.newKeys & B_BUTTON)
{
if (tIgnoreBPress)
return;

gSpecialVar_Result = 127;
Menu_DestroyCursor();
Expand All @@ -254,25 +262,37 @@ static void Task_HandleListMenuInput(u8 taskId)
EnableBothScriptContexts();
DestroyVerticalScrollIndicator(TOP_ARROW);
DestroyVerticalScrollIndicator(BOTTOM_ARROW);
} else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) {
if (tCursor == tDisplayCount - 1) {
if (tCursor + tScrollOffset == tTotalCount - 1) return;
}
else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN)
{
if (tCursor == tDisplayCount - 1)
{
if (tCursor + tScrollOffset == tTotalCount - 1)
return;
PlaySE(SE_SELECT);
tScrollOffset++;
Menu_BlankWindowRect(tLeft + 1, tTop + 1, tRight - 1, tBottom - 1);
Menu_PrintItems(tLeft + 1, tTop + 1, tDisplayCount, list + tScrollOffset);
} else {
}
else
{
PlaySE(SE_SELECT);
tCursor = Menu_MoveCursor(1);
}
} else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) {
if (tCursor == 0) {
if (tScrollOffset == 0) return;
}
else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP)
{
if (tCursor == 0)
{
if (tScrollOffset == 0)
return;
PlaySE(SE_SELECT);
tScrollOffset--;
Menu_BlankWindowRect(tLeft + 1, tTop + 1, tRight - 1, tBottom - 1);
Menu_PrintItems(tLeft + 1, tTop + 1, tDisplayCount, list + tScrollOffset);
} else {
}
else
{
PlaySE(SE_SELECT);
tCursor = Menu_MoveCursor(-1);
}
Expand Down

0 comments on commit 8ed40e2

Please sign in to comment.