pokeemerald/include/link.h

257 lines
6.4 KiB
C
Raw Normal View History

2017-09-11 11:35:41 +02:00
#ifndef GUARD_LINK_H
#define GUARD_LINK_H
#define MAX_LINK_PLAYERS 4
2017-11-11 04:34:23 +01:00
#define MAX_RFU_PLAYERS 5
2017-09-11 11:35:41 +02:00
#define CMD_LENGTH 8
#define QUEUE_CAPACITY 50
#define BLOCK_BUFFER_SIZE 0x100
#define LINK_STAT_LOCAL_ID 0x00000003
#define LINK_STAT_PLAYER_COUNT 0x0000001C
#define LINK_STAT_PLAYER_COUNT_SHIFT 2
#define LINK_STAT_MASTER 0x00000020
#define LINK_STAT_MASTER_SHIFT 5
#define LINK_STAT_CONN_ESTABLISHED 0x00000040
#define LINK_STAT_CONN_ESTABLISHED_SHIFT 6
#define LINK_STAT_RECEIVED_NOTHING 0x00000100
#define LINK_STAT_RECEIVED_NOTHING_SHIFT 8
#define LINK_STAT_ERRORS 0x0007F000
2017-11-13 05:16:51 +01:00
#define LINK_STAT_ERRORS_SHIFT 12
2017-09-11 11:35:41 +02:00
#define EXTRACT_PLAYER_COUNT(status) \
(((status) & LINK_STAT_PLAYER_COUNT) >> LINK_STAT_PLAYER_COUNT_SHIFT)
#define EXTRACT_MASTER(status) \
(((status) >> LINK_STAT_MASTER_SHIFT) & 1)
#define EXTRACT_CONN_ESTABLISHED(status) \
(((status) >> LINK_STAT_CONN_ESTABLISHED_SHIFT) & 1)
#define EXTRACT_RECEIVED_NOTHING(status) \
(((status) >> LINK_STAT_RECEIVED_NOTHING_SHIFT) & 1)
2017-11-13 05:16:51 +01:00
#define EXTRACT_LINK_ERRORS(status) \
(((status) & LINK_STAT_ERRORS) >> LINK_STAT_ERRORS_SHIFT)
2017-09-11 11:35:41 +02:00
2017-11-11 04:34:23 +01:00
struct LinkStatus
{
u32 localId:2;
u32 playerCount:3;
u32 master:1;
u32 connEstablished:1;
u32 unused_7:1;
u32 receivedNothing:1;
u32 unused_9:7;
u32 errors:7;
};
2017-09-11 11:35:41 +02:00
#define MASTER_HANDSHAKE 0x8FFF
#define SLAVE_HANDSHAKE 0xB9A0
2017-11-11 04:08:17 +01:00
#define SIO_MULTI_CNT ((volatile struct SioMultiCnt *)REG_ADDR_SIOCNT)
2017-09-11 11:35:41 +02:00
enum
{
LINK_STATE_START0,
LINK_STATE_START1,
LINK_STATE_HANDSHAKE,
LINK_STATE_INIT_TIMER,
LINK_STATE_CONN_ESTABLISHED,
};
enum
{
EXCHANGE_NOT_STARTED,
EXCHANGE_COMPLETE,
EXCHANGE_TIMED_OUT,
EXCHANGE_IN_PROGRESS,
2017-11-11 06:05:44 +01:00
EXCHANGE_STAT_4,
EXCHANGE_STAT_5,
EXCHANGE_STAT_6
2017-09-11 11:35:41 +02:00
};
enum
{
QUEUE_FULL_NONE,
QUEUE_FULL_SEND,
QUEUE_FULL_RECV,
};
enum
{
LAG_NONE,
LAG_MASTER,
LAG_SLAVE,
};
struct LinkPlayer
{
/* 0x00 */ u16 version;
/* 0x02 */ u16 lp_field_2;
/* 0x04 */ u32 trainerId;
/* 0x08 */ u8 name[11];
/* 0x13 */ u8 gender;
/* 0x14 */ u32 linkType;
/* 0x18 */ u16 lp_field_18;
/* 0x1A */ u16 language;
};
struct LinkPlayerBlock
{
u8 magic1[16];
struct LinkPlayer linkPlayer;
u8 magic2[16];
};
// circular queues
struct SendQueue
{
u16 data[CMD_LENGTH][QUEUE_CAPACITY];
u8 pos;
u8 count;
};
struct RecvQueue
{
u16 data[MAX_LINK_PLAYERS][CMD_LENGTH][QUEUE_CAPACITY];
u8 pos;
u8 count;
};
struct Link
{
u8 isMaster; // 0: slave, 8: master
u8 state;
u8 localId; // local multi-player ID
u8 playerCount;
u16 tempRecvBuffer[4];
bool8 receivedNothing;
s8 serialIntrCounter;
bool8 handshakeAsMaster;
u8 link_field_F;
// error conditions
bool8 hardwareError; // hardware reported an error
bool8 badChecksum; // checksum didn't match between devices
u8 queueFull; // send or recv queue out of space
u8 lag; // connection is lagging
u16 checksum;
u8 sendCmdIndex;
u8 recvCmdIndex;
struct SendQueue sendQueue;
struct RecvQueue recvQueue;
};
struct BlockRequest
{
void * address;
u32 size;
};
extern const struct BlockRequest sBlockRequestLookupTable[5];
extern struct Link gLink;
2017-11-11 06:25:05 +01:00
extern u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH];
2017-11-11 06:05:44 +01:00
extern u8 gBlockSendBuffer[BLOCK_BUFFER_SIZE]; // gBlockSendBuffer
2017-09-11 11:35:41 +02:00
extern u8 gBlockSendBuffer[BLOCK_BUFFER_SIZE];
extern u16 gLinkType;
extern u32 gLinkStatus;
2017-11-11 04:34:23 +01:00
extern u16 gBlockRecvBuffer[MAX_RFU_PLAYERS][BLOCK_BUFFER_SIZE / 2];
2017-09-11 11:35:41 +02:00
extern u16 gSendCmd[CMD_LENGTH];
extern u8 gShouldAdvanceLinkState;
extern struct LinkPlayer gLinkPlayers[];
extern u16 word_3002910[];
extern bool8 gReceivedRemoteLinkPlayers;
2017-11-11 04:08:17 +01:00
extern bool8 gSerialIsRFU;
2017-09-11 11:35:41 +02:00
void Task_DestroySelf(u8);
void OpenLink(void);
void CloseLink(void);
2017-11-11 06:05:44 +01:00
u16 LinkMain2(const u16 *);
2017-09-11 11:35:41 +02:00
void sub_8007B14(void);
bool32 sub_8007B24(void);
void ClearLinkCallback(void);
void ClearLinkCallback_2(void);
u8 GetLinkPlayerCount(void);
void OpenLinkTimed(void);
2017-11-11 06:05:44 +01:00
u8 GetLinkPlayerDataExchangeStatusTimed(int lower, int upper);
2017-09-11 11:35:41 +02:00
bool8 IsLinkPlayerDataExchangeComplete(void);
u32 GetLinkPlayerTrainerId(u8);
void ResetLinkPlayers(void);
void sub_8007E24(void);
void sub_8007E4C(void);
u8 GetMultiplayerId(void);
u8 bitmask_all_link_players_but_self(void);
2017-11-11 04:08:17 +01:00
bool8 SendBlock(u8, const void *, u16);
2017-09-11 11:35:41 +02:00
u8 GetBlockReceivedStatus(void);
void ResetBlockReceivedFlags(void);
void ResetBlockReceivedFlag(u8);
u8 GetLinkPlayerCount_2(void);
bool8 IsLinkMaster(void);
void CB2_LinkError(void);
u8 GetSioMultiSI(void);
bool8 IsLinkConnectionEstablished(void);
void SetSuppressLinkErrorMessage(bool8);
bool8 HasLinkErrorOccurred(void);
void ResetSerial(void);
u32 LinkMain1(u8 *, u16 *, u16[CMD_LENGTH][MAX_LINK_PLAYERS]);
void LinkVSync(void);
void Timer3Intr(void);
void SerialCB(void);
Decompile TV (#80) * ClearTVShowData * special_0x44 * DoTVShow (nonmatching because align) * DoTVShowBravoTrainerPokemonProfile * Update field names * DoTVShowBravoTrainerBattleTower * Renaming of struct fields * sub_80EBFF4 and UpdateTVScreensOnMap * SetTVMetatilesOnMap * Power buttons for the TV screens on the map * special_0x45 * sub_80EC18C * special_0x4a * ResetGabbyAndTy * GabbyAndTyBeforeInterview * GabbyAndTyAfterInterview * Through IsTVShowInSearchOfTrainersAiring * GabbyAndTyGetLastQuote * GabbyAndTyGetLastBattleTrivia * GabbyAndTySetScriptVarsToFieldObjectLocalIds * InterviewAfter; use TVShow as a precursor for making the individual show structs anonymous * Make TV structs anonymous within the union * Move the TV union to its own subheader * Move TV show enums to the global.tv.h subheader * Funcion renaming * Apply static attributes where able * PutPokemonTodayCaughtOnAir * sub_80EC8A4 * PutPokemonTodayFailedOnTheAir * sub_80EC9E8, sub_80ECA10 * sub_80ECA38 * sub_80ECB00 * Put3CheersForPokeblocksOnTheAir * PutFanClubSpecialOnTheAir * ContestLiveUpdates_BeforeInterview * Other before-interview Contest Live Updates functions * ContestLiveUpdates_BeforeInterview_5 * InterviewAfter_BravoTrainerPokemonProfile * BravoTrainerPokemonProfile_BeforeInterview1 * BravoTrainerPokemonProfile_BeforeInterview2 * Disassemble TV data * Decompile TV data * InterviewAfter_BravoTrainerBattleTowerProfile * SaveRecordedItemPurchasesForTVShow * PutNameRaterShowOnTheAir * StartMassOutbreak * PutLilycoveContestLadyShowOnTheAir * InterviewAfter_FanClubLetter * Rip TV strings * InterviewAfter_RecentHappenings * InterviewAfter_PkmnFanClubOpinions * sub_80ED718 * EndMassOutbreak * sub_80ED888 * sub_80ED8B4 * UpdateMassOutbreakTimeLeft * sub_80ED950 * PutFishingAdviceShowOnTheAir * through sub_80EDA80 * ewram and common syms are now fetched from the object files * BSS symbols are taken from the tv.o file * through sub_80EDC60 * sub_80EDCE8 * sub_80EDD78 * through sub_80EDE84 * nomatching sub_80EDE98 * sub_80EDFB4 * sub_80EE104 * sub_80EE104 * sub_80EE184 * sub_80EE2CC * sub_80EE35C * sub_80EE44C * sub_80EE4DC * sub_80EE5A4 * sub_80EE69C * sub_80EE72C * sub_80EE7C0 * sub_80EE818 * sub_80EE8C8 * sub_80EEA70 * sub_80EEB98 * sub_80EEBF4 * through sub_80EED60 * Functions relating to Pokemon News * sub_80EEF6C * GetPriceReduction * IsPriceDiscounted * sub_80EF120 * through sub_80EF370 * sub_80EF40C * HasMixableShowAlreadyBeenSpawnedWithPlayerID * TV_SortPurchasesByQuantity * FindActiveBroadcastByShowType_SetScriptResult * InterviewBefore * through sub_80EF88C * through sub_80EF93C * through sub_80EFA24 * through TV_BernoulliTrial * sub_80EFB58 * sub_80EFBA4 * sub_80EFBDC * through sub_80EFD98 * ChangePokemonNickname * ChangeBoxPokemonNickname * sub_80EFF9C * through player_id_to_dword * CheckForBigMovieOrEmergencyNewsOnTV * GetMomOrDadStringForTVMessage * sub_80F01E8 * sub_80F0358 * sub_80F049C * TV record mixing functions * sub_80F06D0 * sub_80F0708 nonmatching * through sub_80F0B24 * sub_80F0B64 * through sub_80F0C04 * sub_80F0C7C * sub_80F0D60 * sub_80F0E58 * sub_80F0E84 * through sub_80F0F24 * sub_80F0F64 * sub_80F1208 * sub_80F1254 * sub_80F1290 * sub_80F12A4 * sub_80F14F8 * DoTVShowTodaysSmartShopper * DoTVShowTheNameRaterShow * DoTVShowPokemonTodaySuccessfulCapture * DoTVShowPokemonTodayFailedCapture * DoTVShowPokemonFanClubLetter * DoTVShowRecentHappenings * DoTVShowPokemonFanClubOpinions * DoTVShowPokemonNewsMassOutbreak * DoTVShowPokemonContestLiveUpdates * DoTVShowPokemonBattleUpdate * DoTVShow3CheersForPokeblocks * DoTVShowInSearchOfTrainers * Label GabbyAndTyData fields; remove ddump comments from data/text/tv.inc * DoTVShowPokemonAngler * DoTVShowTheWorldOfMasters; update RAM symbols and field names * Decorate static functions * DoTVShowTodaysRivalTrainer; region map enums * TVDewfordTrendWatcherNetworkTextGroup * DoTVShowHoennTreasureInvestigators * DoTVShowFindThatGamer * DoTVShowBreakingNewsTV * DoTVShowSecretBaseVisit * DoTVShowPokemonLotterWinnerFlashReport * DoTVShowThePokemonBattleSeminar * DoTVShowTrainerFanClubSpecial, DoTVShowTrainerFanClub * DoTVShowSpotTheCuties * DoTVShowPokemonNewsBattleFrontier * DoTVShowWhatsNo1InHoennToday * Helpers for DoTVShowSecretBaseSecrets * DoTVShowSecretBaseSecrets * DoTVShowSafariFanClub * Finish decompilation of tv.s * Some renaming * Rename text group pointers * revoke statis; pokenews enums * Labels are number one * Label all TV struct fields * Make data/text/tv.inc more readable * Split data/text/tv.inc * Rename pokenews text pointers * Frontier Symbol constants; indicate static rodata objects with 's' prefix * Fix leading spaces/tabs F*** CLion sometimes * Fix inconsequential warning
2017-10-13 17:09:36 +02:00
u8 GetLinkPlayerCount(void);
2017-09-11 11:35:41 +02:00
2017-10-01 01:12:42 +02:00
void sub_800E0E8(void);
bool8 sub_800A520(void);
void sub_800DFB4(u8, u8);
2017-10-01 18:54:01 +02:00
void sub_800ADF8(void);
2017-10-13 17:22:50 +02:00
void sub_800B488(void);
void sub_800A620(void);
void sub_8011BD0(void);
2017-11-13 04:09:11 +01:00
u8 IsLinkMaster(void);
2017-10-22 18:43:15 +02:00
void sub_800AC34(void);
2017-10-01 01:12:42 +02:00
2017-11-11 06:05:44 +01:00
void SetLinkDebugValues(u32 seed, u32 flags);
2017-11-11 02:47:24 +01:00
void sub_800A418(void);
2017-11-11 06:05:44 +01:00
void SetSuppressLinkErrorMessage(bool8 flag);
void sub_800B524(struct LinkPlayer *linkPlayer);
u8 sub_800B2E8(void);
u8 sub_800B320(void);
u8 sub_800B33C(void);
2017-11-08 02:25:24 +01:00
2017-11-09 01:29:37 +01:00
extern u16 gUnknown_03003020[6];
2017-11-11 06:25:05 +01:00
extern u32 gLinkDebugSeed;
2017-11-11 06:05:44 +01:00
extern struct LinkPlayerBlock gLocalLinkPlayerBlock;
extern bool8 gLinkErrorOccurred;
2017-11-11 06:25:05 +01:00
extern u32 gLinkDebugFlags;
extern bool8 gUnknown_03003078[MAX_LINK_PLAYERS];
extern u8 gUnknown_0300307C[MAX_LINK_PLAYERS];
2017-11-11 06:05:44 +01:00
extern u16 gLinkHeldKeys;
extern u32 gLinkStatus;
2017-11-09 01:29:37 +01:00
extern u8 gUnknown_030030E4;
extern u8 gUnknown_030030E8;
2017-11-11 06:25:05 +01:00
extern u8 gUnknown_030030EC[MAX_LINK_PLAYERS];
extern u8 gUnknown_030030F0[MAX_LINK_PLAYERS];
2017-11-09 01:29:37 +01:00
extern u16 gUnknown_030030F4;
2017-11-11 06:05:44 +01:00
extern u8 gSuppressLinkErrorMessage;
2017-11-11 04:08:17 +01:00
extern bool8 gSerialIsRFU;
2017-11-13 02:57:21 +01:00
extern bool8 gSavedLinkPlayerCount;
2017-11-13 03:31:08 +01:00
extern u8 gSavedMultiplayerId;
2017-11-11 06:05:44 +01:00
extern struct LinkTestBGInfo gLinkTestBGInfo;
extern void (*gLinkCallback)(void);
extern bool8 gShouldAdvanceLinkState;
2017-11-11 06:25:05 +01:00
extern u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS];
2017-11-11 06:05:44 +01:00
extern u8 gBlockRequestType;
2017-11-13 05:16:51 +01:00
extern u8 gLastSendQueueCount;
extern u8 gLastRecvQueueCount;
2017-11-11 06:25:05 +01:00
extern u16 gUnknown_03004134;
extern u32 gUnknown_03003074;
extern u32 gFiller_03003154;
extern u32 gFiller_03003158;
extern u32 gFiller_0300315c;
extern u32 gFiller_03004138;
extern u32 gFiller_0300413C;
extern u32 gFiller_03003080;
2017-11-08 02:25:24 +01:00
2017-09-11 11:35:41 +02:00
#endif // GUARD_LINK_H