summaryrefslogtreecommitdiff
path: root/include/global.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/global.h')
-rw-r--r--include/global.h110
1 files changed, 79 insertions, 31 deletions
diff --git a/include/global.h b/include/global.h
index 4ccd2be50..e4c11f9ef 100644
--- a/include/global.h
+++ b/include/global.h
@@ -9,6 +9,7 @@
#include "constants/flags.h"
#include "constants/vars.h"
#include "constants/species.h"
+#include "constants/berry.h"
// Prevent cross-jump optimization.
#define BLOCK_CROSS_JUMP asm("");
@@ -73,6 +74,14 @@
#define abs(x) (((x) < 0) ? -(x) : (x))
#endif
+// Used in cases where division by 0 can occur in the retail version.
+// Avoids invalid opcodes on some emulators, and the otherwise UB.
+#ifdef UBFIX
+#define SAFE_DIV(a, b) ((b) ? (a) / (b) : 0)
+#else
+#define SAFE_DIV(a, b) ((a) / (b))
+#endif
+
// Extracts the upper 16 bits of a 32-bit number
#define HIHALF(n) (((n) & 0xFFFF0000) >> 16)
@@ -98,7 +107,7 @@
#define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr)
// Macros for checking the joypad
-#define TEST_BUTTON(field, button) ({(field) & (button);})
+#define TEST_BUTTON(field, button) ((field) & (button))
#define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button)
#define JOY_HELD(button) TEST_BUTTON(gMain.heldKeys, button)
#define JOY_HELD_RAW(button) TEST_BUTTON(gMain.heldKeysRaw, button)
@@ -174,13 +183,13 @@ struct Pokedex
/*0x44*/ u8 seen[DEX_FLAGS_NO];
};
-struct PokemonJumpResults
+struct PokemonJumpRecords
{
u16 jumpsInRow;
- u16 field2;
+ u16 unused1; // Set to 0, never read
u16 excellentsInRow;
- u16 field6;
- u32 field8;
+ u16 gamesWithMaxPlayers;
+ u32 unused2; // Set to 0, never read
u32 bestJumpScore;
};
@@ -208,7 +217,7 @@ struct PyramidBag
struct BerryCrush
{
- u16 berryCrushResults[4];
+ u16 pressingSpeeds[4]; // For the record with each possible group size, 2-5 players
u32 berryPowderAmount;
u32 unk;
};
@@ -477,7 +486,7 @@ struct SaveBlock2
/*0xB0*/ struct PlayersApprentice playerApprentice;
/*0xDC*/ struct Apprentice apprentices[APPRENTICE_COUNT];
/*0x1EC*/ struct BerryCrush berryCrush;
- /*0x1FC*/ struct PokemonJumpResults pokeJump;
+ /*0x1FC*/ struct PokemonJumpRecords pokeJump;
/*0x20C*/ struct BerryPickingResults berryPick;
/*0x21C*/ struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][2][3]; // From record mixing.
/*0x57C*/ struct RankingHall2P hallRecords2P[2][3]; // From record mixing.
@@ -500,7 +509,7 @@ struct SecretBaseParty
struct SecretBase
{
/*0x1A9C*/ u8 secretBaseId;
- /*0x1A9D*/ u8 sbr_field_1_0:4;
+ /*0x1A9D*/ bool8 toRegister:4;
/*0x1A9D*/ u8 gender:1;
/*0x1A9D*/ u8 battledOwnerToday:1;
/*0x1A9D*/ u8 registryStatus:2;
@@ -509,7 +518,7 @@ struct SecretBase
/*0x1AA9*/ u8 language;
/*0x1AAA*/ u16 numSecretBasesReceived;
/*0x1AAC*/ u8 numTimesEntered;
- /*0x1AAD*/ u8 sbr_field_11;
+ /*0x1AAD*/ u8 unused;
/*0x1AAE*/ u8 decorations[DECOR_MAX_SECRET_BASE];
/*0x1ABE*/ u8 decorationPositions[DECOR_MAX_SECRET_BASE];
/*0x1AD0*/ struct SecretBaseParty party;
@@ -578,12 +587,13 @@ struct RamScript
struct RamScriptData data;
};
-struct EasyChatPair
+// See dewford_trend.c
+struct DewfordTrend
{
- u16 unk0_0:7;
- u16 unk0_7:7;
- u16 unk1_6:1;
- u16 unk2;
+ u16 trendiness:7;
+ u16 maxTrendiness:7;
+ u16 gainingTrendiness:1;
+ u16 rand;
u16 words[2];
}; /*size = 0x8*/
@@ -717,7 +727,7 @@ struct ContestWinner
u8 contestRank;
};
-struct DayCareMail
+struct DaycareMail
{
struct MailStruct message;
u8 OT_name[PLAYER_NAME_LENGTH + 1];
@@ -729,7 +739,7 @@ struct DayCareMail
struct DaycareMon
{
struct BoxPokemon mon;
- struct DayCareMail mail;
+ struct DaycareMail mail;
u32 steps;
};
@@ -740,9 +750,9 @@ struct DayCare
u8 stepCounter;
};
-struct RecordMixingDayCareMail
+struct RecordMixingDaycareMail
{
- struct DayCareMail mail[DAYCARE_MON_COUNT];
+ struct DaycareMail mail[DAYCARE_MON_COUNT];
u32 numDaycareMons;
bool16 holdsItem[DAYCARE_MON_COUNT];
};
@@ -892,11 +902,57 @@ struct MysteryEventStruct
/*0x000 0x322C*/ struct WonderNewsSaveStruct wonderNews;
/*0x1c0 0x33EC*/ struct WonderCardSaveStruct wonderCard;
/*0x310 0x353C*/ struct MEventBuffer_3430 buffer_310;
- /*0x338 0x3564*/ u16 unk_338[4];
+ /*0x338 0x3564*/ u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
/*0x340 0x356C*/ struct MysteryEventStruct unk_340;
/*0x344 0x3570*/ u32 unk_344[2][5];
}; // 0x36C 0x3598
+// For external event data storage. The majority of these may have never been used.
+// In Emerald, the only known used fields are the PokeCoupon and BoxRS ones, but hacking the distribution discs allows Emerald to receive events and set the others
+struct ExternalEventData
+{
+ u8 unknownExternalDataFields1[7]; // if actually used, may be broken up into different fields.
+ u32 unknownExternalDataFields2:8;
+ u32 currentPokeCoupons:24; // PokéCoupons stored by Pokémon Colosseum and XD from Mt. Battle runs. Earned PokéCoupons are also added to totalEarnedPokeCoupons. Colosseum/XD caps this at 9,999,999, but will read up to 16,777,215.
+ u32 gotGoldPokeCouponTitleReward:1; // Master Ball from JP Colosseum Bonus Disc; for reaching 30,000 totalEarnedPokeCoupons
+ u32 gotSilverPokeCouponTitleReward:1; // Light Ball Pikachu from JP Colosseum Bonus Disc; for reaching 5000 totalEarnedPokeCoupons
+ u32 gotBronzePokeCouponTitleReward:1; // PP Max from JP Colosseum Bonus Disc; for reaching 2500 totalEarnedPokeCoupons
+ u32 receivedAgetoCelebi:1; // from JP Colosseum Bonus Disc
+ u32 unknownExternalDataFields3:4;
+ u32 totalEarnedPokeCoupons:24; // Used by the JP Colosseum bonus disc. Determines PokéCoupon rank to distribute rewards. Unread in International games. Colosseum/XD caps this at 9,999,999.
+ u8 unknownExternalDataFields4[5]; // if actually used, may be broken up into different fields.
+} __attribute__((packed)); /*size = 0x14*/
+
+// For external event flags. The majority of these may have never been used.
+// In Emerald, Jirachi cannot normally be received, but hacking the distribution discs allows Emerald to receive Jirachi and set the flag
+struct ExternalEventFlags
+{
+ u8 usedBoxRS:1; // Set by Pokémon Box: Ruby & Sapphire; denotes whether this save has connected to it and triggered the free False Swipe Swablu Egg giveaway.
+ u8 boxRSEggsUnlocked:2; // Set by Pokémon Box: Ruby & Sapphire; denotes the number of Eggs unlocked from deposits; 1 for ExtremeSpeed Zigzagoon (at 100 deposited), 2 for Pay Day Skitty (at 500 deposited), 3 for Surf Pichu (at 1499 deposited)
+ u8 padding:5;
+ u8 unknownFlag1;
+ u8 receivedGCNJirachi; // Both the US Colosseum Bonus Disc and PAL/AUS Pokémon Channel use this field. One cannot receive a WISHMKR Jirachi and CHANNEL Jirachi with the same savefile.
+ u8 unknownFlag3;
+ u8 unknownFlag4;
+ u8 unknownFlag5;
+ u8 unknownFlag6;
+ u8 unknownFlag7;
+ u8 unknownFlag8;
+ u8 unknownFlag9;
+ u8 unknownFlag10;
+ u8 unknownFlag11;
+ u8 unknownFlag12;
+ u8 unknownFlag13;
+ u8 unknownFlag14;
+ u8 unknownFlag15;
+ u8 unknownFlag16;
+ u8 unknownFlag17;
+ u8 unknownFlag18;
+ u8 unknownFlag19;
+ u8 unknownFlag20;
+
+} __attribute__((packed));/*size = 0x15*/
+
struct SaveBlock1
{
/*0x00*/ struct Coords16 pos;
@@ -966,11 +1022,13 @@ struct SaveBlock1
/*0x2BE0*/ struct MailStruct mail[MAIL_COUNT];
/*0x2E20*/ u8 additionalPhrases[8]; // bitfield for 33 additional phrases in easy chat system
/*0x2E28*/ OldMan oldMan;
- /*0x2e64*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff
+ /*0x2e64*/ struct DewfordTrend dewfordTrends[SAVED_TRENDS_COUNT];
/*0x2e90*/ struct ContestWinner contestWinners[NUM_CONTEST_WINNERS]; // see CONTEST_WINNER_*
/*0x3030*/ struct DayCare daycare;
/*0x3150*/ struct LinkBattleRecords linkBattleRecords;
- /*0x31A8*/ u8 giftRibbons[52];
+ /*0x31A8*/ u8 giftRibbons[GIFT_RIBBONS_COUNT];
+ /*0x31B3*/ struct ExternalEventData externalEventData;
+ /*0x31C7*/ struct ExternalEventFlags externalEventFlags;
/*0x31DC*/ struct Roamer roamer;
/*0x31F8*/ struct EnigmaBerry enigmaBerry;
/*0x322C*/ struct MEventBuffers unk_322C;
@@ -997,14 +1055,4 @@ struct MapPosition
s8 height;
};
-struct TradeRoomPlayer
-{
- u8 playerId;
- u8 isLocalPlayer;
- u8 c;
- u8 facing;
- struct MapPosition pos;
- u16 field_C;
-};
-
#endif // GUARD_GLOBAL_H