code:
#ifndef GUARD_TASK_H
#define GUARD_TASK_H

#define HEAD_SENTINEL 0xFE
#define TAIL_SENTINEL 0xFF

#define NUM_TASKS 16
#define NUM_TASK_DATA 16

typedef void (*TaskFunc)(u8 taskId);

struct Task
{
    TaskFunc func;
    bool8 isActive;
    u8 prev;
    u8 next;
    u8 priority;
    s16 data[NUM_TASK_DATA];
};

extern struct Task gTasks[];

void ResetTasks(void);
u8 CreateTask(TaskFunc func, u8 priority);
void DestroyTask(u8 taskId);
void RunTasks(void);
void TaskDummy(u8 taskId);
void SetTaskFuncWithFollowupFunc(u8 taskId, TaskFunc func, TaskFunc followupFunc);
void SwitchTaskToFollowupFunc(u8 taskId);
bool8 FuncIsActiveTask(TaskFunc func);
u8 FindTaskIdByFunc(TaskFunc func);
u8 GetTaskCount(void);
void SetWordTaskArg(u8 taskId, u8 dataElem, u32 value);
u32 GetWordTaskArg(u8 taskId, u8 dataElem);

#endif // GUARD_TASK_H

repo_name: Lunos/pokeemerald

license: mit


code:
#ifndef GUARD_TEXT_WINDOW_H
#define GUARD_TEXT_WINDOW_H

#define WINDOW_FRAMES_COUNT 20

struct TilesPal
{
    const u8 *tiles;
    const u16 *pal;
};

extern const u8 gTextWindowFrame1_Gfx[];
extern const u16 gTextWindowFrame1_Pal[];

const struct TilesPal *GetWindowFrameTilesPal(u8 id);
void LoadMessageBoxGfx(u8 windowId, u16 destOffset, u8 palOffset);
void LoadUserWindowBorderGfx(u8 windowId, u16 destOffset, u8 palOffset);
void LoadWindowGfx(u8 windowId, u8 frameId, u16 destOffset, u8 palOffset);
void LoadUserWindowBorderGfx_(u8 windowId, u16 destOffset, u8 palOffset);
void DrawTextBorderOuter(u8 windowId, u16 tileNum, u8 palNum);
void DrawTextBorderInner(u8 windowId, u16 tileNum, u8 palNum);
void rbox_fill_rectangle(u8 windowId);
const u16 *GetTextWindowPalette(u8 id);
const u16 *GetOverworldTextboxPalettePtr(void);
void sub_8098C6C(u8 bg, u16 destOffset, u8 palOffset);

#endif // GUARD_TEXT_WINDOW_H


code:
#ifndef GUARD_TILESET_ANIMS_H
#define GUARD_TILESET_ANIMS_H

void InitTilesetAnimations(void);
void InitSecondaryTilesetAnimation(void);
void UpdateTilesetAnimations(void);
void TransferTilesetAnimsBuffer(void);

#endif // GUARD_TILESET_ANIMS_H


code:
#ifndef GUARD_tilesets_H
#define GUARD_tilesets_H

// Exported type declarations

// Exported RAM declarations

// Exported ROM declarations

extern struct Tileset *gTilesetPointer_SecretBase;
extern struct Tileset *gTilesetPointer_SecretBaseRedCave;

#endif //GUARD_tilesets_H


code:
#ifndef GUARD_TIME_EVENTS_H
#define GUARD_TIME_EVENTS_H

void UpdateMirageRnd(u16);
u8 IsMirageIslandPresent(void);
void UpdateBirchState(u16);

#endif // GUARD_TIME_EVENTS_H


code:
#ifndef GUARD_TITLE_SCREEN_H
#define GUARD_TITLE_SCREEN_H

extern const u16 gIntroWaterDropAlphaBlend[];

void CB2_InitTitleScreen(void);

#endif // GUARD_TITLE_SCREEN_H


code:
#ifndef GUARD_TRADE_H
#define GUARD_TRADE_H

#include "link_rfu.h"
#include "constants/trade.h"

// Exported type declarations

// Exported RAM declarations
extern struct MailStruct gTradeMail[PARTY_SIZE];
extern u8 gSelectedTradeMonPositions[2];

// Exported ROM declarations
extern const struct WindowTemplate gTradeEvolutionSceneYesNoWindowTemplate;

s32 GetGameProgressForLinkTrade(void);
void CB2_StartCreateTradeMenu(void);
void CB2_LinkTrade(void);
int CanRegisterMonForTradingBoard(struct GFtgtGnameSub a0, u16, u16, u8);
int GetUnionRoomTradeMessageId(struct GFtgtGnameSub a0, struct GFtgtGnameSub a1, u16 a2, u16 a3, u8 a4, u16 a5, u8 a6);
int CanSpinTradeMon(struct Pokemon*, u16);
void InitTradeSequenceBgGpuRegs(void);
void LinkTradeDrawWindow(void);
void InitTradeBg(void);
void DrawTextOnTradeWindow(u8, const u8 *, u8);

#endif //GUARD_TRADE_H


code:
//
// Created by scott on 10/21/2017.
//

#ifndef GUARD_TRADER_H
#define GUARD_TRADER_H

void DecorationItemsMenuAction_Trade(u8 taskId);
void ExitTraderMenu(u8 taskId);
void TraderSetup(void);
void Trader_ResetFlag(void);

#endif //GUARD_TRADER_H


code:
#ifndef GUARD_TRAINER_CARD_H
#define GUARD_TRAINER_CARD_H

#define TRAINER_CARD_PROFILE_LENGTH  4
#define TRAINER_CARD_STICKER_TYPES   3

enum
{
    CARD_TYPE_FRLG,
    CARD_TYPE_RS,
    CARD_TYPE_EMERALD,
};

enum
{
    MON_ICON_TINT_NORMAL,
    MON_ICON_TINT_BLACK,
    MON_ICON_TINT_PINK,
    MON_ICON_TINT_SEPIA,
};

struct TrainerCard
{
    /*0x00*/ u8 gender;
    /*0x01*/ u8 stars;
    /*0x02*/ bool8 hasPokedex;
    /*0x03*/ bool8 caughtAllHoenn;
    /*0x04*/ bool8 hasAllPaintings;
    /*0x06*/ u16 hofDebutHours;
    /*0x08*/ u16 hofDebutMinutes;
    /*0x0A*/ u16 hofDebutSeconds;
    /*0x0C*/ u16 caughtMonsCount;
    /*0x0E*/ u16 trainerId;
    /*0x10*/ u16 playTimeHours;
    /*0x12*/ u16 playTimeMinutes;
    /*0x14*/ u16 linkBattleWins;
    /*0x16*/ u16 linkBattleLosses;
    /*0x18*/ u16 battleTowerWins;
    /*0x1A*/ u16 battleTowerStraightWins;
    /*0x1C*/ u16 contestsWithFriends;
    /*0x1E*/ u16 pokeblocksWithFriends;
    /*0x20*/ u16 pokemonTrades;
    /*0x24*/ u32 money;
    /*0x28*/ u16 easyChatProfile[TRAINER_CARD_PROFILE_LENGTH];
    /*0x30*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
    /*0x38*/ u8 version;
    /*0x3A*/ bool16 hasAllFrontierSymbols;
    /*0x3C*/ u32 berryCrushPoints;
    /*0x40*/ u32 unionRoomNum;
    /*0x44*/ u8 filler[8];
    /*0x4C*/ bool8 shouldDrawStickers; // FRLG only
    /*0x4D*/ u8 unused;
    /*0x4E*/ u8 monIconTint; // FRLG only
    /*0x4F*/ u8 facilityClass;
    /*0x50*/ u8 stickers[TRAINER_CARD_STICKER_TYPES]; // FRLG only
    /*0x54*/ u16 monSpecies[PARTY_SIZE]; // FRLG only
    /*0x60*/ bool16 hasAllSymbols;
    /*0x62*/ u16 frontierBP;
};

extern struct TrainerCard gTrainerCards[4];

u32 CountPlayerTrainerStars(void);
u8 GetTrainerCardStars(u8 cardId);
void CopyTrainerCardData(struct TrainerCard *dst, u16 *src, u8 gameVersion);
void ShowPlayerTrainerCard(void (*callback)(void));
void ShowTrainerCardInLink(u8 arg0, void (*callback)(void));
void TrainerCard_GenerateCardForPlayer(struct TrainerCard *);

#endif // GUARD_TRAINER_CARD_H


code:
#ifndef GUARD_TRAINER_HILL_H
#define GUARD_TRAINER_HILL_H

#define HILL_TRAINER_NAME_LENGTH 11

struct TrainerHillTrainer
{
    u8 name[HILL_TRAINER_NAME_LENGTH];
    u8 facilityClass;
    u32 unused;
    u16 speechBefore[EASY_CHAT_BATTLE_WORDS_COUNT];
    u16 speechWin[EASY_CHAT_BATTLE_WORDS_COUNT];
    u16 speechLose[EASY_CHAT_BATTLE_WORDS_COUNT];
    u16 speechAfter[EASY_CHAT_BATTLE_WORDS_COUNT];
    struct BattleTowerPokemon mons[PARTY_SIZE];
};

struct TrHillRoomTrainers
{
    u8 name[2][HILL_TRAINER_NAME_LENGTH];
    u8 facilityClass[2];
};

struct TrHillDisplay
{
    // Metatile data. Add 0x200 to the values in this array to get metatiles.
    // This data then overwrites the metatiles in the map starting at (0,5)
    u8 metatileData[0x100];
    // Collision data. One bit for each tile in column-major order,
    // so every array entry is one row. 1 = impassable, 0 = passable
    u16 collisionData[16];
    // Trainer coordinates, starting at (0,6). Format is 0bYYYYXXXX.
    u8 coords[2];
    // Trainer facing directions. Same as (DIR_* - 1).
    // Effectively an array of nibbles, one for each trainer.
    u8 direction;
    // Trainer sight ranges. Effectively an array of nibbles, one for each trainer.
    u8 range;
};

struct TrHillFloor
{
    u8 trainerNum1;
    u8 trainerNum2;
    struct TrainerHillTrainer trainers[2];
    struct TrHillDisplay display;
};

struct TrHillTag
{
    u8 numTrainers;
    u8 unused1;
    u8 numFloors;
    u32 checksum;
    struct TrHillFloor floors[0];
};

extern u32 *gTrainerHillVBlankCounter;

void CallTrainerHillFunction(void);
void ResetTrainerHillResults(void);
u8 GetTrainerHillOpponentClass(u16 trainerId);
void GetTrainerHillTrainerName(u8 *dst, u16 trainerId);
u8 GetTrainerHillTrainerFrontSpriteId(u16 trainerId);
void InitTrainerHillBattleStruct(void);
void FreeTrainerHillBattleStruct(void);
void CopyTrainerHillTrainerText(u8 which, u16 trainerId);
bool8 InTrainerHillChallenge(void);
void nullsub_129(void);
void PrintOnTrainerHillRecordsWindow(void);
void LoadTrainerHillObjectEventTemplates(void);
bool32 LoadTrainerHillFloorObjectEventScripts(void);
void GenerateTrainerHillFloorLayout(u16 *mapArg);
bool32 InTrainerHill(void);
u8 GetCurrentTrainerHillMapId(void);
const struct WarpEvent* SetWarpDestinationTrainerHill4F(void);
const struct WarpEvent* SetWarpDestinationTrainerHillFinalFloor(u8 warpEventId);
u16 LocalIdToHillTrainerId(u8 localId);
bool8 GetHillTrainerFlag(u8 objectEventId);
void SetHillTrainerFlag(void);
const u8 *GetTrainerHillTrainerScript(void);
void FillHillTrainerParty(void);
void FillHillTrainersParties(void);
u8 GetTrainerEncounterMusicIdInTrainerHill(u16 trainerId);
u8 GetNumFloorsInTrainerHillChallenge(void);
void TryLoadTrainerHillEReaderPalette(void);
bool32 OnTrainerHillEReaderChallengeFloor(void);

#endif // GUARD_TRAINER_HILL_H


code:
#ifndef GUARD_TRAINER_POKEMON_SPRITES_H
#define GUARD_TRAINER_POKEMON_SPRITES_H

bool16 ResetAllPicSprites(void);
u16 CreatePicSprite2(u16 species, u32 otId, u32 personality, u8 flags, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 CreateMonPicSprite_HandleDeoxys(u16 species, u32 otId, u32 personality, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 FreeAndDestroyMonPicSprite(u16 spriteId);
u16 CreateTrainerPicSprite(u16 species, bool8 isFrontPic, s16 x, s16 y, u8 paletteSlot, u16 paletteTag);
u16 FreeAndDestroyTrainerPicSprite(u16 spriteId);
u16 CreateTrainerCardTrainerPicSprite(u16 species, bool8 isFrontPic, u16 destX, u16 destY, u8 paletteSlot, u8 windowId);
u16 PlayerGenderToFrontTrainerPicId_Debug(u8 gender, bool8 getClass);

#endif // GUARD_TRAINER_POKEMON_SPRITES_H


code:
#ifndef GUARD_TRAINER_SEE_H
#define GUARD_TRAINER_SEE_H

struct ApproachingTrainer
{
    u8 objectEventId;
    u8 radius; // plus 1
    const u8 *trainerScriptPtr;
    u8 taskId;
};

extern u16 gWhichTrainerToFaceAfterBattle;
extern u8 gPostBattleMovementScript[4];
extern struct ApproachingTrainer gApproachingTrainers[2];
extern u8 gNoOfApproachingTrainers;
extern bool8 gTrainerApproachedPlayer;
extern u8 gApproachingTrainerId;

bool8 CheckForTrainersWantingBattle(void);
void sub_80B4578(struct ObjectEvent *var);
void EndTrainerApproach(void);
void TryPrepareSecondApproachingTrainer(void);
u8 FldEff_ExclamationMarkIcon(void);
u8 FldEff_QuestionMarkIcon(void);
u8 FldEff_HeartIcon(void);
u8 GetCurrentApproachingTrainerObjectEventId(void);
u8 GetChosenApproachingTrainerObjectEventId(u8 arrayId);
void PlayerFaceTrainerAfterBattle(void);

#endif // GUARD_TRAINER_SEE_H


code:
#ifndef GUARD_TRIG_H
#define GUARD_TRIG_H

extern const s16 gSineTable[];

s16 Sin(s16 index, s16 amplitude);
s16 Cos(s16 index, s16 amplitude);
s16 Sin2(u16 angle);
s16 Cos2(u16 angle);

#endif // GUARD_TRIG_H


code:
#ifndef GUARD_TV_H
#define GUARD_TV_H

#define SLOT_MACHINE 0
#define ROULETTE 1

extern u8 *const gTVStringVarPtrs[3];

void ClearTVShowData(void);
void sub_80EE184(void);
void sub_80EE35C(u16 foeSpecies, u16 species, u8 moveIdx, const u16 *movePtr, u16 betterMove);
void TryPutFrontierTVShowOnAir(u16 winStreak, u8 facility);
void DoTVShow(void);
void DoTVShowInSearchOfTrainers(void);
void TryPutTreasureInvestigatorsOnAir(void);
void TryPutLotteryWinnerReportOnAir(void);
void TryPutTrainerFanClubOnAir(void);
void IncrementDailyPlantedBerries(void);
void IncrementDailyPickedBerries(void);
void IncrementDailyBattlePoints(u16 delta);
void HideBattleTowerReporter(void);
void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx);
void TryPutSpotTheCutiesOnAir(struct Pokemon *pokemon, u8 ribbonMonDataIdx);
u32 GetPlayerIDAsU32(void);
bool8 GetPriceReduction(u8 newsKind);
void sub_80F14F8(TVShow *shows);
size_t CountDigits(int value);
u8 GetRibbonCount(struct Pokemon *pokemon);
void AlertTVThatPlayerPlayedSlotMachine(u16 nCoinsSpent);
void AlertTVThatPlayerPlayedRoulette(u16 nCoinsSpent);
void AlertTVOfNewCoinTotal(u16 nCoinsPaidOut);
void TryPutSecretBaseSecretsOnAir(void);
void TryPutTodaysRivalTrainerOnAir(void);
void sub_80EDC60(const u16 *words);
void sub_80EDA80(void);
void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx);
void sub_80F0BB8(void);
void RecordFishingAttemptForTV(bool8 caughtFish);
void IncrementDailySlotsUses(void);
void IncrementDailyRouletteUses(void);
void IncrementDailyWildBattles(void);
void IncrementDailyBerryBlender(void);
void sub_80F1208(TVShow *shows);
void sub_80EE44C(u8 nMonsCaught, u8 nPkblkUsed);
void sub_80F14F8(TVShow *shows);
size_t sub_80EF370(int value);
bool8 Put3CheersForPokeblocksOnTheAir(const u8 *partnersName, u8 flavor, u8 unused, u8 sheen, u8 language);
void SetPokemonAnglerSpecies(u16 species);
void UpdateTVShowsPerDay(u16 days);
void PutPokemonTodayCaughtOnAir(void);
void TV_PutSecretBaseVisitOnTheAir(void);
void PutBattleUpdateOnTheAir(u8 opponentLinkPlayerId, u16 move, u16 speciesPlayer, u16 speciesOpponent);
void BravoTrainerPokemonProfile_BeforeInterview1(u16 move);
void InterviewBefore(void);
void InterviewAfter(void);
void UpdateTVScreensOnMap(int, int);
void TV_PrintIntToStringVar(u8 varIdx, int value);
void SaveRecordedItemPurchasesForTVShow(void);
bool8 ShouldAirFrontierTVShow(void);
void sub_80EE8C8(u16 winStreak, u8 facilityAndMode);
void BravoTrainerPokemonProfile_BeforeInterview2(u8 contestStandingPlace);
void ContestLiveUpdates_Init(u8 round1Placing);
void ContestLiveUpdates_SetRound2Placing(u8 round2Placing);
void ContestLiveUpdates_SetWinnerAppealFlag(u8 flag);
void ContestLiveUpdates_SetWinnerMoveUsed(u16 move);
void ContestLiveUpdates_SetLoserData(u8 flag, u8 loser);
void ResetGabbyAndTy(void);

#endif //GUARD_TV_H


code:
#ifndef GUARD_UNION_ROOM_H
#define GUARD_UNION_ROOM_H

#include "link_rfu.h"
#include "link.h"
#include "constants/union_room.h"

// Exported type declarations

struct WirelessGnameUnamePair
{
    struct GFtgtGname gname;
    u8 ALIGNED(4) playerName[PLAYER_NAME_LENGTH + 1];
};

struct UnkStruct_x1C
{
    struct WirelessGnameUnamePair gname_uname;
    u8 active:1;
};

struct UnkStruct_x20
{
    struct WirelessGnameUnamePair gname_uname;
    u16 timeoutCounter;
    u8 groupScheduledAnim:2;
    bool8 useRedText:1; // Never set
    u8 field_1B;
    u8 filler[3];
};

struct UnkStruct_Main0
{
    struct UnkStruct_x20 arr[MAX_UNION_ROOM_PLAYERS];
};

struct UnkStruct_Main4
{
    struct UnkStruct_x1C arr[MAX_RFU_PLAYERS];
};

struct UnkStruct_Main8
{
    struct UnkStruct_x20 arr[MAX_RFU_PLAYERS];
};

struct WirelessLink_Leader
{
    struct UnkStruct_Main0 *field_0;
    struct UnkStruct_Main4 *field_4;
    struct UnkStruct_Main8 *field_8;
    u8 state;
    u8 textState;
    u8 delayTimerAfterOk;
    u8 listWindowId;
    u8 bButtonCancelWindowId;
    u8 nPlayerModeWindowId;
    u8 listTaskId;
    u8 playerCount;
    u16 field_14;
    u8 field_16;
    u8 listenTaskId;
    u8 activity;
    u8 joinRequestAnswer;
    u16 memberConfirmTimeout;
};

struct WirelessLink_Group
{
    struct UnkStruct_Main0 *field_0;
    struct UnkStruct_Main4 *field_4;
    u8 state;
    u8 textState;
    u8 field_A;
    u8 listWindowId;
    u8 bButtonCancelWindowId;
    u8 playerNameAndIdWindowId;
    u8 listTaskId;
    u8 leaderId;
    u8 field_10;
    u8 listenTaskId;
    u8 isWonderNews;
    u8 field_13;
    u8 refreshTimer;
    u8 delayBeforePrint;
};

struct UnionRoomObject
{
    u8 state;
    u8 gfxId;
    s8 animState;
    u8 schedAnim;
};

struct WirelessLink_URoom
{
    struct UnkStruct_Main0 *field_0;
    struct UnkStruct_Main4 *field_4;
    struct UnkStruct_Main0 *field_8;
    struct UnkStruct_Main4 *field_C;
    u16 unknown; // Never read
    u16 field_12;
    u8 state;
    u8 stateAfterPrint;
    u8 textState;
    u8 filler[4];
    u8 topListMenuWindowId;
    u8 topListMenuId;
    u8 tradeBoardSelectWindowId;
    u8 tradeBoardDetailsWindowId;
    u8 unused1;
    u8 searchTaskId;
    u8 spriteIds[40];
    u8 unused2;
    u8 tradeBoardListMenuId;
    u16 playerSendBuffer[6];
    u8 activityRequestStrbufs[4][16];
    u16 partnerYesNoResponse;
    u16 recvActivityRequest[3];
    struct UnionRoomObject objects[MAX_UNION_ROOM_PLAYERS];
    u8 trainerCardStrBuffer[12][15];
    u8 trainerCardColorStrBuffer[48];
    u8 trainerCardMsgStrBuffer[200];
};

union WirelessLink_Main
{
    struct WirelessLink_Leader *leader;
    struct WirelessLink_Group *group;
    struct WirelessLink_URoom *uRoom;
};

struct UnionRoomTrade
{
    u16 state;
    u16 type;
    u32 playerPersonality;
    u8 offerPlayerId;
    u8 filler1;
    u16 playerSpecies;
    u16 playerLevel;
    u16 species;
    u16 level;
    u16 filler2;
    u32 personality;
};

// Exported RAM declarations

extern u8 gPlayerCurrActivity;
extern union WirelessLink_Main gUnknown_02022C30;
extern struct GFtgtGnameSub gPartnerTgtGnameSub;

extern u16 gUnionRoomOfferedSpecies;
extern u8 gUnionRoomRequestedMonType;

// Exported ROM declarations

u8 CreateTask_CreateTradeMenu(void);
void SetUsingUnionRoomStartMenu(void);
void MEvent_CreateTask_CardOrNewsWithFriend(u32 arg0);
void MEvent_CreateTask_CardOrNewsOverWireless(u32 arg0);
void MEvent_CreateTask_Leader(u32 arg0);
u8 CreateTask_ListenToWireless(void);
void StartUnionRoomBattle(u16 battleFlags);

#endif //GUARD_UNION_ROOM_H


code:
#ifndef GUARD_UNION_ROOM_BATTLE_H
#define GUARD_UNION_ROOM_BATTLE_H

void CB2_UnionRoomBattle(void);

#endif //GUARD_UNION_ROOM_BATTLE_H


code:
#ifndef GUARD_UNION_ROOM_CHAT_H
#define GUARD_UNION_ROOM_CHAT_H

void EnterUnionRoomChat(void);
void InitUnionRoomChatRegisteredTexts(void);

#endif // GUARD_UNION_ROOM_CHAT_H


code:
#ifndef GUARD_UNION_ROOM_PLAYER_AVATAR_H
#define GUARD_UNION_ROOM_PLAYER_AVATAR_H

u8 InitUnionRoomPlayerObjects(struct UnionRoomObject *players);
void DestroyUnionRoomPlayerObjects(void);
void CreateGroupMemberSpritesInvisible(u8 *spriteIds, s32 playerIdx);
void DestroyGroupMemberSprites(u8 *spriteIds);
void SetTilesAroundUnionRoomPlayersPassable(void);
void ScheduleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom);
void HandleUnionRoomPlayerRefresh(struct WirelessLink_URoom *uroom);
bool32 TryInteractWithUnionRoomMember(struct UnkStruct_Main0 *main0, s16 *directionPtr, s16 *playerIdxPtr, u8 *spriteIds);
void UpdateUnionRoomMemberFacing(u32 currDirection, u32 playerIdx, struct UnkStruct_Main0 *main0);

#endif //GUARD_UNION_ROOM_PLAYER_AVATAR_H


code:
#ifndef GUARD_UTIL_H
#define GUARD_UTIL_H

#include "sprite.h"

extern const u8 gMiscBlank_Gfx[]; // unused in Emerald
extern const u32 gBitTable[];

u8 CreateInvisibleSpriteWithCallback(void (*)(struct Sprite *));
void StoreWordInTwoHalfwords(u16 *, u32);
void LoadWordFromTwoHalfwords(u16 *, u32 *);
int CountTrailingZeroBits(u32 value);
u16 CalcCRC16(const u8 *data, s32 length);
u16 CalcCRC16WithTable(const u8 *data, u32 length);
u32 CalcByteArraySum(const u8* data, u32 length);
void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor);
void DoBgAffineSet(struct BgAffineDstData *dest, u32 texX, u32 texY, s16 scrX, s16 scrY, s16 sx, s16 sy, u16 alpha);
void CopySpriteTiles(u8 shape, u8 size, u8 *tiles, u16 *tilemap, u8 *output);

#endif // GUARD_UTIL_H


code:
#ifndef GUARD_WALDA_PHRASE_H
#define GUARD_WALDA_PHRASE_H

u16 TryBufferWaldaPhrase(void);
void DoWaldaNamingScreen(void);
u16 TryGetWallpaperWithWaldaPhrase(void);

#endif // GUARD_WALDA_PHRASE_H


code:
#ifndef GUARD_WALLCLOCK_H
#define GUARD_WALLCLOCK_H

void CB2_StartWallClock(void);
void CB2_ViewWallClock(void);

#endif //GUARD_WALLCLOCK_H


code:
#ifndef GUARD_WILD_ENCOUNTER_H
#define GUARD_WILD_ENCOUNTER_H

#define LAND_WILD_COUNT     12
#define WATER_WILD_COUNT    5
#define ROCK_WILD_COUNT     5
#define FISH_WILD_COUNT     10

struct WildPokemon
{
    u8 minLevel;
    u8 maxLevel;
    u16 species;
};

struct WildPokemonInfo
{
    u8 encounterRate;
    const struct WildPokemon *wildPokemon;
};

struct WildPokemonHeader
{
    u8 mapGroup;
    u8 mapNum;
    const struct WildPokemonInfo *landMonsInfo;
    const struct WildPokemonInfo *waterMonsInfo;
    const struct WildPokemonInfo *rockSmashMonsInfo;
    const struct WildPokemonInfo *fishingMonsInfo;
};

extern const struct WildPokemonHeader gWildMonHeaders[];

void DisableWildEncounters(bool8 disabled);
bool8 StandardWildEncounter(u16 currMetaTileBehavior, u16 previousMetaTileBehavior);
void ScrSpecial_RockSmashWildEncounter(void);
bool8 SweetScentWildEncounter(void);
bool8 DoesCurrentMapHaveFishingMons(void);
void FishingWildEncounter(u8 rod);
u16 GetLocalWildMon(bool8 *isWaterMon);
u16 GetLocalWaterMon(void);
bool8 UpdateRepelCounter(void);

#endif // GUARD_WILD_ENCOUNTER_H


code:
# JSON files are run through jsonproc, which is a tool that converts JSON data to an output file
# based on an Inja template. https://github.com/pantor/inja

AUTO_GEN_TARGETS += $(DATA_SRC_SUBDIR)/wild_encounters.h
$(DATA_SRC_SUBDIR)/wild_encounters.h: $(DATA_SRC_SUBDIR)/wild_encounters.json $(DATA_SRC_SUBDIR)/wild_encounters.json.txt
	$(JSONPROC) $^ $@

$(C_BUILDDIR)/wild_encounter.o: c_dep += $(DATA_SRC_SUBDIR)/wild_encounters.h


code:
ENTRY(Start)

gNumMusicPlayers = 4;
gMaxLines = 0;

/* Modify the following load addresses as needed to make more room. Alternately, delete both the
   declarations below and their references further down to get rid of the gaps.                  */

__anim_mon_load_address = 0x8b00000;
__gfx_load_address = 0x8c00000;

SECTIONS {
    . = 0x2000000;

    ewram (NOLOAD) :
    ALIGN(4)
    {
        gHeap = .;

        . = 0x1C000;

        INCLUDE "sym_ewram.ld"

        . = 0x40000;
}

    . = 0x3000000;

    iwram (NOLOAD) :
    ALIGN(4)
    {
        /* .bss starts at 0x3000000 */
        INCLUDE "sym_bss.ld"

        /* .bss.code starts at 0x3001AA8 */
        src/m4a.o(.bss.code);

        /* COMMON starts at 0x30022A8 */
        INCLUDE "sym_common.ld"
        *libc.a:sbrkr.o(COMMON);
        end = .;
        . = 0x8000;
    }

    . = 0x8000000;

    .text :
    ALIGN(4)
    {
        src/crt0.o(.text);
        src/main.o(.text);
        gflib/malloc.o(.text);
        gflib/dma3_manager.o(.text);
        gflib/gpu_regs.o(.text);
        gflib/bg.o(.text);
        gflib/blit.o(.text);
        gflib/window.o(.text);
        gflib/text.o(.text);
        gflib/sprite.o(.text);
        gflib/string_util.o(.text);
        src/link.o(.text);
        src/AgbRfu_LinkManager.o(.text);
        src/link_rfu_3.o(.text);
        src/link_rfu_2.o(.text);
        src/union_room.o(.text);
        src/mystery_gift.o(.text);
        src/union_room_player_avatar.o(.text);
        src/wireless_communication_status_screen.o(.text);
        src/union_room_battle.o(.text);
        src/mevent2.o(.text);
        src/mevent_801BAAC.o(.text);
        src/mevent_server.o(.text);
        src/mevent_client.o(.text);
        src/mevent_server_helpers.o(.text);
        src/mevent_news.o(.text);
        src/union_room_chat.o(.text);
        src/berry_crush.o(.text);
        src/berry_powder.o(.text);
        src/dodrio_berry_picking.o(.text);
        src/pokemon_jump.o(.text);
        src/minigame_countdown.o(.text);
        src/rtc.o(.text);
        src/main_menu.o(.text);
        src/battle_controllers.o(.text);
        src/decompress.o(.text);
        src/digit_obj_util.o(.text);
        src/battle_bg.o(.text);
        src/battle_main.o(.text);
        src/battle_util.o(.text);
        src/battle_script_commands.o(.text);
        src/battle_util2.o(.text);
        src/battle_controller_player.o(.text);
        src/battle_gfx_sfx_util.o(.text);
        src/battle_controller_opponent.o(.text);
        src/battle_ai_switch_items.o(.text);
        src/battle_controller_link_opponent.o(.text);
        src/pokemon.o(.text);
        src/trig.o(.text);
        src/random.o(.text);
        src/util.o(.text);
        src/daycare.o(.text);
        src/egg_hatch.o(.text);
        src/battle_interface.o(.text);
        src/battle_anim_smokescreen.o(.text);
        src/pokeball.o(.text);
        src/load_save.o(.text);
        src/trade.o(.text);
        src/berry_blender.o(.text);
        src/play_time.o(.text);
        src/new_game.o(.text);
        src/overworld.o(.text);
        src/fieldmap.o(.text);
        src/metatile_behavior.o(.text);
        src/field_camera.o(.text);
        src/field_door.o(.text);
        src/field_player_avatar.o(.text);
        src/event_object_movement.o(.text);
        src/field_message_box.o(.text);
        src/event_object_lock.o(.text);
        src/text_window.o(.text);
        src/script.o(.text);
        src/scrcmd.o(.text);
        src/field_control_avatar.o(.text);
        src/event_data.o(.text);
        src/coord_event_weather.o(.text);
        src/field_tasks.o(.text);
        src/clock.o(.text);
        src/reset_rtc_screen.o(.text);
        src/start_menu.o(.text);
        src/tileset_anims.o(.text);
        src/palette.o(.text);
        src/sound.o(.text);
        src/battle_anim.o(.text);
        src/battle_anim_mons.o(.text);
        src/task.o(.text);
        src/reshow_battle_screen.o(.text);
        src/battle_anim_status_effects.o(.text);
        src/title_screen.o(.text);
        src/field_weather.o(.text);
        src/field_weather_effect.o(.text);
        src/field_screen_effect.o(.text);
        src/battle_setup.o(.text);
        src/cable_club.o(.text);
        src/trainer_see.o(.text);
        src/wild_encounter.o(.text);
        src/field_effect.o(.text);
        src/scanline_effect.o(.text);
        src/option_menu.o(.text);
        src/pokedex.o(.text);
        src/trainer_card.o(.text);
        src/frontier_pass.o(.text);
        src/pokemon_storage_system.o(.text);
        src/pokemon_icon.o(.text);
        src/script_movement.o(.text);
        src/fldeff_cut.o(.text);
        src/mail_data.o(.text);
        src/map_name_popup.o(.text);
        src/item_menu_icons.o(.text);
        src/battle_anim_mon_movement.o(.text);
        src/item.o(.text);
        src/contest.o(.text);
        src/shop.o(.text);
        src/fldeff_escalator.o(.text);
        src/berry.o(.text);
        src/script_menu.o(.text);
        src/naming_screen.o(.text);
        src/money.o(.text);
        src/contest_effect.o(.text);
        src/record_mixing.o(.text);
        src/secret_base.o(.text);
        src/tv.o(.text);
        src/contest_util.o(.text);
        src/script_pokemon_util.o(.text);
        src/field_poison.o(.text);
        src/pokemon_size_record.o(.text);
        src/fldeff_misc.o(.text);
        src/field_special_scene.o(.text);
        src/rotating_gate.o(.text);
        src/safari_zone.o(.text);
        src/contest_link.o(.text);
        src/item_use.o(.text);
        src/battle_anim_effects_1.o(.text);
        src/battle_anim_effects_2.o(.text);
        src/battle_anim_water.o(.text);
        src/battle_anim_fire.o(.text);
        src/battle_anim_electric.o(.text);
        src/battle_anim_ice.o(.text);
        src/battle_anim_fight.o(.text);
        src/battle_anim_poison.o(.text);
        src/battle_anim_flying.o(.text);
        src/battle_anim_psychic.o(.text);
        src/battle_anim_bug.o(.text);
        src/battle_anim_rock.o(.text);
        src/battle_anim_ghost.o(.text);
        src/battle_anim_dragon.o(.text);
        src/battle_anim_dark.o(.text);
        src/battle_anim_ground.o(.text);
        src/battle_anim_normal.o(.text);
        src/battle_anim_utility_funcs.o(.text);
        src/battle_intro.o(.text);
        src/bike.o(.text);
        src/easy_chat.o(.text);
        src/mon_markings.o(.text);
        src/mauville_old_man.o(.text);
        src/mail.o(.text);
        src/menu_helpers.o(.text);
        src/dewford_trend.o(.text);
        src/heal_location.o(.text);
        src/region_map.o(.text);
        src/image_processing_effects.o(.text);
        src/decoration.o(.text);
        src/slot_machine.o(.text);
        src/contest_painting.o(.text);
        src/battle_ai_script_commands.o(.text);
        src/trader.o(.text);
        src/starter_choose.o(.text);
        src/wallclock.o(.text);
        src/fldeff_rocksmash.o(.text);
        src/fldeff_dig.o(.text);
        src/pokeblock.o(.text);
        src/fldeff_flash.o(.text);
        src/post_battle_event_funcs.o(.text);
        src/time_events.o(.text);
        src/birch_pc.o(.text);
        src/hof_pc.o(.text);
        src/field_specials.o(.text);
        src/battle_records.o(.text);
        src/pokedex_area_screen.o(.text);
        src/evolution_scene.o(.text);
        src/roulette.o(.text);
        src/pokedex_cry_screen.o(.text);
        src/coins.o(.text);
        src/landmark.o(.text);
        src/fldeff_strength.o(.text);
        src/battle_transition.o(.text);
        src/battle_controller_link_partner.o(.text);
        src/battle_message.o(.text);
        src/cable_car.o(.text);
        src/math_util.o(.text);
        src/palette_util.o(.text);
        src/confetti_util.o(.text);
        src/save.o(.text);
        src/mystery_event_script.o(.text);
        src/field_effect_helpers.o(.text);
        src/contest_ai.o(.text);
        src/battle_anim_sound_tasks.o(.text);
        src/battle_controller_safari.o(.text);
        src/fldeff_sweetscent.o(.text);
        src/battle_anim_effects_3.o(.text);
        src/move_relearner.o(.text);
        src/fldeff_softboiled.o(.text);
        src/decoration_inventory.o(.text);
        src/roamer.o(.text);
        src/battle_tower.o(.text);
        src/use_pokeblock.o(.text);
        src/battle_controller_wally.o(.text);
        src/player_pc.o(.text);
        src/intro.o(.text);
        src/reset_save_heap.o(.text);
        src/field_region_map.o(.text);
        src/battle_anim_throw.o(.text);
        src/hall_of_fame.o(.text);
        src/credits.o(.text);
        src/lottery_corner.o(.text);
        src/diploma.o(.text);
        src/berry_tag_screen.o(.text);
        src/mystery_event_menu.o(.text);
        src/save_failed_screen.o(.text);
        src/braille_puzzles.o(.text);
        src/pokeblock_feed.o(.text);
        src/clear_save_data_screen.o(.text);
        src/intro_credits_graphics.o(.text);
        src/evolution_graphics.o(.text);
        src/bard_music.o(.text);
        src/fldeff_teleport.o(.text);
        src/battle_tv.o(.text);
        src/pokemon_animation.o(.text);
        src/recorded_battle.o(.text);
        src/battle_controller_recorded_opponent.o(.text);
        src/battle_controller_recorded_player.o(.text);
        src/trainer_pokemon_sprites.o(.text);
        src/lilycove_lady.o(.text);
        src/battle_dome.o(.text);
        src/battle_palace.o(.text);
        src/match_call.o(.text);
        src/menu.o(.text);
        src/battle_factory_screen.o(.text);
        src/apprentice.o(.text);
        src/frontier_util.o(.text);
        src/battle_arena.o(.text);
        src/battle_factory.o(.text);
        src/battle_pike.o(.text);
        src/rotating_tile_puzzle.o(.text);
        src/battle_pyramid.o(.text);
        src/item_menu.o(.text);
        src/list_menu.o(.text);
        src/dynamic_placeholder_text_util.o(.text);
        src/save_location.o(.text);
        src/item_icon.o(.text);
        src/party_menu.o(.text);
        src/battle_tent.o(.text);
        src/unk_text_util_2.o(.text);
        src/multiboot.o(.text);
        src/battle_controller_player_partner.o(.text);
        src/mirage_tower.o(.text);
        src/pokemon_summary_screen.o(.text);
        src/pokedex_area_region_map.o(.text);
        src/battle_pyramid_bag.o(.text);
        src/pokenav.o(.text);
        src/pokenav_main_menu.o(.text);
        src/pokenav_match_call_ui.o(.text);
        src/pokenav_menu_handler_1.o(.text);
        src/pokenav_menu_handler_2.o(.text);
        src/pokenav_match_call_1.o(.text);
        src/pokenav_match_call_2.o(.text);
        src/pokenav_region_map.o(.text);
        src/pokenav_conditions_1.o(.text);
        src/pokenav_conditions_2.o(.text);
        src/pokenav_conditions_3.o(.text);
        src/pokenav_ribbons_1.o(.text);
        src/pokenav_ribbons_2.o(.text);
        src/pokenav_match_call_data.o(.text);
        src/menu_specialized.o(.text);
        src/ereader_helpers.o(.text);
        src/faraway_island.o(.text);
        src/ereader_screen.o(.text);
        src/trainer_hill.o(.text);
        src/rayquaza_scene.o(.text);
        src/walda_phrase.o(.text);
        src/contest_link_util.o(.text);
        src/gym_leader_rematch.o(.text);
        src/battle_transition_frontier.o(.text);
        src/international_string_util.o(.text);
    } =0

    script_data :
    ALIGN(4)
    {
        data/event_scripts.o(script_data);
        data/battle_anim_scripts.o(script_data);
        data/battle_scripts_1.o(script_data);
        data/field_effect_scripts.o(script_data);
        data/battle_scripts_2.o(script_data);
        data/battle_ai_scripts.o(script_data);
        data/contest_ai_scripts.o(script_data);
        data/mystery_event_script_cmd_table.o(script_data);
    } =0

    lib_text :
    ALIGN(4)
    {
        src/libgcnmultiboot.o(.text);
        src/m4a_1.o(.text);
        src/m4a.o(.text);
        src/agb_flash.o(.text);
        src/agb_flash_1m.o(.text);
        src/agb_flash_mx.o(.text);
        src/siirtc.o(.text);
        src/librfu_stwi.o(.text);
        src/librfu_intr.o(.text);
        src/librfu_rfu.o(.text);
        src/librfu_sio32id.o(.text);
        src/libisagbprn.o(.text);
        *libagbsyscall.a:ArcTan2.o(.text);
        *libagbsyscall.a:BgAffineSet.o(.text);
        *libagbsyscall.a:CpuFastSet.o(.text);
        *libagbsyscall.a:CpuSet.o(.text);
        *libagbsyscall.a:Div.o(.text);
        *libagbsyscall.a:LZ77UnCompVram.o(.text);
        *libagbsyscall.a:LZ77UnCompWram.o(.text);
        *libagbsyscall.a:MultiBoot.o(.text);
        *libagbsyscall.a:ObjAffineSet.o(.text);
        *libagbsyscall.a:RLUnCompVram.o(.text);
        *libagbsyscall.a:RLUnCompWram.o(.text);
        *libagbsyscall.a:RegisterRamReset.o(.text);
        *libagbsyscall.a:SoftReset.o(.text);
        *libagbsyscall.a:Sqrt.o(.text);
        *libagbsyscall.a:VBlankIntrWait.o(.text);
        *libgcc.a:_call_via_rX.o(.text);
        *libgcc.a:_divdi3.o(.text);
        *libgcc.a:_divsi3.o(.text);
        *libgcc.a:_dvmd_tls.o(.text);
        *libgcc.a:_fixunsdfsi.o(.text);
        *libgcc.a:_fixunssfsi.o(.text);
        *libgcc.a:_modsi3.o(.text);
        *libgcc.a:_muldi3.o(.text);
        *libgcc.a:_udivdi3.o(.text);
        *libgcc.a:_udivsi3.o(.text);
        *libgcc.a:_umodsi3.o(.text);
        *libgcc.a:dp-bit.o(.text);
        *libgcc.a:fp-bit.o(.text);
        *libgcc.a:_lshrdi3.o(.text);
        *libgcc.a:_negdi2.o(.text);
        *libc.a:memcpy.o(.text);
        *libc.a:memset.o(.text);
        *libc.a:strcmp.o(.text);
        *libc.a:strcpy.o(.text);
        *libc.a:impure.o(.text);
        *libc.a:vsprintf.o(.text);
        *libc.a:vfprintf.o(.text);
        *libc.a:wsetup.o(.text);
        *libc.a:dtoa.o(.text);
        *libc.a:fflush.o(.text);
        *libc.a:findfp.o(.text);
        *libc.a:freer.o(.text);
        *libc.a:mtrim.o(.text);
        *libc.a:fvwrite.o(.text);
        *libc.a:fwalk.o(.text);
        *libc.a:locale.o(.text);
        *libc.a:makebuf.o(.text);
        *libc.a:mallocr.o(.text);
        *libc.a:mbtowc_r.o(.text);
        *libc.a:memchr.o(.text);
        *libc.a:memmove.o(.text);
        *libc.a:mlock.o(.text);
        *libc.a:mprec.o(.text);
        *libc.a:s_isinf.o(.text);
        *libc.a:s_isnan.o(.text);
        *libc.a:sbrkr.o(.text);
        *libc.a:stdio.o(.text);
        *libc.a:strlen.o(.text);
        *libc.a:syscalls.o(.text);
        *libc.a:writer.o(.text);
        *libc.a:callocr.o(.text);
        *libc.a:closer.o(.text);
        *libc.a:errno.o(.text);
        *libc.a:fstatr.o(.text);
        *libc.a:libcfunc.o(.text);
        *libc.a:lseekr.o(.text);
        *libc.a:readr.o(.text);
    } =0

    .rodata :
    ALIGN(4)
    {
        src/main.o(.rodata);
        gflib/bg.o(.rodata);
        gflib/window.o(.rodata);
        gflib/text.o(.rodata);
        gflib/sprite.o(.rodata);
        gflib/io_reg.o(.rodata);
        gflib/string_util.o(.rodata);
        src/link.o(.rodata);
        src/link.o(.rodata.str1.4);
        src/AgbRfu_LinkManager.o(.rodata);
        src/link_rfu_3.o(.rodata);
        src/link_rfu_2.o(.rodata);
        src/link_rfu_2.o(.rodata.str1.4);
        src/union_room.o(.rodata);
        src/mystery_gift.o(.rodata);
        src/union_room_player_avatar.o(.rodata);
        src/wireless_communication_status_screen.o(.rodata);
        src/union_room_battle.o(.rodata);
        src/mevent2.o(.rodata);
        src/mevent_801BAAC.o(.rodata);
        src/mevent_server.o(.rodata);
        src/mevent_client.o(.rodata);
        src/mevent_scripts.o(.rodata);
        src/union_room_chat.o(.rodata);
        src/berry_crush.o(.rodata);
        src/berry_powder.o(.rodata);
        src/dodrio_berry_picking.o(.rodata);
        src/pokemon_jump.o(.rodata);
        src/minigame_countdown.o(.rodata);
        src/rtc.o(.rodata);
        src/main_menu.o(.rodata);
        src/battle_controllers.o(.rodata);
        src/digit_obj_util.o(.rodata);
        src/data.o(.rodata);
        src/battle_bg.o(.rodata);
        src/battle_main.o(.rodata);
        src/battle_util.o(.rodata);
        src/battle_script_commands.o(.rodata);
        src/battle_controller_player.o(.rodata);
        src/battle_anim_smokescreen.o(.rodata);
        src/battle_controller_opponent.o(.rodata);
        src/battle_ai_switch_items.o(.rodata);
        src/battle_controller_link_opponent.o(.rodata);
        src/pokemon.o(.rodata);
        src/trig.o(.rodata);
        src/util.o(.rodata);
        src/daycare.o(.rodata);
        src/egg_hatch.o(.rodata);
        src/battle_gfx_sfx_util.o(.rodata);
        src/battle_interface.o(.rodata);
        src/pokeball.o(.rodata);
        src/trade.o(.rodata);
        src/berry_blender.o(.rodata);
        src/new_game.o(.rodata);
        src/overworld.o(.rodata);
        data/tilesets.o(.rodata);
        data/maps.o(.rodata);
        src/fieldmap.o(.rodata);
        src/metatile_behavior.o(.rodata);
        src/field_door.o(.rodata);
        src/field_player_avatar.o(.rodata);
        src/event_object_movement.o(.rodata);
        src/text_window.o(.rodata);
        src/scrcmd.o(.rodata);
        src/field_control_avatar.o(.rodata);
        src/coord_event_weather.o(.rodata);
        src/field_tasks.o(.rodata);
        src/reset_rtc_screen.o(.rodata);
        src/start_menu.o(.rodata);
        src/tileset_anims.o(.rodata);
        src/palette.o(.rodata);
        src/sound.o(.rodata);
        src/battle_anim.o(.rodata);
        src/battle_anim_mons.o(.rodata);
        data/map_events.o(.rodata);
        src/reshow_battle_screen.o(.rodata);
        src/battle_anim_status_effects.o(.rodata);
        src/title_screen.o(.rodata);
        src/field_weather.o(.rodata);
        src/field_weather_effect.o(.rodata);
        src/field_screen_effect.o(.rodata);
        src/battle_setup.o(.rodata);
        src/cable_club.o(.rodata);
        src/trainer_see.o(.rodata);
        src/wild_encounter.o(.rodata);
        src/field_effect.o(.rodata);
        src/scanline_effect.o(.rodata);
        src/option_menu.o(.rodata);
        src/pokedex.o(.rodata);
        src/trainer_card.o(.rodata);
        src/frontier_pass.o(.rodata);
        src/pokemon_storage_system.o(.rodata);
        src/pokemon_icon.o(.rodata);
        src/fldeff_cut.o(.rodata);
        src/map_name_popup.o(.rodata);
        src/item_menu_icons.o(.rodata);
        src/battle_anim_mon_movement.o(.rodata);
        src/item.o(.rodata);
        src/contest.o(.rodata);
        src/shop.o(.rodata);
        src/fldeff_escalator.o(.rodata);
        src/berry.o(.rodata);
        src/script_menu.o(.rodata);
        src/naming_screen.o(.rodata);
        src/money.o(.rodata);
        src/contest_effect.o(.rodata);
        src/record_mixing.o(.rodata);
        src/secret_base.o(.rodata);
        src/tv.o(.rodata);
        src/contest_util.o(.rodata);
        src/script_pokemon_util.o(.rodata);
        src/pokemon_size_record.o(.rodata)
        src/fldeff_misc.o(.rodata);
        src/field_special_scene.o(.rodata);
        src/rotating_gate.o(.rodata);
        src/contest_link.o(.rodata);
        src/item_use.o(.rodata);
        src/battle_anim_effects_1.o(.rodata);
        src/battle_anim_effects_2.o(.rodata);
        src/battle_anim_water.o(.rodata);
        src/battle_anim_fire.o(.rodata);
        src/battle_anim_electric.o(.rodata);
        src/battle_anim_ice.o(.rodata);
        src/battle_anim_fight.o(.rodata);
        src/battle_anim_poison.o(.rodata);
        src/battle_anim_flying.o(.rodata);
        src/battle_anim_psychic.o(.rodata);
        src/battle_anim_bug.o(.rodata);
        src/battle_anim_rock.o(.rodata);
        src/battle_anim_ghost.o(.rodata);
        src/battle_anim_dragon.o(.rodata);
        src/battle_anim_dark.o(.rodata);
        src/battle_anim_ground.o(.rodata);
        src/battle_anim_normal.o(.rodata);
        src/battle_anim_utility_funcs.o(.rodata);
        src/battle_intro.o(.rodata);
        src/bike.o(.rodata);
        src/easy_chat.o(.rodata);
        src/mon_markings.o(.rodata);
        src/mauville_old_man.o(.rodata);
        src/mail.o(.rodata);
        src/menu_helpers.o(.rodata);
        src/heal_location.o(.rodata);
        src/region_map.o(.rodata);
        src/image_processing_effects.o(.rodata);
        data/image_processing_effects.o(.rodata);
        src/decoration.o(.rodata);
        src/slot_machine.o(.rodata);
        src/contest_painting.o(.rodata);
        src/battle_ai_script_commands.o(.rodata);
        src/trader.o(.rodata);
        src/starter_choose.o(.rodata);
        src/wallclock.o(.rodata);
        src/pokeblock.o(.rodata);
        src/fldeff_flash.o(.rodata);
        src/time_events.o(.rodata);
        src/field_specials.o(.rodata);
        src/battle_records.o(.rodata);
        src/pokedex_area_screen.o(.rodata);
        src/evolution_scene.o(.rodata);
        src/roulette.o(.rodata);
        src/pokedex_cry_screen.o(.rodata);
        src/landmark.o(.rodata);
        src/battle_transition.o(.rodata);
        src/battle_controller_link_partner.o(.rodata);
        src/battle_message.o(.rodata);
        src/cable_car.o(.rodata);
        src/save.o(.rodata);
        src/field_effect_helpers.o(.rodata);
        src/contest_ai.o(.rodata);
        src/battle_anim_sound_tasks.o(.rodata);
        src/battle_controller_safari.o(.rodata);
        src/battle_anim_effects_3.o(.rodata);
        src/move_relearner.o(.rodata);
        src/roamer.o(.rodata);
        src/battle_tower.o(.rodata);
        src/use_pokeblock.o(.rodata);
        src/battle_controller_wally.o(.rodata);
        src/player_pc.o(.rodata);
        src/intro.o(.rodata);
        src/field_region_map.o(.rodata);
        src/battle_anim_throw.o(.rodata);
        src/hall_of_fame.o(.rodata);
        src/credits.o(.rodata);
        src/lottery_corner.o(.rodata);
        src/diploma.o(.rodata);
        src/strings.o(.rodata);
        src/berry_tag_screen.o(.rodata);
        src/mystery_event_menu.o(.rodata);
        src/save_failed_screen.o(.rodata);
        src/braille_puzzles.o(.rodata);
        src/pokeblock_feed.o(.rodata);
        src/clear_save_data_screen.o(.rodata);
        src/intro_credits_graphics.o(.rodata);
        src/evolution_graphics.o(.rodata);
        src/bard_music.o(.rodata);
        src/battle_tv.o(.rodata);
        src/pokemon_animation.o(.rodata);
        src/battle_controller_recorded_opponent.o(.rodata);
        src/battle_controller_recorded_player.o(.rodata);
        src/trainer_pokemon_sprites.o(.rodata);
        src/lilycove_lady.o(.rodata);
        src/battle_dome.o(.rodata);
        src/battle_palace.o(.rodata);
        src/match_call.o(.rodata);
        src/menu.o(.rodata);
        src/battle_factory_screen.o(.rodata);
        src/apprentice.o(.rodata);
        src/frontier_util.o(.rodata);
        src/battle_arena.o(.rodata);
        src/battle_factory.o(.rodata);
        src/battle_pike.o(.rodata);
        src/rotating_tile_puzzle.o(.rodata);
        src/battle_pyramid.o(.rodata);
        src/item_menu.o(.rodata);
        src/list_menu.o(.rodata);
        src/save_location.o(.rodata);
        src/item_icon.o(.rodata);
        src/party_menu.o(.rodata);
        src/battle_tent.o(.rodata);
        src/unk_text_util_2.o(.rodata);
        src/multiboot.o(.rodata);
        src/battle_controller_player_partner.o(.rodata);
        src/mirage_tower.o(.rodata);
        src/pokemon_summary_screen.o(.rodata);
        src/pokedex_area_region_map.o(.rodata);
        src/battle_pyramid_bag.o(.rodata);
        src/pokenav.o(.rodata);
        src/pokenav_main_menu.o(.rodata);
        src/pokenav_match_call_ui.o(.rodata);
        src/pokenav_menu_handler_1.o(.rodata);
        src/pokenav_menu_handler_2.o(.rodata);
        src/pokenav_match_call_1.o(.rodata);
        src/pokenav_match_call_2.o(.rodata);
        src/pokenav_region_map.o(.rodata);
        src/pokenav_conditions_2.o(.rodata);
        src/pokenav_conditions_3.o(.rodata);
        src/pokenav_ribbons_1.o(.rodata);
        src/pokenav_ribbons_2.o(.rodata);
        src/pokenav_match_call_data.o(.rodata);
        src/menu_specialized.o(.rodata);
        src/ereader_helpers.o(.rodata);
        src/faraway_island.o(.rodata);
        src/ereader_screen.o(.rodata);
        src/trainer_hill.o(.rodata);
        src/rayquaza_scene.o(.rodata);
        src/walda_phrase.o(.rodata);
        src/gym_leader_rematch.o(.rodata);
        src/battle_transition_frontier.o(.rodata);
        src/text_input_strings.o(.rodata);
        data/fonts.o(.rodata);
        src/mystery_event_msg.o(.rodata);
        data/mystery_event.o(.rodata);
        src/m4a_tables.o(.rodata);
        data/sound_data.o(.rodata);
    } =0

    song_data :
    ALIGN(4)
    {
        sound/songs/midi/mus_dummy.o(.rodata);
        sound/songs/midi/se_use_item.o(.rodata);
        sound/songs/midi/se_pc_login.o(.rodata);
        sound/songs/midi/se_pc_off.o(.rodata);
        sound/songs/midi/se_pc_on.o(.rodata);
        sound/songs/midi/se_select.o(.rodata);
        sound/songs/se_win_open.o(.rodata);
        sound/songs/se_wall_hit.o(.rodata);
        sound/songs/midi/se_door.o(.rodata);
        sound/songs/midi/se_exit.o(.rodata);
        sound/songs/midi/se_ledge.o(.rodata);
        sound/songs/midi/se_bike_bell.o(.rodata);
        sound/songs/midi/se_not_effective.o(.rodata);
        sound/songs/midi/se_effective.o(.rodata);
        sound/songs/midi/se_super_effective.o(.rodata);
        sound/songs/midi/se_ball_open.o(.rodata);
        sound/songs/midi/se_faint.o(.rodata);
        sound/songs/midi/se_flee.o(.rodata);
        sound/songs/midi/se_sliding_door.o(.rodata);
        sound/songs/midi/se_ship.o(.rodata);
        sound/songs/midi/se_bang.o(.rodata);
        sound/songs/midi/se_pin.o(.rodata);
        sound/songs/midi/se_boo.o(.rodata);
        sound/songs/midi/se_ball.o(.rodata);
        sound/songs/midi/se_contest_place.o(.rodata);
        sound/songs/midi/se_a.o(.rodata);
        sound/songs/midi/se_i.o(.rodata);
        sound/songs/midi/se_u.o(.rodata);
        sound/songs/midi/se_e.o(.rodata);
        sound/songs/midi/se_o.o(.rodata);
        sound/songs/midi/se_n.o(.rodata);
        sound/songs/midi/se_success.o(.rodata);
        sound/songs/midi/se_failure.o(.rodata);
        sound/songs/midi/se_exp.o(.rodata);
        sound/songs/midi/se_bike_hop.o(.rodata);
        sound/songs/midi/se_switch.o(.rodata);
        sound/songs/midi/se_click.o(.rodata);
        sound/songs/midi/se_fu_zaku.o(.rodata);
        sound/songs/midi/se_contest_condition_lose.o(.rodata);
        sound/songs/midi/se_lavaridge_fall_warp.o(.rodata);
        sound/songs/midi/se_ice_stairs.o(.rodata);
        sound/songs/midi/se_ice_break.o(.rodata);
        sound/songs/midi/se_ice_crack.o(.rodata);
        sound/songs/midi/se_fall.o(.rodata);
        sound/songs/midi/se_unlock.o(.rodata);
        sound/songs/midi/se_warp_in.o(.rodata);
        sound/songs/midi/se_warp_out.o(.rodata);
        sound/songs/midi/se_repel.o(.rodata);
        sound/songs/midi/se_rotating_gate.o(.rodata);
        sound/songs/midi/se_truck_move.o(.rodata);
        sound/songs/midi/se_truck_stop.o(.rodata);
        sound/songs/midi/se_truck_unload.o(.rodata);
        sound/songs/midi/se_truck_door.o(.rodata);
        sound/songs/midi/se_berry_blender.o(.rodata);
        sound/songs/midi/se_card.o(.rodata);
        sound/songs/midi/se_save.o(.rodata);
        sound/songs/midi/se_ball_bounce_1.o(.rodata);
        sound/songs/midi/se_ball_bounce_2.o(.rodata);
        sound/songs/midi/se_ball_bounce_3.o(.rodata);
        sound/songs/midi/se_ball_bounce_4.o(.rodata);
        sound/songs/midi/se_ball_trade.o(.rodata);
        sound/songs/midi/se_ball_throw.o(.rodata);
        sound/songs/midi/se_note_c.o(.rodata);
        sound/songs/midi/se_note_d.o(.rodata);
        sound/songs/midi/se_note_e.o(.rodata);
        sound/songs/midi/se_note_f.o(.rodata);
        sound/songs/midi/se_note_g.o(.rodata);
        sound/songs/midi/se_note_a.o(.rodata);
        sound/songs/midi/se_note_b.o(.rodata);
        sound/songs/midi/se_note_c_high.o(.rodata);
        sound/songs/midi/se_puddle.o(.rodata);
        sound/songs/midi/se_bridge_walk.o(.rodata);
        sound/songs/midi/se_itemfinder.o(.rodata);
        sound/songs/midi/se_ding_dong.o(.rodata);
        sound/songs/midi/se_balloon_red.o(.rodata);
        sound/songs/midi/se_balloon_blue.o(.rodata);
        sound/songs/midi/se_balloon_yellow.o(.rodata);
        sound/songs/midi/se_breakable_door.o(.rodata);
        sound/songs/midi/se_mud_ball.o(.rodata);
        sound/songs/midi/se_field_poison.o(.rodata);
        sound/songs/midi/se_escalator.o(.rodata);
        sound/songs/midi/se_thunderstorm.o(.rodata);
        sound/songs/midi/se_thunderstorm_stop.o(.rodata);
        sound/songs/midi/se_downpour.o(.rodata);
        sound/songs/midi/se_downpour_stop.o(.rodata);
        sound/songs/midi/se_rain.o(.rodata);
        sound/songs/midi/se_rain_stop.o(.rodata);
        sound/songs/midi/se_thunder.o(.rodata);
        sound/songs/midi/se_thunder2.o(.rodata);
        sound/songs/midi/se_elevator.o(.rodata);
        sound/songs/midi/se_low_health.o(.rodata);
        sound/songs/midi/se_exp_max.o(.rodata);
        sound/songs/midi/se_roulette_ball.o(.rodata);
        sound/songs/midi/se_roulette_ball2.o(.rodata);
        sound/songs/midi/se_taillow_wing_flap.o(.rodata);
        sound/songs/midi/se_shop.o(.rodata);
        sound/songs/midi/se_contest_heart.o(.rodata);
        sound/songs/midi/se_contest_curtain_rise.o(.rodata);
        sound/songs/midi/se_contest_curtain_fall.o(.rodata);
        sound/songs/midi/se_contest_icon_change.o(.rodata);
        sound/songs/midi/se_contest_icon_clear.o(.rodata);
        sound/songs/midi/se_contest_mons_turn.o(.rodata);
        sound/songs/midi/se_shiny.o(.rodata);
        sound/songs/midi/se_intro_blast.o(.rodata);
        sound/songs/midi/se_mugshot.o(.rodata);
        sound/songs/midi/se_applause.o(.rodata);
        sound/songs/midi/se_vend.o(.rodata);
        sound/songs/midi/se_orb.o(.rodata);
        sound/songs/se_dex_scroll.o(.rodata);
        sound/songs/se_dex_page.o(.rodata);
        sound/songs/midi/se_pokenav_on.o(.rodata);
        sound/songs/midi/se_pokenav_off.o(.rodata);
        sound/songs/midi/se_dex_search.o(.rodata);
        sound/songs/midi/se_egg_hatch.o(.rodata);
        sound/songs/midi/se_ball_tray_enter.o(.rodata);
        sound/songs/midi/se_ball_tray_ball.o(.rodata);
        sound/songs/midi/se_ball_tray_exit.o(.rodata);
        sound/songs/midi/se_glass_flute.o(.rodata);
        sound/songs/se_m_thunderbolt.o(.rodata);
        sound/songs/se_m_thunderbolt2.o(.rodata);
        sound/songs/se_m_harden.o(.rodata);
        sound/songs/se_m_nightmare.o(.rodata);
        sound/songs/se_m_vital_throw.o(.rodata);
        sound/songs/se_m_vital_throw2.o(.rodata);
        sound/songs/se_m_bubble.o(.rodata);
        sound/songs/se_m_bubble2.o(.rodata);
        sound/songs/se_m_bubble3.o(.rodata);
        sound/songs/se_m_rain_dance.o(.rodata);
        sound/songs/midi/se_m_cut.o(.rodata);
        sound/songs/se_m_string_shot.o(.rodata);
        sound/songs/se_m_string_shot2.o(.rodata);
        sound/songs/se_m_rock_throw.o(.rodata);
        sound/songs/midi/se_m_gust.o(.rodata);
        sound/songs/midi/se_m_gust2.o(.rodata);
        sound/songs/midi/se_m_double_slap.o(.rodata);
        sound/songs/se_m_double_team.o(.rodata);
        sound/songs/midi/se_m_razor_wind.o(.rodata);
        sound/songs/se_m_icy_wind.o(.rodata);
        sound/songs/se_m_thunder_wave.o(.rodata);
        sound/songs/midi/se_m_comet_punch.o(.rodata);
        sound/songs/midi/se_m_mega_kick.o(.rodata);
        sound/songs/midi/se_m_mega_kick2.o(.rodata);
        sound/songs/se_m_crabhammer.o(.rodata);
        sound/songs/midi/se_m_jump_kick.o(.rodata);
        sound/songs/se_m_flame_wheel.o(.rodata);
        sound/songs/se_m_flame_wheel2.o(.rodata);
        sound/songs/se_m_flamethrower.o(.rodata);
        sound/songs/midi/se_m_fire_punch.o(.rodata);
        sound/songs/se_m_toxic.o(.rodata);
        sound/songs/se_m_sacred_fire.o(.rodata);
        sound/songs/se_m_sacred_fire2.o(.rodata);
        sound/songs/se_m_ember.o(.rodata);
        sound/songs/midi/se_m_take_down.o(.rodata);
        sound/songs/se_m_blizzard.o(.rodata);
        sound/songs/se_m_blizzard2.o(.rodata);
        sound/songs/midi/se_m_scratch.o(.rodata);
        sound/songs/midi/se_m_vicegrip.o(.rodata);
        sound/songs/midi/se_m_wing_attack.o(.rodata);
        sound/songs/midi/se_m_fly.o(.rodata);
        sound/songs/midi/se_m_sand_attack.o(.rodata);
        sound/songs/midi/se_m_razor_wind2.o(.rodata);
        sound/songs/se_m_bite.o(.rodata);
        sound/songs/midi/se_m_headbutt.o(.rodata);
        sound/songs/se_m_surf.o(.rodata);
        sound/songs/se_m_hydro_pump.o(.rodata);
        sound/songs/se_m_whirlpool.o(.rodata);
        sound/songs/midi/se_m_horn_attack.o(.rodata);
        sound/songs/midi/se_m_tail_whip.o(.rodata);
        sound/songs/se_m_mist.o(.rodata);
        sound/songs/se_m_poison_powder.o(.rodata);
        sound/songs/midi/se_m_bind.o(.rodata);
        sound/songs/se_m_dragon_rage.o(.rodata);
        sound/songs/se_m_sing.o(.rodata);
        sound/songs/se_m_perish_song.o(.rodata);
        sound/songs/midi/se_m_pay_day.o(.rodata);
        sound/songs/se_m_dig.o(.rodata);
        sound/songs/se_m_dizzy_punch.o(.rodata);
        sound/songs/se_m_self_destruct.o(.rodata);
        sound/songs/se_m_explosion.o(.rodata);
        sound/songs/se_m_absorb_2.o(.rodata);
        sound/songs/se_m_absorb.o(.rodata);
        sound/songs/se_m_screech.o(.rodata);
        sound/songs/se_m_bubble_beam.o(.rodata);
        sound/songs/se_m_bubble_beam2.o(.rodata);
        sound/songs/se_m_supersonic.o(.rodata);
        sound/songs/se_m_belly_drum.o(.rodata);
        sound/songs/se_m_metronome.o(.rodata);
        sound/songs/se_m_bonemerang.o(.rodata);
        sound/songs/se_m_lick.o(.rodata);
        sound/songs/se_m_psybeam.o(.rodata);
        sound/songs/se_m_faint_attack.o(.rodata);
        sound/songs/midi/se_m_swords_dance.o(.rodata);
        sound/songs/midi/se_m_leer.o(.rodata);
        sound/songs/se_m_swagger.o(.rodata);
        sound/songs/se_m_swagger2.o(.rodata);
        sound/songs/se_m_heal_bell.o(.rodata);
        sound/songs/se_m_confuse_ray.o(.rodata);
        sound/songs/se_m_snore.o(.rodata);
        sound/songs/se_m_brick_break.o(.rodata);
        sound/songs/se_m_giga_drain.o(.rodata);
        sound/songs/se_m_psybeam2.o(.rodata);
        sound/songs/se_m_solar_beam.o(.rodata);
        sound/songs/se_m_petal_dance.o(.rodata);
        sound/songs/se_m_teleport.o(.rodata);
        sound/songs/se_m_minimize.o(.rodata);
        sound/songs/se_m_sketch.o(.rodata);
        sound/songs/se_m_swift.o(.rodata);
        sound/songs/se_m_reflect.o(.rodata);
        sound/songs/se_m_barrier.o(.rodata);
        sound/songs/se_m_detect.o(.rodata);
        sound/songs/se_m_lock_on.o(.rodata);
        sound/songs/se_m_moonlight.o(.rodata);
        sound/songs/se_m_charm.o(.rodata);
        sound/songs/se_m_charge.o(.rodata);
        sound/songs/se_m_strength.o(.rodata);
        sound/songs/se_m_hyper_beam.o(.rodata);
        sound/songs/se_m_waterfall.o(.rodata);
        sound/songs/se_m_reversal.o(.rodata);
        sound/songs/se_m_acid_armor.o(.rodata);
        sound/songs/se_m_sandstorm.o(.rodata);
        sound/songs/se_m_tri_attack.o(.rodata);
        sound/songs/se_m_tri_attack2.o(.rodata);
        sound/songs/se_m_encore.o(.rodata);
        sound/songs/se_m_encore2.o(.rodata);
        sound/songs/se_m_baton_pass.o(.rodata);
        sound/songs/se_m_milk_drink.o(.rodata);
        sound/songs/se_m_attract.o(.rodata);
        sound/songs/se_m_attract2.o(.rodata);
        sound/songs/se_m_morning_sun.o(.rodata);
        sound/songs/se_m_flatter.o(.rodata);
        sound/songs/se_m_sand_tomb.o(.rodata);
        sound/songs/se_m_grasswhistle.o(.rodata);
        sound/songs/se_m_spit_up.o(.rodata);
        sound/songs/se_m_dive.o(.rodata);
        sound/songs/se_m_earthquake.o(.rodata);
        sound/songs/se_m_twister.o(.rodata);
        sound/songs/se_m_sweet_scent.o(.rodata);
        sound/songs/se_m_yawn.o(.rodata);
        sound/songs/se_m_sky_uppercut.o(.rodata);
        sound/songs/se_m_stat_increase.o(.rodata);
        sound/songs/se_m_heat_wave.o(.rodata);
        sound/songs/se_m_uproar.o(.rodata);
        sound/songs/se_m_hail.o(.rodata);
        sound/songs/se_m_cosmic_power.o(.rodata);
        sound/songs/se_m_teeter_dance.o(.rodata);
        sound/songs/se_m_stat_decrease.o(.rodata);
        sound/songs/se_m_haze.o(.rodata);
        sound/songs/se_m_hyper_beam2.o(.rodata);
        sound/songs/midi/se_rg_door.o(.rodata);
        sound/songs/midi/se_rg_card_flip.o(.rodata);
        sound/songs/midi/se_rg_card_flipping.o(.rodata);
        sound/songs/midi/se_rg_card_open.o(.rodata);
        sound/songs/midi/se_rg_bag_cursor.o(.rodata);
        sound/songs/midi/se_rg_bag_pocket.o(.rodata);
        sound/songs/midi/se_rg_ball_click.o(.rodata);
        sound/songs/midi/se_rg_shop.o(.rodata);
        sound/songs/midi/se_rg_ss_anne_horn.o(.rodata);
        sound/songs/midi/se_rg_help_open.o(.rodata);
        sound/songs/midi/se_rg_help_close.o(.rodata);
        sound/songs/midi/se_rg_help_error.o(.rodata);
        sound/songs/midi/se_rg_deoxys_move.o(.rodata);
        sound/songs/midi/se_rg_poke_jump_success.o(.rodata);
        sound/songs/midi/se_rg_poke_jump_failure.o(.rodata);
        sound/songs/midi/se_pokenav_call.o(.rodata);
        sound/songs/midi/se_pokenav_hang_up.o(.rodata);
        sound/songs/midi/se_arena_timeup1.o(.rodata);
        sound/songs/midi/se_arena_timeup2.o(.rodata);
        sound/songs/midi/se_pike_curtain_close.o(.rodata);
        sound/songs/midi/se_pike_curtain_open.o(.rodata);
        sound/songs/midi/se_sudowoodo_shake.o(.rodata);
        sound/songs/midi/mus_littleroot_test.o(.rodata);
        sound/songs/midi/mus_gsc_route38.o(.rodata);
        sound/songs/midi/mus_caught.o(.rodata);
        sound/songs/midi/mus_victory_wild.o(.rodata);
        sound/songs/midi/mus_victory_gym_leader.o(.rodata);
        sound/songs/midi/mus_victory_league.o(.rodata);
        sound/songs/midi/mus_c_comm_center.o(.rodata);
        sound/songs/midi/mus_gsc_pewter.o(.rodata);
        sound/songs/midi/mus_c_vs_legend_beast.o(.rodata);
        sound/songs/midi/mus_route101.o(.rodata);
        sound/songs/midi/mus_route110.o(.rodata);
        sound/songs/midi/mus_route120.o(.rodata);
        sound/songs/midi/mus_petalburg.o(.rodata);
        sound/songs/midi/mus_oldale.o(.rodata);
        sound/songs/midi/mus_gym.o(.rodata);
        sound/songs/midi/mus_surf.o(.rodata);
        sound/songs/midi/mus_petalburg_woods.o(.rodata);
        sound/songs/midi/mus_level_up.o(.rodata);
        sound/songs/midi/mus_heal.o(.rodata);
        sound/songs/midi/mus_obtain_badge.o(.rodata);
        sound/songs/midi/mus_obtain_item.o(.rodata);
        sound/songs/midi/mus_evolved.o(.rodata);
        sound/songs/midi/mus_obtain_tmhm.o(.rodata);
        sound/songs/midi/mus_lilycove_museum.o(.rodata);
        sound/songs/midi/mus_route122.o(.rodata);
        sound/songs/midi/mus_oceanic_museum.o(.rodata);
        sound/songs/midi/mus_evolution_intro.o(.rodata);
        sound/songs/midi/mus_evolution.o(.rodata);
        sound/songs/midi/mus_move_deleted.o(.rodata);
        sound/songs/midi/mus_encounter_girl.o(.rodata);
        sound/songs/midi/mus_encounter_male.o(.rodata);
        sound/songs/midi/mus_abandoned_ship.o(.rodata);
        sound/songs/midi/mus_fortree.o(.rodata);
        sound/songs/midi/mus_birch_lab.o(.rodata);
        sound/songs/midi/mus_b_tower_rs.o(.rodata);
        sound/songs/midi/mus_encounter_swimmer.o(.rodata);
        sound/songs/midi/mus_cave_of_origin.o(.rodata);
        sound/songs/midi/mus_obtain_berry.o(.rodata);
        sound/songs/midi/mus_awaken_legend.o(.rodata);
        sound/songs/midi/mus_slots_jackpot.o(.rodata);
        sound/songs/midi/mus_slots_win.o(.rodata);
        sound/songs/midi/mus_too_bad.o(.rodata);
        sound/songs/midi/mus_roulette.o(.rodata);
        sound/songs/midi/mus_link_contest_p1.o(.rodata);
        sound/songs/midi/mus_link_contest_p2.o(.rodata);
        sound/songs/midi/mus_link_contest_p3.o(.rodata);
        sound/songs/midi/mus_link_contest_p4.o(.rodata);
        sound/songs/midi/mus_encounter_rich.o(.rodata);
        sound/songs/midi/mus_verdanturf.o(.rodata);
        sound/songs/midi/mus_rustboro.o(.rodata);
        sound/songs/midi/mus_poke_center.o(.rodata);
        sound/songs/midi/mus_route104.o(.rodata);
        sound/songs/midi/mus_route119.o(.rodata);
        sound/songs/midi/mus_cycling.o(.rodata);
        sound/songs/midi/mus_poke_mart.o(.rodata);
        sound/songs/midi/mus_littleroot.o(.rodata);
        sound/songs/midi/mus_mt_chimney.o(.rodata);
        sound/songs/midi/mus_encounter_female.o(.rodata);
        sound/songs/midi/mus_lilycove.o(.rodata);
        sound/songs/midi/mus_route111.o(.rodata);
        sound/songs/midi/mus_help.o(.rodata);
        sound/songs/midi/mus_underwater.o(.rodata);
        sound/songs/midi/mus_victory_trainer.o(.rodata);
        sound/songs/midi/mus_title.o(.rodata);
        sound/songs/midi/mus_intro.o(.rodata);
        sound/songs/midi/mus_encounter_may.o(.rodata);
        sound/songs/midi/mus_encounter_intense.o(.rodata);
        sound/songs/midi/mus_encounter_cool.o(.rodata);
        sound/songs/midi/mus_route113.o(.rodata);
        sound/songs/midi/mus_encounter_aqua.o(.rodata);
        sound/songs/midi/mus_follow_me.o(.rodata);
        sound/songs/midi/mus_encounter_brendan.o(.rodata);
        sound/songs/midi/mus_ever_grande.o(.rodata);
        sound/songs/midi/mus_encounter_suspicious.o(.rodata);
        sound/songs/midi/mus_victory_aqua_magma.o(.rodata);
        sound/songs/midi/mus_cable_car.o(.rodata);
        sound/songs/midi/mus_game_corner.o(.rodata);
        sound/songs/midi/mus_dewford.o(.rodata);
        sound/songs/midi/mus_safari_zone.o(.rodata);
        sound/songs/midi/mus_victory_road.o(.rodata);
        sound/songs/midi/mus_aqua_magma_hideout.o(.rodata);
        sound/songs/midi/mus_sailing.o(.rodata);
        sound/songs/midi/mus_mt_pyre.o(.rodata);
        sound/songs/midi/mus_slateport.o(.rodata);
        sound/songs/midi/mus_mt_pyre_exterior.o(.rodata);
        sound/songs/midi/mus_school.o(.rodata);
        sound/songs/midi/mus_hall_of_fame.o(.rodata);
        sound/songs/midi/mus_fallarbor.o(.rodata);
        sound/songs/midi/mus_sealed_chamber.o(.rodata);
        sound/songs/midi/mus_contest_winner.o(.rodata);
        sound/songs/midi/mus_contest.o(.rodata);
        sound/songs/midi/mus_encounter_magma.o(.rodata);
        sound/songs/midi/mus_intro_battle.o(.rodata);
        sound/songs/midi/mus_abnormal_weather.o(.rodata);
        sound/songs/midi/mus_weather_groudon.o(.rodata);
        sound/songs/midi/mus_sootopolis.o(.rodata);
        sound/songs/midi/mus_contest_results.o(.rodata);
        sound/songs/midi/mus_hall_of_fame_room.o(.rodata);
        sound/songs/midi/mus_trick_house.o(.rodata);
        sound/songs/midi/mus_encounter_twins.o(.rodata);
        sound/songs/midi/mus_encounter_elite_four.o(.rodata);
        sound/songs/midi/mus_encounter_hiker.o(.rodata);
        sound/songs/midi/mus_contest_lobby.o(.rodata);
        sound/songs/midi/mus_encounter_interviewer.o(.rodata);
        sound/songs/midi/mus_encounter_champion.o(.rodata);
        sound/songs/midi/mus_credits.o(.rodata);
        sound/songs/midi/mus_end.o(.rodata);
        sound/songs/midi/mus_b_frontier.o(.rodata);
        sound/songs/midi/mus_b_arena.o(.rodata);
        sound/songs/midi/mus_obtain_b_points.o(.rodata);
        sound/songs/midi/mus_register_match_call.o(.rodata);
        sound/songs/midi/mus_b_pyramid.o(.rodata);
        sound/songs/midi/mus_b_pyramid_top.o(.rodata);
        sound/songs/midi/mus_b_palace.o(.rodata);
        sound/songs/midi/mus_rayquaza_appears.o(.rodata);
        sound/songs/midi/mus_b_tower.o(.rodata);
        sound/songs/midi/mus_obtain_symbol.o(.rodata);
        sound/songs/midi/mus_b_dome.o(.rodata);
        sound/songs/midi/mus_b_pike.o(.rodata);
        sound/songs/midi/mus_b_factory.o(.rodata);
        sound/songs/midi/mus_vs_rayquaza.o(.rodata);
        sound/songs/midi/mus_vs_frontier_brain.o(.rodata);
        sound/songs/midi/mus_vs_mew.o(.rodata);
        sound/songs/midi/mus_b_dome_lobby.o(.rodata);
        sound/songs/midi/mus_vs_wild.o(.rodata);
        sound/songs/midi/mus_vs_aqua_magma.o(.rodata);
        sound/songs/midi/mus_vs_trainer.o(.rodata);
        sound/songs/midi/mus_vs_gym_leader.o(.rodata);
        sound/songs/midi/mus_vs_champion.o(.rodata);
        sound/songs/midi/mus_vs_regi.o(.rodata);
        sound/songs/midi/mus_vs_kyogre_groudon.o(.rodata);
        sound/songs/midi/mus_vs_rival.o(.rodata);
        sound/songs/midi/mus_vs_elite_four.o(.rodata);
        sound/songs/midi/mus_vs_aqua_magma_leader.o(.rodata);
        sound/songs/midi/mus_rg_follow_me.o(.rodata);
        sound/songs/midi/mus_rg_game_corner.o(.rodata);
        sound/songs/midi/mus_rg_rocket_hideout.o(.rodata);
        sound/songs/midi/mus_rg_gym.o(.rodata);
        sound/songs/midi/mus_rg_jigglypuff.o(.rodata);
        sound/songs/midi/mus_rg_intro_fight.o(.rodata);
        sound/songs/midi/mus_rg_title.o(.rodata);
        sound/songs/midi/mus_rg_cinnabar.o(.rodata);
        sound/songs/midi/mus_rg_lavender.o(.rodata);
        sound/songs/midi/mus_rg_heal.o(.rodata);
        sound/songs/midi/mus_rg_cycling.o(.rodata);
        sound/songs/midi/mus_rg_encounter_rocket.o(.rodata);
        sound/songs/midi/mus_rg_encounter_girl.o(.rodata);
        sound/songs/midi/mus_rg_encounter_boy.o(.rodata);
        sound/songs/midi/mus_rg_hall_of_fame.o(.rodata);
        sound/songs/midi/mus_rg_viridian_forest.o(.rodata);
        sound/songs/midi/mus_rg_mt_moon.o(.rodata);
        sound/songs/midi/mus_rg_poke_mansion.o(.rodata);
        sound/songs/midi/mus_rg_credits.o(.rodata);
        sound/songs/midi/mus_rg_route1.o(.rodata);
        sound/songs/midi/mus_rg_route24.o(.rodata);
        sound/songs/midi/mus_rg_route3.o(.rodata);
        sound/songs/midi/mus_rg_route11.o(.rodata);
        sound/songs/midi/mus_rg_victory_road.o(.rodata);
        sound/songs/midi/mus_rg_vs_gym_leader.o(.rodata);
        sound/songs/midi/mus_rg_vs_trainer.o(.rodata);
        sound/songs/midi/mus_rg_vs_wild.o(.rodata);
        sound/songs/midi/mus_rg_vs_champion.o(.rodata);
        sound/songs/midi/mus_rg_pallet.o(.rodata);
        sound/songs/midi/mus_rg_oak_lab.o(.rodata);
        sound/songs/midi/mus_rg_oak.o(.rodata);
        sound/songs/midi/mus_rg_poke_center.o(.rodata);
        sound/songs/midi/mus_rg_ss_anne.o(.rodata);
        sound/songs/midi/mus_rg_surf.o(.rodata);
        sound/songs/midi/mus_rg_poke_tower.o(.rodata);
        sound/songs/midi/mus_rg_silph.o(.rodata);
        sound/songs/midi/mus_rg_fuchsia.o(.rodata);
        sound/songs/midi/mus_rg_celadon.o(.rodata);
        sound/songs/midi/mus_rg_victory_trainer.o(.rodata);
        sound/songs/midi/mus_rg_victory_wild.o(.rodata);
        sound/songs/midi/mus_rg_victory_gym_leader.o(.rodata);
        sound/songs/midi/mus_rg_vermillion.o(.rodata);
        sound/songs/midi/mus_rg_pewter.o(.rodata);
        sound/songs/midi/mus_rg_encounter_rival.o(.rodata);
        sound/songs/midi/mus_rg_rival_exit.o(.rodata);
        sound/songs/midi/mus_rg_dex_rating.o(.rodata);
        sound/songs/midi/mus_rg_obtain_key_item.o(.rodata);
        sound/songs/midi/mus_rg_caught_intro.o(.rodata);
        sound/songs/midi/mus_rg_photo.o(.rodata);
        sound/songs/midi/mus_rg_game_freak.o(.rodata);
        sound/songs/midi/mus_rg_caught.o(.rodata);
        sound/songs/midi/mus_rg_new_game_instruct.o(.rodata);
        sound/songs/midi/mus_rg_new_game_intro.o(.rodata);
        sound/songs/midi/mus_rg_new_game_exit.o(.rodata);
        sound/songs/midi/mus_rg_poke_jump.o(.rodata);
        sound/songs/midi/mus_rg_union_room.o(.rodata);
        sound/songs/midi/mus_rg_net_center.o(.rodata);
        sound/songs/midi/mus_rg_mystery_gift.o(.rodata);
        sound/songs/midi/mus_rg_berry_pick.o(.rodata);
        sound/songs/midi/mus_rg_sevii_cave.o(.rodata);
        sound/songs/midi/mus_rg_teachy_tv_show.o(.rodata);
        sound/songs/midi/mus_rg_sevii_route.o(.rodata);
        sound/songs/midi/mus_rg_sevii_dungeon.o(.rodata);
        sound/songs/midi/mus_rg_sevii_123.o(.rodata);
        sound/songs/midi/mus_rg_sevii_45.o(.rodata);
        sound/songs/midi/mus_rg_sevii_67.o(.rodata);
        sound/songs/midi/mus_rg_poke_flute.o(.rodata);
        sound/songs/midi/mus_rg_vs_deoxys.o(.rodata);
        sound/songs/midi/mus_rg_vs_mewtwo.o(.rodata);
        sound/songs/midi/mus_rg_vs_legend.o(.rodata);
        sound/songs/midi/mus_rg_encounter_gym_leader.o(.rodata);
        sound/songs/midi/mus_rg_encounter_deoxys.o(.rodata);
        sound/songs/midi/mus_rg_trainer_tower.o(.rodata);
        sound/songs/midi/mus_rg_slow_pallet.o(.rodata);
        sound/songs/midi/mus_rg_teachy_tv_menu.o(.rodata);
        sound/songs/midi/ph_trap_blend.o(.rodata);
        sound/songs/midi/ph_trap_held.o(.rodata);
        sound/songs/midi/ph_trap_solo.o(.rodata);
        sound/songs/midi/ph_face_blend.o(.rodata);
        sound/songs/midi/ph_face_held.o(.rodata);
        sound/songs/midi/ph_face_solo.o(.rodata);
        sound/songs/midi/ph_cloth_blend.o(.rodata);
        sound/songs/midi/ph_cloth_held.o(.rodata);
        sound/songs/midi/ph_cloth_solo.o(.rodata);
        sound/songs/midi/ph_dress_blend.o(.rodata);
        sound/songs/midi/ph_dress_held.o(.rodata);
        sound/songs/midi/ph_dress_solo.o(.rodata);
        sound/songs/midi/ph_fleece_blend.o(.rodata);
        sound/songs/midi/ph_fleece_held.o(.rodata);
        sound/songs/midi/ph_fleece_solo.o(.rodata);
        sound/songs/midi/ph_kit_blend.o(.rodata);
        sound/songs/midi/ph_kit_held.o(.rodata);
        sound/songs/midi/ph_kit_solo.o(.rodata);
        sound/songs/midi/ph_price_blend.o(.rodata);
        sound/songs/midi/ph_price_held.o(.rodata);
        sound/songs/midi/ph_price_solo.o(.rodata);
        sound/songs/midi/ph_lot_blend.o(.rodata);
        sound/songs/midi/ph_lot_held.o(.rodata);
        sound/songs/midi/ph_lot_solo.o(.rodata);
        sound/songs/midi/ph_goat_blend.o(.rodata);
        sound/songs/midi/ph_goat_held.o(.rodata);
        sound/songs/midi/ph_goat_solo.o(.rodata);
        sound/songs/midi/ph_thought_blend.o(.rodata);
        sound/songs/midi/ph_thought_held.o(.rodata);
        sound/songs/midi/ph_thought_solo.o(.rodata);
        sound/songs/midi/ph_choice_blend.o(.rodata);
        sound/songs/midi/ph_choice_held.o(.rodata);
        sound/songs/midi/ph_choice_solo.o(.rodata);
        sound/songs/midi/ph_mouth_blend.o(.rodata);
        sound/songs/midi/ph_mouth_held.o(.rodata);
        sound/songs/midi/ph_mouth_solo.o(.rodata);
        sound/songs/midi/ph_foot_blend.o(.rodata);
        sound/songs/midi/ph_foot_held.o(.rodata);
        sound/songs/midi/ph_foot_solo.o(.rodata);
        sound/songs/midi/ph_goose_blend.o(.rodata);
        sound/songs/midi/ph_goose_held.o(.rodata);
        sound/songs/midi/ph_goose_solo.o(.rodata);
        sound/songs/midi/ph_strut_blend.o(.rodata);
        sound/songs/midi/ph_strut_held.o(.rodata);
        sound/songs/midi/ph_strut_solo.o(.rodata);
        sound/songs/midi/ph_cure_blend.o(.rodata);
        sound/songs/midi/ph_cure_held.o(.rodata);
        sound/songs/midi/ph_cure_solo.o(.rodata);
        sound/songs/midi/ph_nurse_blend.o(.rodata);
        sound/songs/midi/ph_nurse_held.o(.rodata);
        sound/songs/midi/ph_nurse_solo.o(.rodata);
    } =0

    lib_rodata :
    SUBALIGN(4)
    {
        src/m4a.o(.rodata);
        src/agb_flash.o(.rodata);
        src/agb_flash_1m.o(.rodata);
        src/agb_flash_mx.o(.rodata);
        src/agb_flash_le.o(.rodata);
        src/siirtc.o(.rodata);
        src/librfu_rfu.o(.rodata);
        src/librfu_sio32id.o(.rodata);
        *libgcc.a:_divdi3.o(.rodata);
        *libgcc.a:_udivdi3.o(.rodata);
        *libc.a(.rodata);
        *libc.a(.data);
        *libc.a:syscalls.o(.rodata);
        src/libisagbprn.o(.rodata);
    } =0

    other_data :
    ALIGN(4)
    {
        data/unknown_serial_data.o(.rodata);
        data/multiboot_pokemon_colosseum.o(.rodata);
    } =0

    anim_mon_front_pic_data __anim_mon_load_address :
    ALIGN(4)
    {
        src/anim_mon_front_pics.o(.rodata);
    } =0

    gfx_data __gfx_load_address :
    ALIGN(4)
    {
        src/graphics.o(.rodata);
    } =0

    /* DWARF debug sections.
       Symbols in the DWARF debugging sections are relative to the beginning
       of the section so we begin them at 0.  */

    /* DWARF 1 */
    .debug          0 : { *(.debug) }
    .line           0 : { *(.line) }

    /* GNU DWARF 1 extensions */
    .debug_srcinfo  0 : { *(.debug_srcinfo) }
    .debug_sfnames  0 : { *(.debug_sfnames) }

    /* DWARF 1.1 and DWARF 2 */
    .debug_aranges  0 : { *(.debug_aranges) }
    .debug_pubnames 0 : { *(.debug_pubnames) }

    /* DWARF 2 */
    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
    .debug_abbrev   0 : { *(.debug_abbrev) }
    .debug_line     0 : { *(.debug_line) }
    .debug_frame    0 : { *(.debug_frame) }
    .debug_str      0 : { *(.debug_str) }
    .debug_loc      0 : { *(.debug_loc) }
    .debug_macinfo  0 : { *(.debug_macinfo) }

    /* Discard everything not specifically mentioned above. */
    /DISCARD/ :
    {
        *(*);
    }
}


code:
ENTRY(Start)

gNumMusicPlayers = 4;
gMaxLines = 0;

SECTIONS {
    . = 0x2000000;

    ewram (NOLOAD) :
    ALIGN(4)
    {
        gHeap = .;

        . = 0x1C000;

        src/*.o(ewram_data);
        gflib/*.o(ewram_data);

        . = 0x40000;
}

    . = 0x3000000;

    iwram (NOLOAD) :
    ALIGN(4)
    {
        /* .bss starts at 0x3000000 */
        src/*.o(.bss);
        gflib/*.o(.bss);

        /* .bss.code starts at 0x3001AA8 */
        src/m4a.o(.bss.code);

        /* COMMON starts at 0x30022A8 */
        src/*.o(COMMON);
        gflib/*.o(COMMON);
        *libc.a:sbrkr.o(COMMON);
        end = .;
        . = 0x8000;
    }

    . = 0x8000000;

    .text :
    ALIGN(4)
    {
        src/crt0.o(.text);
        src/*.o(.text);
        gflib/*.o(.text);
        asm/*.o(.text);
    } =0

    script_data :
    ALIGN(4)
    {
		data/*.o(script_data);
    } =0

    lib_text :
    ALIGN(4)
    {
        src/libgcnmultiboot.o(.text);
        src/m4a_1.o(.text);
        src/m4a.o(.text);
        src/agb_flash.o(.text);
        src/agb_flash_1m.o(.text);
        src/agb_flash_mx.o(.text);
        src/siirtc.o(.text);
        src/librfu_stwi.o(.text);
        src/librfu_intr.o(.text);
        src/librfu_rfu.o(.text);
        src/librfu_sio32id.o(.text);
        *libagbsyscall.a:*.o(.text*);
        *libgcc.a:*.o(.text*);
        *libc.a:*.o(.text*);
        src/libisagbprn.o(.text);
    } =0

    .rodata :
    ALIGN(4)
    {
        src/*.o(.rodata*);
        gflib/*.o(.rodata*);
        data/*.o(.rodata*);
    } =0

    song_data :
    ALIGN(4)
    {
        sound/songs/*.o(.rodata);
    } =0

    lib_rodata :
    SUBALIGN(4)
    {
        src/m4a.o(.rodata);
        src/agb_flash.o(.rodata);
        src/agb_flash_1m.o(.rodata);
        src/agb_flash_mx.o(.rodata);
        src/agb_flash_le.o(.rodata);
        src/siirtc.o(.rodata);
        src/librfu_rfu.o(.rodata);
        src/librfu_sio32id.o(.rodata);
        *libgcc.a:*.o(.rodata*);
        *libc.a:*.o(.rodata*);
        *libc.a:*.o(.data*);
        src/libisagbprn.o(.rodata);
    } =0

    other_data :
    ALIGN(4)
    {
        data/unknown_serial_data.o(.rodata);
        data/multiboot_berry_glitch_fix.o(.rodata);
        data/multiboot_pokemon_colosseum.o(.rodata);
    } =0

    anim_mon_front_pic_data :
    ALIGN(4)
    {
        src/anim_mon_front_pics.o(.rodata);
    } =0

    gfx_data :
    ALIGN(4)
    {
        src/graphics.o(.rodata);
    } =0

    /* DWARF debug sections.
       Symbols in the DWARF debugging sections are relative to the beginning
       of the section so we begin them at 0.  */

    /* DWARF 1 */
    .debug          0 : { *(.debug) }
    .line           0 : { *(.line) }

    /* GNU DWARF 1 extensions */
    .debug_srcinfo  0 : { *(.debug_srcinfo) }
    .debug_sfnames  0 : { *(.debug_sfnames) }

    /* DWARF 1.1 and DWARF 2 */
    .debug_aranges  0 : { *(.debug_aranges) }
    .debug_pubnames 0 : { *(.debug_pubnames) }

    /* DWARF 2 */
    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
    .debug_abbrev   0 : { *(.debug_abbrev) }
    .debug_line     0 : { *(.debug_line) }
    .debug_frame    0 : { *(.debug_frame) }
    .debug_str      0 : { *(.debug_str) }
    .debug_loc      0 : { *(.debug_loc) }
    .debug_macinfo  0 : { *(.debug_macinfo) }

    /* Discard everything not specifically mentioned above. */
    /DISCARD/ :
    {
        *(*);
    }
}


code:
TOOLCHAIN := $(DEVKITARM)
COMPARE ?= 0

ifeq ($(CC),)
HOSTCC := gcc
else
HOSTCC := $(CC)
endif

ifeq ($(CXX),)
HOSTCXX := g++
else
HOSTCXX := $(CXX)
endif

ifneq (,$(wildcard $(TOOLCHAIN)/base_tools))
include $(TOOLCHAIN)/base_tools
else
export PATH := $(TOOLCHAIN)/bin:$(PATH)
PREFIX := arm-none-eabi-
OBJCOPY := $(PREFIX)objcopy
export CC := $(PREFIX)gcc
export AS := $(PREFIX)as
endif
export CPP := $(PREFIX)cpp
export LD := $(PREFIX)ld

ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif

ASFLAGS := -mcpu=arm7tdmi
ARFLAGS := rc

SYSCALLS := IntrWait \
            RegisterRamReset \
            Sqrt \
            MusicPlayerOpen \
            SoundBiasReset \
            SoundDriverVSyncOn \
            Mod \
            VBlankIntrWait \
            MusicPlayerStart \
            SoundDriverVSyncOff \
            HuffUnComp \
            SoftResetExram \
            MusicPlayerFadeOut \
            LZ77UnCompWram \
            SoundDriverMain \
            SoundBiasChange \
            LZ77UnCompVram \
            ArcTan2 \
            MusicPlayerStop \
            DivArm \
            ModArm \
            SoundDriverVSync \
            SoundDriverInit \
            BgAffineSet \
            Diff8bitUnFilterWram \
            MultiBoot \
            MidiKey2Freq \
            Div \
            Diff8bitUnFilterVram \
            ArcTan \
            ObjAffineSet \
            SoftResetRom \
            SoundDriverMode \
            RLUnCompWram \
            BitUnPack \
            SoundChannelClear \
            CpuFastSet \
            CpuSet \
            Diff16bitUnFilter \
            SoundBiasSet \
            MusicPlayerContinue \
            SoftReset \
            RLUnCompVram

ASM_SRCS := libagbsyscall.s
ASM_OBJS := $(foreach syscall, $(SYSCALLS), $(syscall).o)

LIB := libagbsyscall.a

.PHONY: all clean

all: $(LIB)
	@:

clean:
	rm -f $(LIB) $(ASM_OBJS)

$(LIB): $(ASM_OBJS)
	$(AR) $(ARFLAGS) $@ $^

$(ASM_OBJS): libagbsyscall.s
	$(AS) $(ASFLAGS) --defsym L_$(*F)=1 -o $@ $<

path: libagbsyscall/Makefile


code:
	.include "../constants/gba_constants.inc"
	.include "../asm/macros/function.inc"

	.text

	.set SOFT_RESET_DIRECT_BUF, 0x03007FFA
	.set RESET_EX_WRAM_FLAG,           0x1

	.ifdef NO_GRANULAR_AGBSYSCALL
	.set L_IntrWait, 1
	.set L_RegisterRamReset, 1
	.set L_Sqrt, 1
	.set L_MusicPlayerOpen, 1
	.set L_SoundBiasReset, 1
	.set L_SoundDriverVSyncOn, 1
	.set L_Mod, 1
	.set L_VBlankIntrWait, 1
	.set L_MusicPlayerStart, 1
	.set L_SoundDriverVSyncOff, 1
	.set L_HuffUnComp, 1
	.set L_SoftResetExram, 1
	.set L_MusicPlayerFadeOut, 1
	.set L_LZ77UnCompWram, 1
	.set L_SoundDriverMain, 1
	.set L_SoundBiasChange, 1
	.set L_LZ77UnCompVram, 1
	.set L_ArcTan2, 1
	.set L_MusicPlayerStop, 1
	.set L_DivArm, 1
	.set L_ModArm, 1
	.set L_SoundDriverVSync, 1
	.set L_SoundDriverInit, 1
	.set L_BgAffineSet, 1
	.set L_Diff8bitUnFilterWram, 1
	.set L_MultiBoot, 1
	.set L_MidiKey2Freq, 1
	.set L_Div, 1
	.set L_Diff8bitUnFilterVram, 1
	.set L_ArcTan, 1
	.set L_ObjAffineSet, 1
	.set L_SoftResetRom, 1
	.set L_SoundDriverMode, 1
	.set L_RLUnCompWram, 1
	.set L_BitUnPack, 1
	.set L_SoundChannelClear, 1
	.set L_CpuFastSet, 1
	.set L_CpuSet, 1
	.set L_Diff16bitUnFilter, 1
	.set L_SoundBiasSet, 1
	.set L_MusicPlayerContinue, 1
	.set L_SoftReset, 1
	.set L_RLUnCompVram, 1
	.endif

	.ifdef L_IntrWait
	thumb_func_start IntrWait
IntrWait:
	movs r2, #0
	svc #4
	bx lr
	thumb_func_end IntrWait
	.endif

	.ifdef L_RegisterRamReset
	thumb_func_start RegisterRamReset
RegisterRamReset:
	svc #1
	bx lr
	thumb_func_end RegisterRamReset
	.endif

	.ifdef L_Sqrt
	thumb_func_start Sqrt
Sqrt:
	svc #8
	bx lr
	thumb_func_end Sqrt
	.endif

	.ifdef L_MusicPlayerOpen
	thumb_func_start MusicPlayerOpen
MusicPlayerOpen:
	svc #32
	bx lr
	thumb_func_end MusicPlayerOpen
	.endif

	.ifdef L_SoundBiasReset
	thumb_func_start SoundBiasReset
SoundBiasReset:
	movs r0, #0
	svc #25
	bx lr
	thumb_func_end SoundBiasReset
	.endif

	.ifdef L_SoundDriverVSyncOn
	thumb_func_start SoundDriverVSyncOn
SoundDriverVSyncOn:
	svc #41
	bx lr
	thumb_func_end SoundDriverVSyncOn
	.endif

	.ifdef L_Mod
	thumb_func_start Mod
Mod:
	svc #6
	mov r0, r1
	bx lr
	thumb_func_end Mod
	.endif

	.ifdef L_VBlankIntrWait
	thumb_func_start VBlankIntrWait
VBlankIntrWait:
	movs r2, #0
	svc #5
	bx lr
	thumb_func_end VBlankIntrWait
	.endif

	.ifdef L_MusicPlayerStart
	thumb_func_start MusicPlayerStart
MusicPlayerStart:
	svc #33
	bx lr
	thumb_func_end MusicPlayerStart
	.endif

	.ifdef L_SoundDriverVSyncOff
	thumb_func_start SoundDriverVSyncOff
SoundDriverVSyncOff:
	svc #40
	bx lr
	thumb_func_end SoundDriverVSyncOff
	.endif

	.ifdef L_HuffUnComp
	thumb_func_start HuffUnComp
HuffUnComp:
	svc #19
	bx lr
	thumb_func_end HuffUnComp
	.endif

	.ifdef L_SoftResetExram
	arm_func_start SoftResetExram
SoftResetExram:
	ldr r3, =REG_IME
	movs r2, #0
	strb r2, [r3, #0]
	ldr r3, =SOFT_RESET_DIRECT_BUF
	movs r2, #1
	strb r2, [r3, #0]
	subs r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00
	mov sp, r3
	movs r2, #RESET_EX_WRAM_FLAG
	bics r0, r2
	svc #1
	svc #0
	.pool
	arm_func_end SoftResetExram
	.endif

	.ifdef L_MusicPlayerFadeOut
	thumb_func_start MusicPlayerFadeOut
MusicPlayerFadeOut:
	svc #36
	bx lr
	thumb_func_end MusicPlayerFadeOut
	.endif

	.ifdef L_LZ77UnCompWram
	thumb_func_start LZ77UnCompWram
LZ77UnCompWram:
	svc #17
	bx lr
	thumb_func_end LZ77UnCompWram
	.endif

	.ifdef L_SoundDriverMain
	thumb_func_start SoundDriverMain
SoundDriverMain:
	svc #28
	bx lr
	thumb_func_end SoundDriverMain
	.endif

	.ifdef L_SoundBiasChange
	thumb_func_start SoundBiasChange
SoundBiasChange:
	svc #25
	bx lr
	thumb_func_end SoundBiasChange
	.endif

	.ifdef L_LZ77UnCompVram
	thumb_func_start LZ77UnCompVram
LZ77UnCompVram:
	svc #18
	bx lr
	thumb_func_end LZ77UnCompVram
	.endif

	.ifdef L_ArcTan2
	thumb_func_start ArcTan2
ArcTan2:
	svc #10
	bx lr
	thumb_func_end ArcTan2
	.endif

	.ifdef L_MusicPlayerStop
	thumb_func_start MusicPlayerStop
MusicPlayerStop:
	svc #34
	bx lr
	thumb_func_end MusicPlayerStop
	.endif

	.ifdef L_DivArm
	thumb_func_start DivArm
DivArm:
	svc #7
	bx lr
	thumb_func_end DivArm
	.endif

	.ifdef L_ModArm
	thumb_func_start ModArm
ModArm:
	svc #7
	mov r0, r1
	bx lr
	thumb_func_end ModArm
	.endif

	.ifdef L_SoundDriverVSync
	thumb_func_start SoundDriverVSync
SoundDriverVSync:
	svc #29
	bx lr
	thumb_func_end SoundDriverVSync
	.endif

	.ifdef L_SoundDriverInit
	thumb_func_start SoundDriverInit
SoundDriverInit:
	svc #26
	bx lr
	thumb_func_end SoundDriverInit
	.endif

	.ifdef L_BgAffineSet
	thumb_func_start BgAffineSet
BgAffineSet:
	svc #14
	bx lr
	thumb_func_end BgAffineSet
	.endif

	.ifdef L_Diff8bitUnFilterWram
	thumb_func_start Diff8bitUnFilterWram
Diff8bitUnFilterWram:
	svc #22
	bx lr
	thumb_func_end Diff8bitUnFilterWram
	.endif

	.ifdef L_MultiBoot
	thumb_func_start MultiBoot
MultiBoot:
	mov r1, #1
	svc #37
	bx lr
	thumb_func_end MultiBoot
	.endif

	.ifdef L_MidiKey2Freq
	thumb_func_start MidiKey2Freq
MidiKey2Freq:
	svc #31
	bx lr
	thumb_func_end MidiKey2Freq
	.endif

	.ifdef L_Div
	thumb_func_start Div
Div:
	svc #6
	bx lr
	thumb_func_end Div
	.endif

	.ifdef L_Diff8bitUnFilterVram
	thumb_func_start Diff8bitUnFilterVram
Diff8bitUnFilterVram:
	svc #23
	bx lr
	thumb_func_end Diff8bitUnFilterVram
	.endif

	.ifdef L_ArcTan
	thumb_func_start ArcTan
ArcTan:
	svc #9
	bx lr
	thumb_func_end ArcTan
	.endif

	.ifdef L_ObjAffineSet
	thumb_func_start ObjAffineSet
ObjAffineSet:
	svc #15
	bx lr
	thumb_func_end ObjAffineSet
	.endif

	.ifdef L_SoftResetRom
	thumb_func_start SoftResetRom
SoftResetRom:
	ldr r3, =REG_IME
	movs r2, #0
	strb r2, [r3, #0]
	ldr r3, =SOFT_RESET_DIRECT_BUF
	movs r2, #0
	strb r2, [r3, #0]
	sub r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00
	mov sp, r3
	svc #1
	svc #0
	.pool
	thumb_func_end SoftResetRom
	.endif

	.ifdef L_SoundDriverMode
	thumb_func_start SoundDriverMode
SoundDriverMode:
	svc #27
	bx lr
	thumb_func_end SoundDriverMode
	.endif

	.ifdef L_RLUnCompWram
	thumb_func_start RLUnCompWram
RLUnCompWram:
	svc #20
	bx lr
	thumb_func_end RLUnCompWram
	.endif

	.ifdef L_BitUnPack
	thumb_func_start BitUnPack
BitUnPack:
	svc #16
	bx lr
	thumb_func_end BitUnPack
	.endif

	.ifdef L_SoundChannelClear
	thumb_func_start SoundChannelClear
SoundChannelClear:
	svc #30
	bx lr
	thumb_func_end SoundChannelClear
	.endif

	.ifdef L_CpuFastSet
	thumb_func_start CpuFastSet
CpuFastSet:
	svc #12
	bx lr
	thumb_func_end CpuFastSet
	.endif

	.ifdef L_CpuSet
	thumb_func_start CpuSet
CpuSet:
	svc #11
	bx lr
	thumb_func_end CpuSet
	.endif

	.ifdef L_Diff16bitUnFilter
	thumb_func_start Diff16bitUnFilter
Diff16bitUnFilter:
	svc #24
	bx lr
	thumb_func_end Diff16bitUnFilter
	.endif

	.ifdef L_SoundBiasSet
	thumb_func_start SoundBiasSet
SoundBiasSet:
	movs r0, #1
	svc #25
	bx lr
	thumb_func_end SoundBiasSet
	.endif

	.ifdef L_MusicPlayerContinue
	thumb_func_start MusicPlayerContinue
MusicPlayerContinue:
	svc #35
	bx lr
	thumb_func_end MusicPlayerContinue
	.endif

	.ifdef L_SoftReset
	thumb_func_start SoftReset
SoftReset:
	ldr r3, =REG_IME
	movs r2, #0
	strb r2, [r3, #0]
	ldr r1, =0x3007f00
	mov sp, r1
	svc #1
	svc #0
	.pool
	thumb_func_end SoftReset
	.endif

	.ifdef L_RLUnCompVram
	thumb_func_start RLUnCompVram
RLUnCompVram:
	svc #21
	bx lr
	thumb_func_end RLUnCompVram
	.endif

	.align 2, 0 @ Don't pad with nop


code:
# Map JSON data

MAPS_DIR = $(DATA_ASM_SUBDIR)/maps
LAYOUTS_DIR = $(DATA_ASM_SUBDIR)/layouts

MAP_DIRS := $(dir $(wildcard $(MAPS_DIR)/*/map.json))
MAP_CONNECTIONS := $(patsubst $(MAPS_DIR)/%/,$(MAPS_DIR)/%/connections.inc,$(MAP_DIRS))
MAP_EVENTS := $(patsubst $(MAPS_DIR)/%/,$(MAPS_DIR)/%/events.inc,$(MAP_DIRS))
MAP_HEADERS := $(patsubst $(MAPS_DIR)/%/,$(MAPS_DIR)/%/header.inc,$(MAP_DIRS))

$(DATA_ASM_BUILDDIR)/maps.o: $(DATA_ASM_SUBDIR)/maps.s $(LAYOUTS_DIR)/layouts.inc $(LAYOUTS_DIR)/layouts_table.inc $(MAPS_DIR)/headers.inc $(MAPS_DIR)/groups.inc $(MAPS_DIR)/connections.inc $(MAP_CONNECTIONS) $(MAP_HEADERS)
	$(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@
$(DATA_ASM_BUILDDIR)/map_events.o: $(DATA_ASM_SUBDIR)/map_events.s $(MAPS_DIR)/events.inc $(MAP_EVENTS)
	$(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@

$(MAPS_DIR)/%/header.inc: $(MAPS_DIR)/%/map.json
	$(MAPJSON) map emerald $< $(LAYOUTS_DIR)/layouts.json
$(MAPS_DIR)/%/events.inc: $(MAPS_DIR)/%/header.inc ;
$(MAPS_DIR)/%/connections.inc: $(MAPS_DIR)/%/events.inc ;

$(MAPS_DIR)/groups.inc: $(MAPS_DIR)/map_groups.json
	$(MAPJSON) groups emerald $<
$(MAPS_DIR)/connections.inc: $(MAPS_DIR)/groups.inc ;
$(MAPS_DIR)/events.inc: $(MAPS_DIR)/connections.inc ;
$(MAPS_DIR)/headers.inc: $(MAPS_DIR)/events.inc ;
include/constants/map_groups.h: $(MAPS_DIR)/headers.inc ;

$(LAYOUTS_DIR)/layouts.inc: $(LAYOUTS_DIR)/layouts.json
	$(MAPJSON) layouts emerald $<
$(LAYOUTS_DIR)/layouts_table.inc: $(LAYOUTS_DIR)/layouts.inc ;
include/constants/layouts.h: $(LAYOUTS_DIR)/layouts_table.inc ;