Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ INCLUDE_SCANINC_ARGS := $(INCLUDE_DIRS:%=-I %)
O_LEVEL ?= 2
CPPFLAGS := $(INCLUDE_CPP_ARGS) -Wno-trigraphs -D$(GAME_VERSION) -DREVISION=$(GAME_REVISION) -D$(GAME_LANGUAGE) -DMODERN=$(MODERN)
ifeq ($(MODERN),0)
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc -nostdinc -undef
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc -nostdinc -undef -std=gnu89
CC1 := tools/agbcc/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O$(O_LEVEL) -fhex-asm
LIBPATH := -L ../../tools/agbcc/lib
Expand Down
4 changes: 4 additions & 0 deletions include/gba/m4a_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ struct SoundChannel

struct MusicPlayerInfo;

#if __STDC_VERSION__ < 202311L
typedef void (*MPlayFunc)();
#else
typedef void (*MPlayFunc)(...);
#endif
typedef void (*PlyNoteFunc)(u32, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
typedef void (*CgbSoundFunc)(void);
typedef void (*CgbOscOffFunc)(u8);
Expand Down
11 changes: 11 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#define asm_comment(x) asm volatile("@ -- " x " -- ")
#define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided")

#if __STDC_VERSION__ < 202311L
#define asm __asm__
#endif

// IDE support
#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__INTELLISENSE__)
// We define these when using certain IDEs to fool preproc
Expand Down Expand Up @@ -131,6 +135,13 @@ extern u8 gStringVar4[];
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES)

// This returns the number of arguments passed to it (up to 8).
#define NARG_8(...) NARG_8_(_, ##__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define NARG_8_(_, a, b, c, d, e, f, g, h, N, ...) N

#define CAT(a, b) CAT_(a, b)
#define CAT_(a, b) a ## b

// This produces an error at compile-time if expr is zero.
// It looks like file.c:line: size of array `id' is negative
#define STATIC_ASSERT(expr, id) typedef char id[(expr) ? 1 : -1];
Expand Down
4 changes: 4 additions & 0 deletions include/librfu.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ struct STWIStatus
u8 recoveryCount;
u8 unk_16;
u8 unk_17;
#if __STDC_VERSION__ < 202311L
void (*callbackM)();
#else
void (*callbackM)(...);
#endif
void (*callbackS)(u16);
void (*callbackID)(void);
union RfuPacket *txPacket;
Expand Down
23 changes: 11 additions & 12 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,17 @@ u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality);
void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition);
void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosition);

// These are full type signatures for GetMonData() and GetBoxMonData(),
// but they are not used since some code erroneously omits the third arg.
// u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data);
// u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data);

#ifdef IS_POKEMON_C
u32 GetMonData(struct Pokemon *, s32, u8 *);
u32 GetBoxMonData(struct BoxPokemon *, s32, u8 *);
#else
u32 GetMonData();
u32 GetBoxMonData();
#endif // IS_POKEMON_C
/* GameFreak called Get(Box)MonData with either 2 or 3 arguments, for
* type safety we have a Get(Box)MonData macro which dispatches to
* either Get(Box)MonData2 or Get(Box)MonData3 based on the number of
* arguments. The two functions are aliases of each other, but they
* differ for matching purposes in the caller's codegen. */
#define GetMonData(...) CAT(GetMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__)
#define GetBoxMonData(...) CAT(GetBoxMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__)
u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data);
u32 GetMonData2(struct Pokemon *mon, s32 field);
u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data);
u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field);

void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg);
void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg);
Expand Down
2 changes: 1 addition & 1 deletion src/daycare.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ static void Debug_AddDaycareSteps(u16 numSteps)

u8 GetNumLevelsGainedFromDaycare(void)
{
if (GetBoxMonData(&gSaveBlock1Ptr->daycare.mons[gSpecialVar_0x8004], MON_DATA_SPECIES) != 0)
if (GetBoxMonData(&gSaveBlock1Ptr->daycare.mons[gSpecialVar_0x8004].mon, MON_DATA_SPECIES) != 0)
return GetNumLevelsGainedForDaycareMon(&gSaveBlock1Ptr->daycare.mons[gSpecialVar_0x8004]);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/field_player_avatar.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static u8 TeleportAnim_RotatePlayer(struct ObjectEvent * object, s16 *timer);

void MovementType_Player(struct Sprite *sprite)
{
UpdateObjectEventCurrentMovement(&gObjectEvents[sprite->data[0]], sprite, ObjectEventCB2_NoMovement2);
UpdateObjectEventCurrentMovement(&gObjectEvents[sprite->data[0]], sprite, (bool8 (*)(struct ObjectEvent *, struct Sprite *))ObjectEventCB2_NoMovement2);
}

static u8 ObjectEventCB2_NoMovement2(struct ObjectEvent * object, struct Sprite *sprite)
Expand Down
12 changes: 12 additions & 0 deletions src/librfu_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ static u16 handshake_wait(u16 slot);
static void STWI_set_timer_in_RAM(u8 count);
static void STWI_stop_timer_in_RAM(void);
static void STWI_init_slave(void);
#if __STDC_VERSION__ < 202311L
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)());
#else
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)(...));
#endif
static void Callback_Dummy_S(u16 reqCommandId, void (*callbackS)(u16));
static void Callback_Dummy_ID(void (*callbackId)(void));

Expand Down Expand Up @@ -134,7 +138,11 @@ static void sio32intr_clock_master(void)
}
gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL)
#if __STDC_VERSION__ < 202311L
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM);
#else
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, (void (*)(...))gSTWIStatus->callbackM);
#endif
}
else
{
Expand Down Expand Up @@ -387,7 +395,11 @@ static void STWI_init_slave(void)
}

NAKED
#if __STDC_VERSION__ < 202311L
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)())
#else
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)(...))
#endif
{
asm("bx r2");
}
Expand Down
22 changes: 21 additions & 1 deletion src/m4a.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <string.h>
#include "global.h"
#include "gba/m4a_internal.h"

extern const u8 gCgb3Vol[];
Expand Down Expand Up @@ -283,6 +283,7 @@ void MPlayExtender(struct CgbChannel *cgbChans)

soundInfo->ident++;

#if __STDC_VERSION__ < 202311L
gMPlayJumpTable[8] = ply_memacc;
gMPlayJumpTable[17] = ply_lfos;
gMPlayJumpTable[19] = ply_mod;
Expand All @@ -292,6 +293,17 @@ void MPlayExtender(struct CgbChannel *cgbChans)
gMPlayJumpTable[31] = TrackStop;
gMPlayJumpTable[32] = FadeOutBody;
gMPlayJumpTable[33] = TrkVolPitSet;
#else
gMPlayJumpTable[8] = (void (*)(...))ply_memacc;
gMPlayJumpTable[17] = (void (*)(...))ply_lfos;
gMPlayJumpTable[19] = (void (*)(...))ply_mod;
gMPlayJumpTable[28] = (void (*)(...))ply_xcmd;
gMPlayJumpTable[29] = (void (*)(...))ply_endtie;
gMPlayJumpTable[30] = (void (*)(...))SampleFreqSet;
gMPlayJumpTable[31] = (void (*)(...))TrackStop;
gMPlayJumpTable[32] = (void (*)(...))FadeOutBody;
gMPlayJumpTable[33] = (void (*)(...))TrkVolPitSet;
#endif

soundInfo->cgbChans = cgbChans;
soundInfo->CgbSound = CgbSound;
Expand Down Expand Up @@ -320,13 +332,21 @@ void MusicPlayerJumpTableCopy(void)

void ClearChain(void *x)
{
#if __STDC_VERSION__ < 202311L
void (*func)(void *) = *(&gMPlayJumpTable[34]);
#else
void (*func)(...) = *(&gMPlayJumpTable[34]);
#endif
func(x);
}

void Clear64byte(void *x)
{
#if __STDC_VERSION__ < 202311L
void (*func)(void *) = *(&gMPlayJumpTable[35]);
#else
void (*func)(...) = *(&gMPlayJumpTable[35]);
#endif
func(x);
}

Expand Down
16 changes: 14 additions & 2 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,11 @@ static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 perso
return substruct;
}

u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data)
/* GameFreak called GetMonData with either 2 or 3 arguments, for type
* safety we have a GetMonData macro (in include/pokemon.h) which
* dispatches to either GetMonData2 or GetMonData3 based on the number
* of arguments. */
u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data)
{
u32 ret;

Expand Down Expand Up @@ -2963,7 +2967,13 @@ u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data)
return ret;
}

u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
u32 GetMonData2(struct Pokemon *mon, s32 field) __attribute__((alias("GetMonData3")));

/* GameFreak called GetBoxMonData with either 2 or 3 arguments, for type
* safety we have a GetBoxMonData macro (in include/pokemon.h) which
* dispatches to either GetBoxMonData2 or GetBoxMonData3 based on the
* number of arguments. */
u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data)
{
s32 i;
u32 retVal = 0;
Expand Down Expand Up @@ -3319,6 +3329,8 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
return retVal;
}

u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field) __attribute__((alias("GetBoxMonData3")));

#define SET8(lhs) (lhs) = *data
#define SET16(lhs) (lhs) = data[0] + (data[1] << 8)
#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24)
Expand Down
4 changes: 4 additions & 0 deletions src/vs_seeker.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,11 @@ void ClearRematchStateByTrainerId(void)

TryGetObjectEventIdByLocalIdAndMap(objectEventTemplates[i].localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objEventId);
objectEvent = &gObjectEvents[objEventId];
#if __STDC_VERSION__ < 202311L
GetRandomFaceDirectionMovementType(&objectEventTemplates[i]); // You are using this function incorrectly. Please consult the manual.
#else
GetRandomFaceDirectionMovementType();
#endif
OverrideMovementTypeForObjectEvent(objectEvent, sFaceDirectionMovementTypeByFacingDirection[objectEvent->facingDirection]);
gSaveBlock1Ptr->trainerRematches[objectEventTemplates[i].localId] = 0;
if (gSelectedObjectEvent == objEventId)
Expand Down
1 change: 1 addition & 0 deletions tools/mapjson/json11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstdlib>
#include <cstdio>
#include <limits>
#include <cstdint>

namespace json11 {

Expand Down