Modern fixes (#697)

This commit is contained in:
Jaizu
2025-06-11 20:27:42 +02:00
committed by GitHub
parent f60d28ceb5
commit 507f1d8d36
12 changed files with 85 additions and 18 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ INCLUDE_SCANINC_ARGS := $(INCLUDE_DIRS:%=-I %)
O_LEVEL ?= 2 O_LEVEL ?= 2
CPPFLAGS := $(INCLUDE_CPP_ARGS) -Wno-trigraphs -D$(GAME_VERSION) -DREVISION=$(GAME_REVISION) -D$(GAME_LANGUAGE) -DMODERN=$(MODERN) CPPFLAGS := $(INCLUDE_CPP_ARGS) -Wno-trigraphs -D$(GAME_VERSION) -DREVISION=$(GAME_REVISION) -D$(GAME_LANGUAGE) -DMODERN=$(MODERN)
ifeq ($(MODERN),0) 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) CC1 := tools/agbcc/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O$(O_LEVEL) -fhex-asm override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O$(O_LEVEL) -fhex-asm
LIBPATH := -L ../../tools/agbcc/lib LIBPATH := -L ../../tools/agbcc/lib
+4
View File
@@ -170,7 +170,11 @@ struct SoundChannel
struct MusicPlayerInfo; struct MusicPlayerInfo;
#if __STDC_VERSION__ < 202311L
typedef void (*MPlayFunc)(); typedef void (*MPlayFunc)();
#else
typedef void (*MPlayFunc)(...);
#endif
typedef void (*PlyNoteFunc)(u32, struct MusicPlayerInfo *, struct MusicPlayerTrack *); typedef void (*PlyNoteFunc)(u32, struct MusicPlayerInfo *, struct MusicPlayerTrack *);
typedef void (*CgbSoundFunc)(void); typedef void (*CgbSoundFunc)(void);
typedef void (*CgbOscOffFunc)(u8); typedef void (*CgbOscOffFunc)(u8);
+11
View File
@@ -19,6 +19,10 @@
#define asm_comment(x) asm volatile("@ -- " x " -- ") #define asm_comment(x) asm volatile("@ -- " x " -- ")
#define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided") #define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided")
#if __STDC_VERSION__ < 202311L
#define asm __asm__
#endif
// IDE support // IDE support
#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__INTELLISENSE__) #if defined(__APPLE__) || defined(__CYGWIN__) || defined(__INTELLISENSE__)
// We define these when using certain IDEs to fool preproc // We define these when using certain IDEs to fool preproc
@@ -131,6 +135,13 @@ extern u8 gStringVar4[];
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT) #define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
#define NUM_ADDITIONAL_PHRASE_BYTES ROUND_BITS_TO_BYTES(NUM_ADDITIONAL_PHRASES) #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. // This produces an error at compile-time if expr is zero.
// It looks like file.c:line: size of array `id' is negative // It looks like file.c:line: size of array `id' is negative
#define STATIC_ASSERT(expr, id) typedef char id[(expr) ? 1 : -1]; #define STATIC_ASSERT(expr, id) typedef char id[(expr) ? 1 : -1];
+4
View File
@@ -316,7 +316,11 @@ struct STWIStatus
u8 recoveryCount; u8 recoveryCount;
u8 unk_16; u8 unk_16;
u8 unk_17; u8 unk_17;
#if __STDC_VERSION__ < 202311L
void (*callbackM)(); void (*callbackM)();
#else
void (*callbackM)(...);
#endif
void (*callbackS)(u16); void (*callbackS)(u16);
void (*callbackID)(void); void (*callbackID)(void);
union RfuPacket *txPacket; union RfuPacket *txPacket;
+11 -12
View File
@@ -335,18 +335,17 @@ u8 GetGenderFromSpeciesAndPersonality(u16 species, u32 personality);
void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition); void SetMultiuseSpriteTemplateToPokemon(u16 speciesTag, u8 battlerPosition);
void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosition); void SetMultiuseSpriteTemplateToTrainerBack(u16 trainerSpriteId, u8 battlerPosition);
// These are full type signatures for GetMonData() and GetBoxMonData(), /* GameFreak called Get(Box)MonData with either 2 or 3 arguments, for
// but they are not used since some code erroneously omits the third arg. * type safety we have a Get(Box)MonData macro which dispatches to
// u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data); * either Get(Box)MonData2 or Get(Box)MonData3 based on the number of
// u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data); * arguments. The two functions are aliases of each other, but they
* differ for matching purposes in the caller's codegen. */
#ifdef IS_POKEMON_C #define GetMonData(...) CAT(GetMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__)
u32 GetMonData(struct Pokemon *, s32, u8 *); #define GetBoxMonData(...) CAT(GetBoxMonData, NARG_8(__VA_ARGS__))(__VA_ARGS__)
u32 GetBoxMonData(struct BoxPokemon *, s32, u8 *); u32 GetMonData3(struct Pokemon *mon, s32 field, u8 *data);
#else u32 GetMonData2(struct Pokemon *mon, s32 field);
u32 GetMonData(); u32 GetBoxMonData3(struct BoxPokemon *boxMon, s32 field, u8 *data);
u32 GetBoxMonData(); u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field);
#endif // IS_POKEMON_C
void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg); void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg);
void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg); void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg);
+1 -1
View File
@@ -605,7 +605,7 @@ static void Debug_AddDaycareSteps(u16 numSteps)
u8 GetNumLevelsGainedFromDaycare(void) 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 GetNumLevelsGainedForDaycareMon(&gSaveBlock1Ptr->daycare.mons[gSpecialVar_0x8004]);
return 0; return 0;
+1 -1
View File
@@ -125,7 +125,7 @@ static u8 TeleportAnim_RotatePlayer(struct ObjectEvent * object, s16 *timer);
void MovementType_Player(struct Sprite *sprite) 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) static u8 ObjectEventCB2_NoMovement2(struct ObjectEvent * object, struct Sprite *sprite)
+12
View File
@@ -6,7 +6,11 @@ static u16 handshake_wait(u16 slot);
static void STWI_set_timer_in_RAM(u8 count); static void STWI_set_timer_in_RAM(u8 count);
static void STWI_stop_timer_in_RAM(void); static void STWI_stop_timer_in_RAM(void);
static void STWI_init_slave(void); static void STWI_init_slave(void);
#if __STDC_VERSION__ < 202311L
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)()); 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_S(u16 reqCommandId, void (*callbackS)(u16));
static void Callback_Dummy_ID(void (*callbackId)(void)); static void Callback_Dummy_ID(void (*callbackId)(void));
@@ -134,7 +138,11 @@ static void sio32intr_clock_master(void)
} }
gSTWIStatus->sending = 0; gSTWIStatus->sending = 0;
if (gSTWIStatus->callbackM != NULL) if (gSTWIStatus->callbackM != NULL)
#if __STDC_VERSION__ < 202311L
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM); Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, gSTWIStatus->callbackM);
#else
Callback_Dummy_M(gSTWIStatus->reqActiveCommand, gSTWIStatus->error, (void (*)(...))gSTWIStatus->callbackM);
#endif
} }
else else
{ {
@@ -387,7 +395,11 @@ static void STWI_init_slave(void)
} }
NAKED NAKED
#if __STDC_VERSION__ < 202311L
static void Callback_Dummy_M(int reqCommandId, int error, void (*callbackM)()) 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"); asm("bx r2");
} }
+21 -1
View File
@@ -1,4 +1,4 @@
#include <string.h> #include "global.h"
#include "gba/m4a_internal.h" #include "gba/m4a_internal.h"
extern const u8 gCgb3Vol[]; extern const u8 gCgb3Vol[];
@@ -283,6 +283,7 @@ void MPlayExtender(struct CgbChannel *cgbChans)
soundInfo->ident++; soundInfo->ident++;
#if __STDC_VERSION__ < 202311L
gMPlayJumpTable[8] = ply_memacc; gMPlayJumpTable[8] = ply_memacc;
gMPlayJumpTable[17] = ply_lfos; gMPlayJumpTable[17] = ply_lfos;
gMPlayJumpTable[19] = ply_mod; gMPlayJumpTable[19] = ply_mod;
@@ -292,6 +293,17 @@ void MPlayExtender(struct CgbChannel *cgbChans)
gMPlayJumpTable[31] = TrackStop; gMPlayJumpTable[31] = TrackStop;
gMPlayJumpTable[32] = FadeOutBody; gMPlayJumpTable[32] = FadeOutBody;
gMPlayJumpTable[33] = TrkVolPitSet; 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->cgbChans = cgbChans;
soundInfo->CgbSound = CgbSound; soundInfo->CgbSound = CgbSound;
@@ -320,13 +332,21 @@ void MusicPlayerJumpTableCopy(void)
void ClearChain(void *x) void ClearChain(void *x)
{ {
#if __STDC_VERSION__ < 202311L
void (*func)(void *) = *(&gMPlayJumpTable[34]); void (*func)(void *) = *(&gMPlayJumpTable[34]);
#else
void (*func)(...) = *(&gMPlayJumpTable[34]);
#endif
func(x); func(x);
} }
void Clear64byte(void *x) void Clear64byte(void *x)
{ {
#if __STDC_VERSION__ < 202311L
void (*func)(void *) = *(&gMPlayJumpTable[35]); void (*func)(void *) = *(&gMPlayJumpTable[35]);
#else
void (*func)(...) = *(&gMPlayJumpTable[35]);
#endif
func(x); func(x);
} }
+14 -2
View File
@@ -2895,7 +2895,11 @@ static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 perso
return substruct; 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; u32 ret;
@@ -2963,7 +2967,13 @@ u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data)
return ret; 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; s32 i;
u32 retVal = 0; u32 retVal = 0;
@@ -3319,6 +3329,8 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
return retVal; return retVal;
} }
u32 GetBoxMonData2(struct BoxPokemon *boxMon, s32 field) __attribute__((alias("GetBoxMonData3")));
#define SET8(lhs) (lhs) = *data #define SET8(lhs) (lhs) = *data
#define SET16(lhs) (lhs) = data[0] + (data[1] << 8) #define SET16(lhs) (lhs) = data[0] + (data[1] << 8)
#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) #define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24)
+4
View File
@@ -954,7 +954,11 @@ void ClearRematchStateByTrainerId(void)
TryGetObjectEventIdByLocalIdAndMap(objectEventTemplates[i].localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objEventId); TryGetObjectEventIdByLocalIdAndMap(objectEventTemplates[i].localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, &objEventId);
objectEvent = &gObjectEvents[objEventId]; objectEvent = &gObjectEvents[objEventId];
#if __STDC_VERSION__ < 202311L
GetRandomFaceDirectionMovementType(&objectEventTemplates[i]); // You are using this function incorrectly. Please consult the manual. GetRandomFaceDirectionMovementType(&objectEventTemplates[i]); // You are using this function incorrectly. Please consult the manual.
#else
GetRandomFaceDirectionMovementType();
#endif
OverrideMovementTypeForObjectEvent(objectEvent, sFaceDirectionMovementTypeByFacingDirection[objectEvent->facingDirection]); OverrideMovementTypeForObjectEvent(objectEvent, sFaceDirectionMovementTypeByFacingDirection[objectEvent->facingDirection]);
gSaveBlock1Ptr->trainerRematches[objectEventTemplates[i].localId] = 0; gSaveBlock1Ptr->trainerRematches[objectEventTemplates[i].localId] = 0;
if (gSelectedObjectEvent == objEventId) if (gSelectedObjectEvent == objEventId)
+1
View File
@@ -23,6 +23,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstdio> #include <cstdio>
#include <limits> #include <limits>
#include <cstdint>
namespace json11 { namespace json11 {