diff --git a/include/cable_club.h b/include/cable_club.h index 515960dfd..7340742ea 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -3,12 +3,6 @@ #include "task.h" -// Exported type declarations - -// Exported RAM declarations - -// Exported ROM declarations - void CreateTask_EnterCableClubSeat(TaskFunc taskFunc); u8 CreateTask_ReestablishCableClubLink(void); void CB2_ReturnFromCableClubBattle(void); diff --git a/include/constants/cable_club.h b/include/constants/cable_club.h index 960a27644..3250ce6f8 100644 --- a/include/constants/cable_club.h +++ b/include/constants/cable_club.h @@ -12,22 +12,18 @@ #define USING_MINIGAME 8 #define USING_BATTLE_TOWER 9 -#define LINKUP_ONGOING 0 -#define LINKUP_SUCCESS 1 -#define LINKUP_SOMEONE_NOT_READY 2 -#define LINKUP_DIFF_SELECTIONS 3 -#define LINKUP_WRONG_NUM_PLAYERS 4 -#define LINKUP_FAILED 5 -#define LINKUP_CONNECTION_ERROR 6 -#define LINKUP_PLAYER_NOT_READY 7 -#define LINKUP_UNK8 8 -#define LINKUP_PARTNER_NOT_READY 9 +#define LINKUP_ONGOING 0 +#define LINKUP_SUCCESS 1 +#define LINKUP_SOMEONE_NOT_READY 2 +#define LINKUP_DIFF_SELECTIONS 3 +#define LINKUP_WRONG_NUM_PLAYERS 4 +#define LINKUP_FAILED 5 +#define LINKUP_CONNECTION_ERROR 6 +#define LINKUP_PLAYER_NOT_READY 7 +#define LINKUP_UNK8 8 +#define LINKUP_PARTNER_NOT_READY 9 #define LINKUP_FAILED_CONTEST_GMODE 10 -#define LINKUP_FAILED_BATTLE_TOWER 11 -#define LINKUP_FOREIGN_GAME 12 - -#define LINK_BATTLE_TOWER_SAME_MON 1 -#define LINK_BATTLE_TOWER_SAME_MONS 2 -#define LINK_BATTLE_TOWER_DIFF_MODE 3 +#define LINKUP_FAILED_BATTLE_TOWER 11 +#define LINKUP_FOREIGN_GAME 12 #endif //GUARD_CONSTANTS_CABLE_CLUB_H diff --git a/include/link.h b/include/link.h index 5e75af088..d33b84c79 100644 --- a/include/link.h +++ b/include/link.h @@ -276,7 +276,6 @@ void CreateWirelessStatusIndicatorSprite(u8, u8); void sub_800ADF8(void); void SetWirelessCommType1(void); void CheckShouldAdvanceLinkState(void); -void sub_8011BD0(void); u8 IsLinkMaster(void); void sub_800AC34(void); bool8 HandleLinkConnection(void); @@ -288,11 +287,11 @@ u8 GetSioMultiSI(void); void sub_800AAF4(void); void sub_800AF18(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06); void sub_800B348(void); -void sub_800B3A4(u32 who); +void LinkPlayerFromBlock(u32 who); bool32 sub_800A07C(void); void ResetLinkPlayerCount(void); void sub_800AA04(u8 a0); -void sub_800B4C0(void); +void SetWirelessCommType0(void); bool32 sub_800B504(void); extern u16 gLinkPartnersHeldKeys[6]; diff --git a/include/link_rfu.h b/include/link_rfu.h index 901b5deae..55b1b3712 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -5,7 +5,18 @@ #include "link.h" #include "AgbRfu_LinkManager.h" -// Exported type declarations +#define RFU_COMMAND_0x4400 0x4400 +#define RFU_COMMAND_0x8800 0x8800 +#define RFU_COMMAND_0x8900 0x8900 +#define RFU_COMMAND_0xA100 0xA100 +#define RFU_COMMAND_0x7700 0x7700 +#define RFU_COMMAND_0x7800 0x7800 +#define RFU_COMMAND_0x6600 0x6600 +#define RFU_COMMAND_0x5F00 0x5F00 +#define RFU_COMMAND_0x2F00 0x2F00 +#define RFU_COMMAND_0xBE00 0xBE00 +#define RFU_COMMAND_0xEE00 0xEE00 +#define RFU_COMMAND_0xED00 0xED00 // RfuTgtData.gname is read as these structs. struct GFtgtGnameSub @@ -67,34 +78,34 @@ struct UnkLinkRfuStruct_02022B44 u8 fill_84[0x58]; }; -struct UnkRfuStruct_2_Sub_6c +struct RfuBlockSend { - /* 0x00 */ u16 unk_00; - /* 0x02 */ u16 unk_02; - /* 0x04 */ const u8 *unk_04; - /* 0x08 */ u32 unk_08; - /* 0x0c */ u32 unk_0c; - /* 0x10 */ u8 unk_10; - /* 0x11 */ u8 unk_11; - /* 0x12 */ u8 unk_12; + /* 0x00 */ u16 next; + /* 0x02 */ u16 count; + /* 0x04 */ const u8 *payload; + /* 0x08 */ u32 receivedFlags; + /* 0x0c */ u32 failedFlags; + /* 0x10 */ bool8 sending; + /* 0x11 */ u8 owner; + /* 0x12 */ u8 receiving; }; -struct UnkRfuStruct_2_Sub_124 +struct RfuRecvQueue { /* 0x000 */ u8 unk_00[32][70]; /* 0x8c0 */ vu8 unk_8c0; /* 0x8c1 */ vu8 unk_8c1; - /* 0x8c2 */ vu8 unk_8c2; - /* 0x8c3 */ vu8 unk_8c3; + /* 0x8c2 */ vu8 count; + /* 0x8c3 */ vu8 full; }; -struct UnkRfuStruct_2_Sub_9e8 +struct RfuSendQueue { /* 0x000 */ u8 unk_00[40][14]; /* 0x230 */ vu8 unk_230; /* 0x231 */ vu8 unk_231; - /* 0x232 */ vu8 unk_232; - /* 0x233 */ vu8 unk_233; + /* 0x232 */ vu8 count; + /* 0x233 */ vu8 full; }; struct UnkRfuStruct_2_Sub_c1c @@ -102,7 +113,7 @@ struct UnkRfuStruct_2_Sub_c1c /* 0x00 */ u8 unk_00[2][14]; /* 0x1c */ vu8 unk_1c; /* 0x1d */ vu8 unk_1d; - /* 0x1e */ vu8 unk_1e; + /* 0x1e */ vu8 count; }; struct UnkRfuStruct_Sub_Unused @@ -114,13 +125,13 @@ struct UnkRfuStruct_Sub_Unused /* 0x203 */ vu8 unk_203; }; -struct UnkRfuStruct_2 +struct GFRfuManager { - /* 0x000 */ void (*linkRfuCallback)(void); - /* 0x004 */ u16 unk_04; + /* 0x000 */ void (*callback)(void); + /* 0x004 */ u16 state; /* 0x006 */ u8 filler_06[4]; - /* 0x00a */ u16 unk_0a; - /* 0x00c */ u8 unk_0c; + /* 0x00a */ u16 linkmanMsg; + /* 0x00c */ u8 parentChild; /* 0x00d */ u8 playerCount; /* 0x00e */ u8 unk_0e; /* 0x00f */ u8 unk_0f; @@ -130,19 +141,19 @@ struct UnkRfuStruct_2 /* 0x04c */ u8 unk_4c[14]; /* 0x05a */ u8 unk_5a; /* 0x05b */ u8 unk_5b; - /* 0x05c */ u8 unk_5c[5]; - /* 0x061 */ u8 unk_61[5]; - /* 0x066 */ u8 unk_66; - /* 0x067 */ u8 unk_67; + /* 0x05c */ bool8 unk_5c[MAX_RFU_PLAYERS]; + /* 0x061 */ bool8 unk_61[MAX_RFU_PLAYERS]; + /* 0x066 */ u8 idleTaskId; + /* 0x067 */ u8 searchTaskId; /* 0x068 */ u8 filler_68[4]; - /* 0x06c */ struct UnkRfuStruct_2_Sub_6c unk_6c; - /* 0x080 */ struct UnkRfuStruct_2_Sub_6c unk_80[5]; + /* 0x06c */ struct RfuBlockSend unk_6c; + /* 0x080 */ struct RfuBlockSend unk_80[MAX_RFU_PLAYERS]; /* 0x0e4 */ u8 unk_e4[5]; /* 0x0e9 */ u8 unk_e9[5]; - /* 0x0ee */ vu8 unk_ee; - /* 0x0ef */ u8 unk_ef; - /* 0x0f0 */ u8 unk_f0; - /* 0x0f1 */ u8 unk_f1; + /* 0x0ee */ vu8 errorState; + /* 0x0ef */ bool8 isShuttingDown; + /* 0x0f0 */ u8 linkLossRecoveryState; + /* 0x0f1 */ u8 errorStatus; /* 0x0f2 */ u16 unk_f2[6]; /* 0x0fe */ u16 unk_fe; /* 0x100 */ u16 unk_100; @@ -151,18 +162,18 @@ struct UnkRfuStruct_2 /* 0x10A */ struct GFtgtGname unk_10A; u8 filler_; u8 playerName[PLAYER_NAME_LENGTH + 1]; - /* 0x124 */ struct UnkRfuStruct_2_Sub_124 unk_124; - /* 0x9e8 */ struct UnkRfuStruct_2_Sub_9e8 unk_9e8; + /* 0x124 */ struct RfuRecvQueue recvQueue; + /* 0x9e8 */ struct RfuSendQueue sendQueue; /* 0xc1c */ struct UnkRfuStruct_2_Sub_c1c unk_c1c; /* 0xc3c */ vu8 unk_c3c; /* 0xc3d */ u8 unk_c3d; - /* 0xc3e */ vu8 unk_c3e; + /* 0xc3e */ vu8 childSlot; /* 0xc3f */ u8 unk_c3f[70]; /* 0xc85 */ u8 unk_c85; /* 0xc86 */ u8 unk_c86; - /* 0xc87 */ u8 unk_c87[5][7][2]; - /* 0xccd */ u8 unk_ccd; - /* 0xcce */ u8 unk_cce; + /* 0xc87 */ u8 recvCmds[5][7][2]; + /* 0xccd */ u8 parentId; + /* 0xcce */ u8 multiplayerId; /* 0xccf */ u8 unk_ccf; /* 0xcd0 */ vu8 unk_cd0; /* 0xcd1 */ u8 unk_cd1[4]; @@ -172,57 +183,48 @@ struct UnkRfuStruct_2 /* 0xcdb */ vu8 unk_cdb; /* 0xcdc */ vu8 unk_cdc; /* 0xcdd */ u8 unk_cdd; - /* 0xcde */ u8 unk_cde[4]; + /* 0xcde */ u8 linkPlayerIdx[RFU_CHILD_MAX]; /* 0xce2 */ u8 unk_ce2; /* 0xce2 */ u8 unk_ce3; /* 0xce4 */ u8 unk_ce4; /* 0xce5 */ u8 unk_ce5; /* 0xce5 */ u8 unk_ce6; - /* 0xce7 */ u8 unk_ce7; + /* 0xce7 */ u8 acceptSlot_flag; /* 0xce8 */ u8 unk_ce8; /* 0xce9 */ u8 unk_ce9; /* 0xcea */ u8 unk_cea[4]; /* 0xcee */ u8 unk_cee[4]; }; // size = 0xcf4 -struct UnkRfuStruct_8010A14 -{ - char unk_00[15]; - u8 unk_0f; - u8 unk_10[4]; - struct LinkPlayer unk_14[5]; - u8 fill_a0[0x5c]; -}; - // Exported RAM declarations -extern struct GFtgtGname gUnknown_02022B14; -extern u8 gUnknown_02022B22[]; -extern struct UnkRfuStruct_2 Rfu; +extern struct GFtgtGname gHostRFUtgtGnameBuffer; +extern u8 gHostRFUtgtUnameBuffer[]; +extern struct GFRfuManager Rfu; extern u8 gWirelessStatusIndicatorSpriteId; // Exported ROM declarations void WipeTrainerNameRecords(void); void sub_800E700(void); void LinkRfu_Shutdown(void); -void sub_800F6FC(u8 who); -void sub_800F728(u8 who); +void Rfu_SetBlockReceivedFlag(u8 who); +void Rfu_ResetBlockReceivedFlag(u8 who); bool32 IsSendingKeysToRfu(void); -void sub_800F804(void); +void StartSendingKeysToRfu(void); void sub_800F850(void); -u8 sub_800FCD8(void); -bool32 sub_800FE84(const u8 *src, size_t size); +u8 Rfu_GetBlockReceivedStatus(void); +bool32 Rfu_InitBlockSend(const u8 *src, size_t size); void ClearLinkRfuCallback(void); -u8 sub_80104F4(void); -u8 rfu_get_multiplayer_id(void); +u8 Rfu_GetLinkPlayerCount(void); +u8 Rfu_GetMultiplayerId(void); bool8 sub_8010100(u8 a0); bool8 IsLinkRfuTaskFinished(void); bool8 Rfu_IsMaster(void); void task_add_05_task_del_08FA224_when_no_RfuFunc(void); void sub_8010434(void); -void sub_800E604(void); +void ResetLinkRfuGFLayer(void); void sub_800E174(void); -void sub_800E6D0(void); +void InitRFU(void); bool32 sub_8010EC0(void); bool32 sub_8010F1C(void); bool32 RfuIsErrorStatus1or2(void); @@ -233,7 +235,7 @@ void sub_80111B0(bool32 a0); u8 RfuGetErrorStatus(void); struct GFtgtGname *GetHostRFUtgtGname(void); void UpdateGameData_GroupLockedIn(u8 a0); -void sub_8011170(u32 a0); +void GetLinkmanErrorParams(u32 a0); void RfuSetErrorStatus(u8 a0, u16 a1); u8 sub_801048C(bool32 a0); void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2); @@ -259,7 +261,7 @@ void UpdateGameDataWithActivitySpriteGendersFlag(u8 a0, u32 a1, u32 a2); void CreateTask_RfuReconnectWithParent(const u8 *src, u16 trainerId); void SetGnameBufferWonderFlags(bool32 a0, bool32 a1); void ClearAndInitHostRFUtgtGname(void); -void sub_8010FCC(u32 a0, u32 a1, u32 a2); +void SetTradeBoardRegisteredMonInfo(u32 type, u32 species, u32 level); void InitializeRfuLinkManager_EnterUnionRoom(void); void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2); bool32 IsUnionRoomListenTaskActive(void); @@ -271,7 +273,8 @@ void sub_800EF7C(void); bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx); bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx); s32 sub_800E87C(u8 idx); -void sub_8011BA4(void); +void CreateTask_RfuIdle(void); +void DestroyTask_RfuIdle(void); void sub_8010198(void); void sub_8011AC8(void); void LinkRfu_FatalError(void); @@ -280,42 +283,17 @@ void sub_80104B0(void); void sub_8011A50(void); void sub_80110B8(u32 a0); bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2); -void sub_800EAB4(void); -void sub_800EAFC(void); void sub_800ED34(u16 unused); -void sub_800EDBC(u16 unused); -void sub_800F048(void); -void sub_800F86C(u8 unused); -void sub_800FCC4(struct UnkRfuStruct_2_Sub_6c *data); -void sub_800FD14(u16 command); -void rfufunc_80F9F44(void); -void sub_800FFB0(void); -void rfufunc_80FA020(void); -bool32 sub_8010454(u32 a0); -void sub_8010528(void); -void sub_8010750(void); -s32 sub_80107A0(void); -void sub_801084C(u8 taskId); -void sub_80109E8(u16 a0); -void sub_8010A70(void *a0); -void sub_8010AAC(u8 taskId); -void sub_8010D0C(u8 taskId); -void sub_80115EC(s32 a0); -u8 sub_8011CE4(const u8 *a0, u16 a1); -void sub_8011D6C(u32 a0); -void sub_8011E94(u32 a0, u32 a1); +bool32 RfuSerialNumberIsValid(u32 serialNo); bool8 sub_8012224(void); -void sub_801227C(void); -void sub_801209C(u8 taskId); -void sub_8011BF8(void); void sub_8011BA4(void); -void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr); -void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr); +void sub_800D6C8(struct RfuRecvQueue *ptr); +void sub_800D724(struct RfuSendQueue *ptr); void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr); -void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2); -void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2); -bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2); -bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2); +void sub_800D7D8(struct RfuRecvQueue *q1, u8 *q2); +void sub_800D888(struct RfuSendQueue *q1, u8 *q2); +bool8 sub_800D934(struct RfuRecvQueue *q1, u8 *q2); +bool8 sub_800D9DC(struct RfuSendQueue *q1, u8 *q2); void sub_800DA68(struct UnkRfuStruct_2_Sub_c1c *q1, const u8 *q2); bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2); void sub_800DB18(struct UnkRfuStruct_Sub_Unused *q1, u8 *q2); diff --git a/include/union_room.h b/include/union_room.h index 7c48a9506..985a6404f 100644 --- a/include/union_room.h +++ b/include/union_room.h @@ -162,7 +162,6 @@ extern u8 gUnionRoomRequestedMonType; // Exported ROM declarations u8 CreateTask_CreateTradeMenu(void); -void nullsub_89(u8 taskId); void var_800D_set_xB(void); void MEvent_CreateTask_CardOrNewsWithFriend(u32 arg0); void MEvent_CreateTask_CardOrNewsOverWireless(u32 arg0); diff --git a/src/battle_controllers.c b/src/battle_controllers.c index a0e9e4416..7f78c1ac9 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -6,6 +6,7 @@ #include "battle_message.h" #include "cable_club.h" #include "link.h" +#include "link_rfu.h" #include "party_menu.h" #include "pokemon.h" #include "recorded_battle.h" @@ -827,7 +828,7 @@ void sub_8033648(void) if (gReceivedRemoteLinkPlayers != 0 && (gBattleTypeFlags & BATTLE_TYPE_20)) { - sub_8011BD0(); + DestroyTask_RfuIdle(); for (i = 0; i < GetLinkPlayerCount(); i++) { if (GetBlockReceivedStatus() & gBitTable[i]) diff --git a/src/berry_blender.c b/src/berry_blender.c index 2a122541d..dfa378552 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -1500,7 +1500,7 @@ static void sub_80808D4(void) switch (sBerryBlenderData->mainState) { case 0: - sub_800B4C0(); + SetWirelessCommType0(); sub_8080588(); Blender_SetParticipantBerryData(0, gSpecialVar_ItemId); Blender_CopyBerryData(&sBerryBlenderData->blendedBerries[0], gSpecialVar_ItemId); diff --git a/src/berry_crush.c b/src/berry_crush.c index 6bc97fad0..da00f0d14 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -842,7 +842,7 @@ void StartBerryCrush(MainCallback callback) SetMainCallback2(callback); Rfu.unk_10 = 0; Rfu.unk_12 = 0; - Rfu.unk_ee = 1; + Rfu.errorState = 1; return; } @@ -853,7 +853,7 @@ void StartBerryCrush(MainCallback callback) SetMainCallback2(callback); Rfu.unk_10 = 0; Rfu.unk_12 = 0; - Rfu.unk_ee = 1; + Rfu.errorState = 1; return; } @@ -863,7 +863,7 @@ void StartBerryCrush(MainCallback callback) SetMainCallback2(callback); Rfu.unk_10 = 0; Rfu.unk_12 = 0; - Rfu.unk_ee = 1; + Rfu.errorState = 1; return; } diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index a4d6dd6c9..e5815e6ae 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -204,7 +204,7 @@ static void Task_ReturnToFieldWirelessLink(u8 taskId) if (!IsLinkTaskFinished()) { if (++task->data[1] > 1800) - sub_8011170(0x6000); + GetLinkmanErrorParams(0x6000); } else { diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 3f5bd8b69..fe1d10834 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -488,7 +488,7 @@ static void rfu_CB_configGameData(u8 reqCommand, u16 reqResult) for (i = 0; i < RFU_GAME_NAME_LENGTH; ++i) gRfuLinkStatus->my.gname[i] = *gname_uname_p++; ++gname_uname_p; - for (i = 0; i < RFU_USER_NAME_LENGTH; ++i) + for (i = 0; i < PLAYER_NAME_LENGTH + 1; ++i) gRfuLinkStatus->my.uname[i] = *gname_uname_p++; } rfu_STC_REQ_callback(reqCommand, reqResult); @@ -718,7 +718,7 @@ static void rfu_STC_readParentCandidateList(void) for (j = 0; j < RFU_GAME_NAME_LENGTH; ++j) target->gname[j] = *packet_p++; ++packet_p; - for (j = 0; j < RFU_USER_NAME_LENGTH; ++j) + for (j = 0; j < PLAYER_NAME_LENGTH + 1; ++j) target->uname[j] = *packet_p++; ++gRfuLinkStatus->findParentCount; } diff --git a/src/link.c b/src/link.c index 6647cda8c..3e4cc0c05 100644 --- a/src/link.c +++ b/src/link.c @@ -124,8 +124,8 @@ EWRAM_DATA struct { u8 lastSendQueueCount; u8 unk_06; } sLinkErrorBuffer = {}; -EWRAM_DATA u16 gUnknown_02022B08 = 0; -EWRAM_DATA void *gUnknown_02022B0C = NULL; +static EWRAM_DATA u16 sUnknown_02022B08 = 0; +static EWRAM_DATA void *sLinkErrorBgTilemapBuffer = NULL; // Static ROM declarations @@ -155,7 +155,7 @@ static void sub_800AE5C(void); static void CheckErrorStatus(void); static void CB2_PrintErrorMessage(void); static bool8 IsSioMultiMaster(void); -static void sub_800B4A4(void); +static void SetWirelessCommType0_Internal(void); static void DisableSerial(void); static void EnableSerial(void); static void CheckMasterOrSlave(void); @@ -172,29 +172,29 @@ static void SendRecvDone(void); // .rodata -ALIGNED(4) const u16 gWirelessLinkDisplayPal[] = INCBIN_U16("graphics/interface/wireless_link_display.gbapal"); -const u32 gWirelessLinkDisplayGfx[] = INCBIN_U32("graphics/interface/wireless_link_display.4bpp.lz"); -const u32 gWirelessLinkDisplayTilemap[] = INCBIN_U32("graphics/interface/wireless_link_display.bin.lz"); -const u16 gLinkTestDigitsPal[] = INCBIN_U16("graphics/interface/link_test_digits.gbapal"); -const u16 gLinkTestDigitsGfx[] = INCBIN_U16("graphics/interface/link_test_digits.4bpp"); -const u8 unkstring_82ed160[] = _("{HIGHLIGHT TRANSPARENT}{COLOR WHITE}"); -const u16 g2BlankTilesGfx[] = INCBIN_U16("graphics/interface/blank_1x2.4bpp"); -const struct BlockRequest gUnknown_082ED1A8[] = { +static const u16 sWirelessLinkDisplayPal[] = INCBIN_U16("graphics/interface/wireless_link_display.gbapal"); +static const u32 sWirelessLinkDisplayGfx[] = INCBIN_U32("graphics/interface/wireless_link_display.4bpp.lz"); +static const u32 sWirelessLinkDisplayTilemap[] = INCBIN_U32("graphics/interface/wireless_link_display.bin.lz"); +static const u16 sLinkTestDigitsPal[] = INCBIN_U16("graphics/interface/link_test_digits.gbapal"); +static const u16 sLinkTestDigitsGfx[] = INCBIN_U16("graphics/interface/link_test_digits.4bpp"); +static const u8 sUnusedTransparentWhite[] = _("{HIGHLIGHT TRANSPARENT}{COLOR WHITE}"); +static const u16 s2BlankTilesGfx[] = INCBIN_U16("graphics/interface/blank_1x2.4bpp"); +static const struct BlockRequest sBlockRequests[] = { {gBlockSendBuffer, 200}, {gBlockSendBuffer, 200}, {gBlockSendBuffer, 100}, {gBlockSendBuffer, 220}, {gBlockSendBuffer, 40} }; -const u8 gBGControlRegs[] = { +static const u8 sBGControlRegs[] = { REG_OFFSET_BG0CNT, REG_OFFSET_BG1CNT, REG_OFFSET_BG2CNT, REG_OFFSET_BG3CNT }; -const char gASCIIGameFreakInc[] = "GameFreak inc."; -const char gASCIITestPrint[] = "TEST PRINT\nP0\nP1\nP2\nP3"; -const struct BgTemplate gUnknown_082ED1FC[] = { +static const char sASCIIGameFreakInc[] = "GameFreak inc."; +static const char sASCIITestPrint[] = "TEST PRINT\nP0\nP1\nP2\nP3"; +static const struct BgTemplate sLinkErrorBgTemplates[] = { { .bg = 0, .charBaseIndex = 2, @@ -207,15 +207,36 @@ const struct BgTemplate gUnknown_082ED1FC[] = { .priority = 1 } }; -const struct WindowTemplate gUnknown_082ED204[] = { - {0x00, 0x00, 0x00, 0x1E, 0x05, 0x0F, 0x0002}, - {0x00, 0x00, 0x06, 0x1E, 0x07, 0x0F, 0x0098}, - {0x00, 0x00, 0x0D, 0x1E, 0x07, 0x0F, 0x016A}, - DUMMY_WIN_TEMPLATE +static const struct WindowTemplate sLinkErrorWindowTemplates[] = { + { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 0, + .width = 30, + .height = 5, + .paletteNum = 15, + .baseBlock = 0x002 + }, { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 6, + .width = 30, + .height = 7, + .paletteNum = 15, + .baseBlock = 0x098 + }, { + .bg = 0, + .tilemapLeft = 0, + .tilemapTop = 13, + .width = 30, + .height = 7, + .paletteNum = 15, + .baseBlock = 0x16A + }, DUMMY_WIN_TEMPLATE }; static const u8 sTextColors[] = { TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY }; -static const u8 sUnused_082ED224[] = {0x00, 0xff, 0xfe, 0xff, 0x00}; +static const u8 sUnused_082ED224[] = {0x00, 0xFF, 0xFE, 0xFF, 0x00}; // .text @@ -229,7 +250,7 @@ bool8 IsWirelessAdapterConnected(void) rfu_waitREQComplete(); return TRUE; } - sub_800B4A4(); + SetWirelessCommType0_Internal(); CloseLink(); RestoreSerialTimer3IntrHandlers(); return FALSE; @@ -242,8 +263,8 @@ void Task_DestroySelf(u8 taskId) static void InitLinkTestBG(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charBaseBlock, u16 a4) { - LoadPalette(gLinkTestDigitsPal, paletteNum * 16, 0x20); - DmaCopy16(3, gLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock) + (16 * a4), sizeof gLinkTestDigitsGfx); + LoadPalette(sLinkTestDigitsPal, paletteNum * 16, 0x20); + DmaCopy16(3, sLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock) + (16 * a4), sizeof sLinkTestDigitsGfx); gLinkTestBGInfo.screenBaseBlock = screenBaseBlock; gLinkTestBGInfo.paletteNum = paletteNum; gLinkTestBGInfo.dummy_8 = a4; @@ -265,12 +286,12 @@ static void InitLinkTestBG(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charB void sub_80094EC(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charBaseBlock) { - LoadPalette(gLinkTestDigitsPal, paletteNum * 16, 0x20); - DmaCopy16(3, gLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock), sizeof gLinkTestDigitsGfx); + LoadPalette(sLinkTestDigitsPal, paletteNum * 16, 0x20); + DmaCopy16(3, sLinkTestDigitsGfx, (u16 *)BG_CHAR_ADDR(charBaseBlock), sizeof sLinkTestDigitsGfx); gLinkTestBGInfo.screenBaseBlock = screenBaseBlock; gLinkTestBGInfo.paletteNum = paletteNum; gLinkTestBGInfo.dummy_8 = 0; - SetGpuReg(gBGControlRegs[bgNum], BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock)); + SetGpuReg(sBGControlRegs[bgNum], BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock)); } void LinkTestScreen(void) @@ -536,8 +557,8 @@ static void ProcessRecvCmds(u8 unused) InitLocalLinkPlayer(); block = &gLocalLinkPlayerBlock; block->linkPlayer = gLocalLinkPlayer; - memcpy(block->magic1, gASCIIGameFreakInc, sizeof(block->magic1) - 1); - memcpy(block->magic2, gASCIIGameFreakInc, sizeof(block->magic2) - 1); + memcpy(block->magic1, sASCIIGameFreakInc, sizeof(block->magic1) - 1); + memcpy(block->magic2, sASCIIGameFreakInc, sizeof(block->magic2) - 1); InitBlockSend(block, sizeof(*block)); break; } @@ -602,8 +623,8 @@ static void ProcessRecvCmds(u8 unused) linkPlayer->progressFlags = 0; } sub_800B524(linkPlayer); - if (strcmp(block->magic1, gASCIIGameFreakInc) != 0 - || strcmp(block->magic2, gASCIIGameFreakInc) != 0) + if (strcmp(block->magic1, sASCIIGameFreakInc) != 0 + || strcmp(block->magic2, sASCIIGameFreakInc) != 0) { SetMainCallback2(CB2_LinkError); } @@ -629,7 +650,7 @@ static void ProcessRecvCmds(u8 unused) sub_800A418(); break; case LINKCMD_0xCCCC: - SendBlock(0, gUnknown_082ED1A8[gRecvCmds[i][1]].address, gUnknown_082ED1A8[gRecvCmds[i][1]].size); + SendBlock(0, sBlockRequests[gRecvCmds[i][1]].address, sBlockRequests[gRecvCmds[i][1]].size); break; case LINKCMD_SEND_HELD_KEYS_2: gLinkPartnersHeldKeys[i] = gRecvCmds[i][1]; @@ -709,7 +730,7 @@ void sub_8009F18(void) { if (gWirelessCommType) { - sub_800F804(); + StartSendingKeysToRfu(); } gLinkCallback = sub_8009F70; } @@ -763,7 +784,7 @@ u8 GetLinkPlayerCount(void) { if (gWirelessCommType) { - return sub_80104F4(); + return Rfu_GetLinkPlayerCount(); } return EXTRACT_PLAYER_COUNT(gLinkStatus); } @@ -1046,7 +1067,7 @@ u8 GetMultiplayerId(void) { if (gWirelessCommType == TRUE) { - return rfu_get_multiplayer_id(); + return Rfu_GetMultiplayerId(); } return SIO_MULTI_CNT->id; } @@ -1063,7 +1084,7 @@ bool8 SendBlock(u8 unused, const void *src, u16 size) { if (gWirelessCommType == TRUE) { - return sub_800FE84(src, size); + return Rfu_InitBlockSend(src, size); } return InitBlockSend(src, size); } @@ -1096,7 +1117,7 @@ u8 GetBlockReceivedStatus(void) { if (gWirelessCommType == TRUE) { - return sub_800FCD8(); + return Rfu_GetBlockReceivedStatus(); } return (gBlockReceivedStatus[3] << 3) | (gBlockReceivedStatus[2] << 2) | (gBlockReceivedStatus[1] << 1) | (gBlockReceivedStatus[0] << 0); } @@ -1105,7 +1126,7 @@ static void SetBlockReceivedFlag(u8 who) { if (gWirelessCommType == TRUE) { - sub_800F6FC(who); + Rfu_SetBlockReceivedFlag(who); } else { @@ -1121,7 +1142,7 @@ void ResetBlockReceivedFlags(void) { for (i = 0; i < MAX_RFU_PLAYERS; i++) { - sub_800F728(i); + Rfu_ResetBlockReceivedFlag(i); } } else @@ -1137,7 +1158,7 @@ void ResetBlockReceivedFlag(u8 who) { if (gWirelessCommType == TRUE) { - sub_800F728(who); + Rfu_ResetBlockReceivedFlag(who); } else if (gBlockReceivedStatus[who]) { @@ -1264,7 +1285,7 @@ static void Task_PrintTestData(u8 taskId) char sp[32]; int i; - strcpy(sp, gASCIITestPrint); + strcpy(sp, sASCIITestPrint); LinkTest_prntstr(sp, 5, 2); LinkTest_prnthex(gShouldAdvanceLinkState, 2, 1, 2); LinkTest_prnthex(gLinkStatus, 15, 1, 8); @@ -1453,7 +1474,7 @@ void sub_800AC34(void) { if (gLinkCallback != NULL) { - gUnknown_02022B08++; + sUnknown_02022B08++; } else { @@ -1508,7 +1529,7 @@ void sub_800AD10(void) { if (gLinkCallback != NULL) { - gUnknown_02022B08++; + sUnknown_02022B08++; } else { @@ -1650,14 +1671,14 @@ void CB2_LinkError(void) { gWirelessCommType = 3; } - sub_800E604(); + ResetLinkRfuGFLayer(); } SetVBlankCallback(sub_80096BC); ResetBgsAndClearDma3BusyFlags(0); - InitBgsFromTemplates(0, gUnknown_082ED1FC, 2); - gUnknown_02022B0C = tilemapBuffer = malloc(0x800); + InitBgsFromTemplates(0, sLinkErrorBgTemplates, ARRAY_COUNT(sLinkErrorBgTemplates)); + sLinkErrorBgTilemapBuffer = tilemapBuffer = malloc(0x800); SetBgTilemapBuffer(1, tilemapBuffer); - if (InitWindows(gUnknown_082ED204)) + if (InitWindows(sLinkErrorWindowTemplates)) { DeactivateAllTextPrinters(); reset_temp_tile_data_buffers(); @@ -1683,11 +1704,11 @@ void CB2_LinkError(void) static void sub_800B080(void) { - LoadBgTiles(0, g2BlankTilesGfx, 0x20, 0); - DecompressAndLoadBgGfxUsingHeap(1, gWirelessLinkDisplayGfx, FALSE, 0, 0); - CopyToBgTilemapBuffer(1, gWirelessLinkDisplayTilemap, 0, 0); + LoadBgTiles(0, s2BlankTilesGfx, 0x20, 0); + DecompressAndLoadBgGfxUsingHeap(1, sWirelessLinkDisplayGfx, FALSE, 0, 0); + CopyToBgTilemapBuffer(1, sWirelessLinkDisplayTilemap, 0, 0); CopyBgTilemapBufferToVram(1); - LoadPalette(gWirelessLinkDisplayPal, 0, 0x20); + LoadPalette(sWirelessLinkDisplayPal, 0, 0x20); FillWindowPixelBuffer(0, PIXEL_FILL(0)); FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized3(0, 3, 2, 6, sTextColors, 0, gText_CommErrorEllipsis); @@ -1700,7 +1721,7 @@ static void sub_800B080(void) static void sub_800B138(void) { - LoadBgTiles(0, g2BlankTilesGfx, 0x20, 0); + LoadBgTiles(0, s2BlankTilesGfx, 0x20, 0); FillWindowPixelBuffer(1, PIXEL_FILL(0)); FillWindowPixelBuffer(2, PIXEL_FILL(0)); AddTextPrinterParameterized3(1, 3, 2, 0, sTextColors, 0, gText_CommErrorCheckConnections); @@ -1813,12 +1834,12 @@ void sub_800B348(void) InitLocalLinkPlayer(); block = &gLocalLinkPlayerBlock; block->linkPlayer = gLocalLinkPlayer; - memcpy(block->magic1, gASCIIGameFreakInc, sizeof(block->magic1) - 1); - memcpy(block->magic2, gASCIIGameFreakInc, sizeof(block->magic2) - 1); + memcpy(block->magic1, sASCIIGameFreakInc, sizeof(block->magic1) - 1); + memcpy(block->magic2, sASCIIGameFreakInc, sizeof(block->magic2) - 1); memcpy(gBlockSendBuffer, block, sizeof(*block)); } -void sub_800B3A4(u32 who) +void LinkPlayerFromBlock(u32 who) { u8 who_ = who; struct LinkPlayerBlock *block; @@ -1828,7 +1849,7 @@ void sub_800B3A4(u32 who) player = &gLinkPlayers[who_]; *player = block->linkPlayer; sub_800B524(player); - if (strcmp(block->magic1, gASCIIGameFreakInc) != 0 || strcmp(block->magic2, gASCIIGameFreakInc) != 0) + if (strcmp(block->magic1, sASCIIGameFreakInc) != 0 || strcmp(block->magic2, sASCIIGameFreakInc) != 0) { SetMainCallback2(CB2_LinkError); } @@ -1871,7 +1892,7 @@ void SetWirelessCommType1(void) } } -static void sub_800B4A4(void) +static void SetWirelessCommType0_Internal(void) { if (gReceivedRemoteLinkPlayers == 0) { @@ -1879,7 +1900,7 @@ static void sub_800B4A4(void) } } -void sub_800B4C0(void) +void SetWirelessCommType0(void) { if (gReceivedRemoteLinkPlayers == 0) { diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 0d69f9281..05b624fe9 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -19,34 +19,76 @@ #include "save.h" #include "mystery_gift.h" -extern u16 gHeldKeyCodeToSend; +struct SioInfo +{ + char magic[15]; // PokemonSioInfo + u8 playerCount; + u8 linkPlayerIdx[RFU_CHILD_MAX]; + struct LinkPlayer linkPlayers[MAX_RFU_PLAYERS]; + u8 filler[92]; +}; u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4]; -struct UnkRfuStruct_2 Rfu; +struct GFRfuManager Rfu; BSS_DATA u8 gUnknown_03000D78[8]; -BSS_DATA u8 gUnknown_03000D80[16]; -BSS_DATA u16 gUnknown_03000D90[8]; +BSS_DATA u8 sResendBlock8[16]; +BSS_DATA u16 sResendBlock16[8]; -EWRAM_DATA struct GFtgtGname gUnknown_02022B14 = {}; -EWRAM_DATA ALIGNED(2) u8 gUnknown_02022B22[RFU_USER_NAME_LENGTH] = {}; -EWRAM_DATA INIT_PARAM gUnknown_02022B2C = {}; +EWRAM_DATA struct GFtgtGname gHostRFUtgtGnameBuffer = {}; +EWRAM_DATA ALIGNED(2) u8 gHostRFUtgtUnameBuffer[PLAYER_NAME_LENGTH + 1] = {}; +EWRAM_DATA INIT_PARAM sRfuReqConfig = {}; EWRAM_DATA struct UnkLinkRfuStruct_02022B44 gUnknown_02022B44 = {}; -// Static ROM declarations +static void ResetSendDataManager(struct RfuBlockSend *); +static void sub_800EAB4(void); +static void sub_800EAFC(void); +static void sub_800EDBC(u16); +static void sub_800F048(void); +static void Task_ExchangeLinkPlayers(u8); +static void RfuHandleReceiveCommand(u8); +static void CallRfuFunc(void); +static void RfuPrepareSendBuffer(u16); +static void HandleBlockSend(void); +static void SendNextBlock(void); +static void SendLastBlock(void); +static u8 GetPartnerIndexByNameAndTrainerID(const u8 *, u16); +static void sub_8010750(void); +static s32 sub_80107A0(void); +static void sub_801084C(u8); +static void sub_80109E8(u16); +static void ValidateAndReceivePokemonSioInfo(void *); +static void sub_8010D0C(u8); +static void sub_80115EC(s32); +static void sub_8011BF8(void); +static void RfuReqDisconnectSlot(u32); +static void sub_8011E94(u32, u32); +static void sub_801209C(u8); +static void Debug_PrintEmpty(void); +static void Task_Idle(u8); -// .rodata +static const INIT_PARAM sRfuReqConfigTemplate = { + .maxMFrame = 4, + .MC_TimerCount = 32, + .availSlot_flag = 0, + .mboot_flag = 0, + .serialNo = 2, + .gameName = (void *)&gHostRFUtgtGnameBuffer, + .userName = gHostRFUtgtUnameBuffer, + .fastSearchParent_flag = TRUE, + .linkRecovery_enable = FALSE, + .linkRecovery_period = 600, + .NI_failCounter_limit = 0x12c +}; -const INIT_PARAM gUnknown_082ED608 = { - 0x04, 0x20, 0x00, 0x00, 0x02, - (u8 *)&gUnknown_02022B14, - gUnknown_02022B22, - 0x01, 0x00, 0x258, 0x12c +static const u8 sAvailSlots[] = { + [1] = AVAIL_SLOT1, + [2] = AVAIL_SLOT2, + [3] = AVAIL_SLOT3, + [4] = AVAIL_SLOT4 }; -const u8 gUnknown_082ED620[] = { - 0, 3, 2, 1, 0 -}; -const u32 gUnknown_082ED628[] = { + +static const u32 sAllBlocksReceived[] = { 0x000000, 0x000001, 0x000003, @@ -73,35 +115,43 @@ const u32 gUnknown_082ED628[] = { 0x7fffff, 0xffffff }; -const u8 gUnknown_082ED68C[] = { + +static const u8 sUnknown_082ED68C[] = { 0, 0, 1, 1, 2, 2, 2, 2, 3 }; -const u8 gUnknown_082ED695[] = { + +static const u8 sUnknown_082ED695[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; -const u8 gUnknown_082ED6A5[] = { + +static const u8 sUnknown_082ED6A5[] = { 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 }; -const struct { + +static const struct { u8 *buffer; u32 size; -} gUnknown_082ED6B8[] = { +} sUnknown_082ED6B8[] = { { gBlockSendBuffer, 200 }, { gBlockSendBuffer, 200 }, { gBlockSendBuffer, 100 }, { gBlockSendBuffer, 220 }, { gBlockSendBuffer, 40 } }; -const u16 gUnknown_082ED6E0[] = { - 0x0002, 0x7f7d, 0x0000, 0xFFFF + +static const u16 sAcceptedSerialNos[] = { + 0x0002, // Pokemon FR/LG/EM + 0x7f7d, + 0x0000, + 0xFFFF }; -const char sUnref_082ED6E8[][15] = { +static const char sASCII_RfuCmds[][15] = { "RFU WAIT", "RFU BOOT", "RFU ERROR", @@ -114,75 +164,79 @@ const char sUnref_082ED6E8[][15] = { "RFU SEND ERR", "RFU CP POLL" }; -const char sUnref_082ED6E9[][16] = { + +static const char sASCII_RecoverCmds[][16] = { " ", "RECOVER START ", "DISSCONECT ", "RECOVER SUUSES", "RECOVER FAILED" }; -const TaskFunc gUnknown_082ED7E0[] = { + +static const TaskFunc sUnknown_082ED7E0[] = { sub_801084C, - sub_8010AAC, + Task_ExchangeLinkPlayers, sub_8010D0C }; -const char gUnknown_082ED7EC[] = "PokemonSioInfo"; -const char gUnknown_082ED7FC[] = "LINK LOSS DISCONNECT!"; -const char gUnknown_082ED814[] = "LINK LOSS RECOVERY NOW"; -ALIGNED(4) const char gUnknown_082ED82C[31] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0x00}; -const char gUnknown_082ED84B[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0x00}; -const char gUnknown_082ED85B[9] = {' ',' ',' ',' ',' ',' ',' ',' ',0x00}; -ALIGNED(4) const char gUnknown_082ED864[2] = {' ',0x00}; -const char gUnknown_082ED866[2] = {'*',0x00}; -const char gUnknown_082ED868[8] = "NOWSLOT"; -const char gUnknown_082ED870[12] = " "; -const char gUnknown_082ED87C[12] = "CLOCK DRIFT"; -const char gUnknown_082ED888[12] = "BUSY SEND "; -const char gUnknown_082ED894[12] = "CMD REJECT "; -const char gUnknown_082ED8A0[12] = "CLOCK SLAVE"; -const char gUnknown_082ED8A8[3][8] = { +static const char sASCII_PokemonSioInfo[] = "PokemonSioInfo"; +static const char sASCII_LinkLossDisconnect[] = "LINK LOSS DISCONNECT!"; +static const char sASCII_LinkLossRecoveryNow[] = "LINK LOSS RECOVERY NOW"; +ALIGNED(4) static const char sASCII_30Commas[31] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}; +static const char sASCII_15Commas[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}; +static const char sASCII_8Commas[9] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'}; +ALIGNED(4) static const char sASCII_Space[2] = {' ','\0'}; +static const char sASCII_Asterisk[2] = {'*','\0'}; +static const char sASCII_NowSlot[8] = "NOWSLOT"; + +static const char sASCII_ClockCmds[][12] = { + " ", + "CLOCK DRIFT", + "BUSY SEND ", + "CMD REJECT ", + "CLOCK SLAVE" +}; + +static const char sASCII_ChildParentSearch[3][8] = { "CHILD ", "PARENT", "SEARCH" }; -// .text - -void nullsub_5(const void *unused_0, u8 unused_1, u8 unused_2) -{ - // debug? -} - -void nullsub_13(u16 unused_0, u8 unused_1, u8 unused_2, u8 unused_3) +static void Debug_PrintString(const void *str, u8 x, u8 y) { } -void sub_800E604(void) +static void Debug_PrintNum(u16 num, u8 x, u8 y, u8 numDigits) +{ + +} + +void ResetLinkRfuGFLayer(void) { s32 i; - u8 unk_ee_bak = Rfu.unk_ee; + u8 errorState = Rfu.errorState; CpuFill16(0, &Rfu, sizeof Rfu); - Rfu.unk_ee = unk_ee_bak; - Rfu.unk_0c = 0xFF; - if (Rfu.unk_ee != 4) + Rfu.errorState = errorState; + Rfu.parentChild = 0xFF; + if (Rfu.errorState != 4) { - Rfu.unk_ee = 0; + Rfu.errorState = 0; } for (i = 0; i < 5; i++) { - sub_800FCC4(Rfu.unk_80 + i); + ResetSendDataManager(Rfu.unk_80 + i); } - sub_800FCC4(&Rfu.unk_6c); - sub_800D6C8(&Rfu.unk_124); - sub_800D724(&Rfu.unk_9e8); + ResetSendDataManager(&Rfu.unk_6c); + sub_800D6C8(&Rfu.recvQueue); + sub_800D724(&Rfu.sendQueue); CpuFill16(0, gSendCmd, sizeof gSendCmd); CpuFill16(0, gRecvCmds, sizeof gRecvCmds); CpuFill16(0, gLinkPlayers, sizeof gLinkPlayers); } -void sub_800E6D0(void) +void InitRFU(void) { IntrFunc serialIntr = gIntrTable[1]; IntrFunc timerIntr = gIntrTable[2]; @@ -201,53 +255,53 @@ void sub_800E700(void) { gLinkType = 0; sub_800AAF4(); - sub_80111B0(0); - sub_800E604(); + sub_80111B0(FALSE); + ResetLinkRfuGFLayer(); rfu_setTimerInterrupt(3, gIntrTable + 2); } } -void sub_800E748(u8 taskId) +static void Task_LinkLeaderSearchForChildren(u8 taskId) { sub_8010750(); - switch (Rfu.unk_04) + switch (Rfu.state) { - case 0: - rfu_LMAN_initializeRFU(&gUnknown_02022B2C); - Rfu.unk_04 = 1; - gTasks[taskId].data[1] = 1; - break; - case 1: - break; - case 2: - rfu_LMAN_establishConnection(Rfu.unk_0c, 0, 240, (u16 *)gUnknown_082ED6E0); - Rfu.unk_04 = 3; - gTasks[taskId].data[1] = 6; - break; - case 3: - break; - case 4: - rfu_LMAN_stopManager(FALSE); - Rfu.unk_04 = 5; - break; - case 5: - break; - case 18: - Rfu.unk_cdb = 0; - rfu_LMAN_setMSCCallback(sub_800EDBC); - sub_800EAB4(); - sub_800EAFC(); - Rfu.unk_04 = 20; - gTasks[taskId].data[1] = 8; - CreateTask(sub_801084C, 5); - DestroyTask(taskId); - break; + case 0: + rfu_LMAN_initializeRFU(&sRfuReqConfig); + Rfu.state = 1; + gTasks[taskId].data[1] = 1; + break; + case 1: + break; + case 2: + rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); + Rfu.state = 3; + gTasks[taskId].data[1] = 6; + break; + case 3: + break; + case 4: + rfu_LMAN_stopManager(FALSE); + Rfu.state = 5; + break; + case 5: + break; + case 18: + Rfu.unk_cdb = 0; + rfu_LMAN_setMSCCallback(sub_800EDBC); + sub_800EAB4(); + sub_800EAFC(); + Rfu.state = 20; + gTasks[taskId].data[1] = 8; + CreateTask(sub_801084C, 5); + DestroyTask(taskId); + break; } } s32 sub_800E87C(u8 idx) { - return gUnknown_082ED6A5[idx]; + return sUnknown_082ED6A5[idx]; } void sub_800E88C(s32 r2, s32 r5) @@ -258,185 +312,185 @@ void sub_800E88C(s32 r2, s32 r5) s32 r6 = 0; if (r5 == -1) { - for (i = 0; i < 4; r2 >>= 1, i++) + for (i = 0; i < RFU_CHILD_MAX; r2 >>= 1, i++) { if (r2 & 1) { - Rfu.unk_cde[i] = r4; + Rfu.linkPlayerIdx[i] = r4; r4++; } } } else { - for (i = 0; i < 4; r1 >>= 1, i++) + for (i = 0; i < RFU_CHILD_MAX; r1 >>= 1, i++) { if (!(r1 & 1)) { - Rfu.unk_cde[i] = 0; + Rfu.linkPlayerIdx[i] = 0; } } - for (r4 = 4; r4 != 0; r4--) + for (r4 = RFU_CHILD_MAX; r4 != 0; r4--) { - for (i = 0; i < 4 && Rfu.unk_cde[i] != r4; i++); - if (i == 4) + for (i = 0; i < RFU_CHILD_MAX && Rfu.linkPlayerIdx[i] != r4; i++); + if (i == RFU_CHILD_MAX) { r6 = r4; } } - for (r5 &= ~r2, i = 0; i < 4; r5 >>= 1, i++) + for (r5 &= ~r2, i = 0; i < RFU_CHILD_MAX; r5 >>= 1, i++) { if (r5 & 1) { - Rfu.unk_cde[i] = r6++; + Rfu.linkPlayerIdx[i] = r6++; } } } } -void sub_800E94C(u8 taskId) +static void Task_JoinGroupSearchForParent(u8 taskId) { - switch (Rfu.unk_04) + switch (Rfu.state) { - case 0: - rfu_LMAN_initializeRFU((INIT_PARAM *)&gUnknown_082ED608); - Rfu.unk_04 = 1; - gTasks[taskId].data[1] = 1; - break; - case 1: + case 0: + rfu_LMAN_initializeRFU((INIT_PARAM *)&sRfuReqConfigTemplate); + Rfu.state = 1; + gTasks[taskId].data[1] = 1; + break; + case 1: + break; + case 6: + rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); + Rfu.state = 7; + gTasks[taskId].data[1] = 7; + break; + case 7: + break; + case 9: + gTasks[taskId].data[1] = 10; + break; + case 11: + switch (sub_80107A0()) + { + case 5: + Rfu.state = 12; break; case 6: - rfu_LMAN_establishConnection(Rfu.unk_0c, 0, 0xf0, (u16 *)gUnknown_082ED6E0); - Rfu.unk_04 = 7; - gTasks[taskId].data[1] = 7; - break; - case 7: - break; case 9: - gTasks[taskId].data[1] = 10; - break; - case 11: - switch (sub_80107A0()) - { - case 5: - Rfu.unk_04 = 12; - break; - case 6: - case 9: - rfu_LMAN_requestChangeAgbClockMaster(); - Rfu.unk_ce4 = 2; - DestroyTask(taskId); - break; - } - break; - case 12: - { - u8 r5 = 1 << Rfu.unk_c3e; - rfu_clearSlot(12, Rfu.unk_c3e); - rfu_setRecvBuffer(16, Rfu.unk_c3e, Rfu.unk_c3f, 70); - rfu_UNI_setSendData(r5, Rfu.unk_4c, 14); - gTasks[taskId].data[1] = 8; + rfu_LMAN_requestChangeAgbClockMaster(); + Rfu.unk_ce4 = 2; DestroyTask(taskId); - if (gUnknown_02022B44.unk_0f == 0) - { - sub_801227C(); - gUnknown_02022B44.unk_0f++; - } - CreateTask(sub_801084C, 5); break; } + break; + case 12: + { + u8 bmChildSlot = 1 << Rfu.childSlot; + rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.childSlot); + rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70); + rfu_UNI_setSendData(bmChildSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)); + gTasks[taskId].data[1] = 8; + DestroyTask(taskId); + if (gUnknown_02022B44.unk_0f == 0) + { + Debug_PrintEmpty(); + gUnknown_02022B44.unk_0f++; + } + CreateTask(sub_801084C, 5); + break; + } } } -void sub_800EAB4(void) +static void sub_800EAB4(void) { u8 i; - u8 r5 = lman.acceptSlot_flag; - for (i = 0; i < 4; i++) + u8 acceptSlot = lman.acceptSlot_flag; + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (r5 & 1) + if (acceptSlot & 1) { - rfu_setRecvBuffer(16, i, Rfu.unk_14[i], 14); - rfu_clearSlot(3, i); + rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], 14); + rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, i); } - r5 >>= 1; + acceptSlot >>= 1; } } -void sub_800EAFC(void) +static void sub_800EAFC(void) { - u8 r5 = lman.acceptSlot_flag; - rfu_UNI_setSendData(r5, Rfu.unk_c87, 70); - Rfu.unk_cda = sub_800E87C(r5); - Rfu.unk_ce2 = r5; - sub_800E88C(r5, -1); - Rfu.unk_0c = 1; + u8 acceptSlot = lman.acceptSlot_flag; + rfu_UNI_setSendData(acceptSlot, Rfu.recvCmds, 70); + Rfu.unk_cda = sub_800E87C(acceptSlot); + Rfu.unk_ce2 = acceptSlot; + sub_800E88C(acceptSlot, -1); + Rfu.parentChild = MODE_PARENT; } -void sub_800EB44(u8 taskId) +static void Task_LinkRfu_UnionRoomListen(u8 taskId) { - if (GetHostRFUtgtGname()->activity == 0x54 && RfuGetErrorStatus() == 4) + if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetErrorStatus() == 4) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); RfuSetErrorStatus(0, 0); } - switch (Rfu.unk_04) + switch (Rfu.state) { - case 0: - rfu_LMAN_initializeRFU(&gUnknown_02022B2C); - Rfu.unk_04 = 1; - gTasks[taskId].data[1] = 1; - break; - case 1: - break; - case 17: - rfu_LMAN_establishConnection(2, 0, 240, (u16 *)gUnknown_082ED6E0); - rfu_LMAN_setMSCCallback(sub_800ED34); - Rfu.unk_04 = 18; - break; - case 18: - break; - case 13: - if (rfu_UNI_setSendData(1 << Rfu.unk_c3e, Rfu.unk_4c, 14) == 0) - { - Rfu.unk_0c = 0; - DestroyTask(taskId); - if (gTasks[taskId].data[7]) - { - CreateTask(sub_8010D0C, 1); - } - else - { - CreateTask(sub_801084C, 5); - } - } - break; - case 14: - rfu_LMAN_stopManager(0); - Rfu.unk_04 = 15; - break; - case 15: - break; - case 16: - Rfu.unk_cdb = 0; - rfu_LMAN_setMSCCallback(sub_800EDBC); - UpdateGameData_GroupLockedIn(TRUE); - sub_800EAB4(); - sub_800EAFC(); - Rfu.unk_04 = 20; - gTasks[taskId].data[1] = 8; - Rfu.unk_0c = 1; - CreateTask(sub_801084C, 5); - Rfu.unk_ce8 = 1; + case 0: + rfu_LMAN_initializeRFU(&sRfuReqConfig); + Rfu.state = 1; + gTasks[taskId].data[1] = 1; + break; + case 1: + break; + case 17: + rfu_LMAN_establishConnection(2, 0, 240, (u16 *)sAcceptedSerialNos); + rfu_LMAN_setMSCCallback(sub_800ED34); + Rfu.state = 18; + break; + case 18: + break; + case 13: + if (rfu_UNI_setSendData(1 << Rfu.childSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)) == 0) + { + Rfu.parentChild = MODE_CHILD; DestroyTask(taskId); - break; + if (gTasks[taskId].data[7]) + { + CreateTask(sub_8010D0C, 1); + } + else + { + CreateTask(sub_801084C, 5); + } + } + break; + case 14: + rfu_LMAN_stopManager(0); + Rfu.state = 15; + break; + case 15: + break; + case 16: + Rfu.unk_cdb = 0; + rfu_LMAN_setMSCCallback(sub_800EDBC); + UpdateGameData_GroupLockedIn(TRUE); + sub_800EAB4(); + sub_800EAFC(); + Rfu.state = 20; + gTasks[taskId].data[1] = 8; + Rfu.parentChild = MODE_PARENT; + CreateTask(sub_801084C, 5); + Rfu.unk_ce8 = TRUE; + DestroyTask(taskId); + break; } } void LinkRfu_CreateConnectionAsParent(void) { - rfu_LMAN_establishConnection(1, 0, 240, (u16 *)gUnknown_082ED6E0); + rfu_LMAN_establishConnection(MODE_PARENT, 0, 240, (u16 *)sAcceptedSerialNos); } void LinkRfu_StopManagerBeforeEnteringChat(void) @@ -448,25 +502,25 @@ void sub_800ED34(u16 unused) { s32 i; - for (i = 0; i < 14; i++) + for (i = 0; i < (int)ARRAY_COUNT(Rfu.unk_4c); i++) { Rfu.unk_4c[i] = 0; } rfu_REQ_recvData(); rfu_waitREQComplete(); - if (gRfuSlotStatusUNI[Rfu.unk_c3e]->recv.newDataFlag) + if (gRfuSlotStatusUNI[Rfu.childSlot]->recv.newDataFlag) { Rfu.unk_cd0++; - sub_800D7D8(&Rfu.unk_124, Rfu.unk_c3f); + sub_800D7D8(&Rfu.recvQueue, Rfu.unk_c3f); gUnknown_02022B44.unk_06++; sub_800F048(); - rfu_UNI_readySendData(Rfu.unk_c3e); - rfu_UNI_clearRecvNewDataFlag(Rfu.unk_c3e); + rfu_UNI_readySendData(Rfu.childSlot); + rfu_UNI_clearRecvNewDataFlag(Rfu.childSlot); } - rfu_LMAN_REQ_sendData(1); + rfu_LMAN_REQ_sendData(TRUE); } -void sub_800EDBC(u16 unused) +static void sub_800EDBC(u16 unused) { Rfu.unk_cdb = 1; } @@ -476,66 +530,66 @@ void LinkRfu_Shutdown(void) u8 i; rfu_LMAN_powerDownRFU(); - if (Rfu.unk_0c == 1) + if (Rfu.parentChild == MODE_PARENT) { - if (FuncIsActiveTask(sub_800E748) == TRUE) + if (FuncIsActiveTask(Task_LinkLeaderSearchForChildren) == TRUE) { - DestroyTask(Rfu.unk_67); - sub_800E604(); + DestroyTask(Rfu.searchTaskId); + ResetLinkRfuGFLayer(); } } - else if (Rfu.unk_0c == 0) + else if (Rfu.parentChild == MODE_CHILD) { - if (FuncIsActiveTask(sub_800E94C) == TRUE) + if (FuncIsActiveTask(Task_JoinGroupSearchForParent) == TRUE) { - DestroyTask(Rfu.unk_67); - sub_800E604(); + DestroyTask(Rfu.searchTaskId); + ResetLinkRfuGFLayer(); } } - else if (Rfu.unk_0c == 2) + else if (Rfu.parentChild == 2) { - if (FuncIsActiveTask(sub_800EB44) == TRUE) + if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) { - DestroyTask(Rfu.unk_67); - sub_800E604(); + DestroyTask(Rfu.searchTaskId); + ResetLinkRfuGFLayer(); } } - for (i = 0; i < 3; i++) + for (i = 0; i < ARRAY_COUNT(sUnknown_082ED7E0); i++) { - if (FuncIsActiveTask(gUnknown_082ED7E0[i]) == TRUE) + if (FuncIsActiveTask(sUnknown_082ED7E0[i]) == TRUE) { - DestroyTask(FindTaskIdByFunc(gUnknown_082ED7E0[i])); + DestroyTask(FindTaskIdByFunc(sUnknown_082ED7E0[i])); } } } -void sub_800EE78(void) +static void CreateTask_LinkLeaderSearchForChildren(void) { - Rfu.unk_67 = CreateTask(sub_800E748, 1); + Rfu.searchTaskId = CreateTask(Task_LinkLeaderSearchForChildren, 1); } -bool8 sub_800EE94(void) +static bool8 sub_800EE94(void) { - if (Rfu.unk_04 == 7 && Rfu.unk_ccd) + if (Rfu.state == 7 && Rfu.parentId) { return TRUE; } return FALSE; } -bool32 sub_800EEBC(void) +static bool32 IsParentSuccessfullyReconnected(void) { - if (Rfu.unk_04 == 7 && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240)) + if (Rfu.state == 7 && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240)) { - Rfu.unk_04 = 9; + Rfu.state = 9; return TRUE; } return FALSE; } -void sub_800EF00(void) +static void CreateTask_JoinGroupSearchForParent(void) { - Rfu.unk_67 = CreateTask(sub_800E94C, 1); + Rfu.searchTaskId = CreateTask(Task_JoinGroupSearchForParent, 1); } bool8 LmanAcceptSlotFlagIsNotZero(void) @@ -549,15 +603,15 @@ bool8 LmanAcceptSlotFlagIsNotZero(void) void LinkRfu_StopManagerAndFinalizeSlots(void) { - Rfu.unk_04 = 4; - Rfu.unk_ce7 = lman.acceptSlot_flag; + Rfu.state = 4; + Rfu.acceptSlot_flag = lman.acceptSlot_flag; } -bool32 WaitRfuState(bool32 a0) +bool32 WaitRfuState(bool32 force) { - if (Rfu.unk_04 == 17 || a0) + if (Rfu.state == 17 || force) { - Rfu.unk_04 = 18; + Rfu.state = 18; return TRUE; } return FALSE; @@ -565,14 +619,14 @@ bool32 WaitRfuState(bool32 a0) void sub_800EF7C(void) { - Rfu.unk_04 = 14; + Rfu.state = 14; } -void sub_800EF88(u8 a0) +static void sub_800EF88(u8 a0) { u8 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if (a0 & 1) { @@ -583,23 +637,23 @@ void sub_800EF88(u8 a0) } } -void sub_800EFB0(void) +static void sub_800EFB0(void) { s32 i, j; for (i = 0; i < 5; i++) { - struct UnkRfuStruct_2 *ptr = &Rfu; + struct GFRfuManager *ptr = &Rfu; for (j = 0; j < 7; j++) { - ptr->unk_c87[i][j][1] = gRecvCmds[i][j] >> 8; - ptr->unk_c87[i][j][0] = gRecvCmds[i][j]; + ptr->recvCmds[i][j][1] = gRecvCmds[i][j] >> 8; + ptr->recvCmds[i][j][0] = gRecvCmds[i][j]; } } CpuFill16(0, gRecvCmds, sizeof gRecvCmds); } -void sub_800F014(void) +static void sub_800F014(void) { s32 i; for (i = 0; i < 7; i++) @@ -612,12 +666,12 @@ void sub_800F014(void) } } -void sub_800F048(void) +static void sub_800F048(void) { if (Rfu.unk_c3c) { u8 r2 = sub_800DAC8(&Rfu.unk_c1c, Rfu.unk_4c); - if (Rfu.unk_c1c.unk_1e == 0) + if (Rfu.unk_c1c.count == 0) { Rfu.unk_c3c = 0; } @@ -628,7 +682,7 @@ void sub_800F048(void) } if (Rfu.unk_c3c == 0) { - sub_800D9DC(&Rfu.unk_9e8, Rfu.unk_4c); + sub_800D9DC(&Rfu.sendQueue, Rfu.unk_4c); sub_800DA68(&Rfu.unk_c1c, Rfu.unk_4c); } } @@ -655,13 +709,13 @@ bool32 IsRfuRecvQueueEmpty(void) return TRUE; } -bool32 sub_800F0F8(void) +static bool32 sub_800F0F8(void) { - if (Rfu.unk_04 < 20) + if (Rfu.state < 20) { rfu_REQ_recvData(); rfu_waitREQComplete(); - rfu_LMAN_REQ_sendData(0); + rfu_LMAN_REQ_sendData(FALSE); } else { @@ -672,12 +726,12 @@ bool32 sub_800F0F8(void) { if (Rfu.unk_ce3) { - sub_8011D6C(Rfu.unk_ce3); + RfuReqDisconnectSlot(Rfu.unk_ce3); Rfu.unk_ce3 = 0; if (Rfu.unk_ce4 == 1) { RfuSetErrorStatus(2, 0x8000); - sub_8011170(0x8000); + GetLinkmanErrorParams(0x8000); return FALSE; } if (!lman.acceptSlot_flag) @@ -689,7 +743,7 @@ bool32 sub_800F0F8(void) } sub_800EFB0(); rfu_UNI_readySendData(Rfu.unk_cda); - rfu_LMAN_REQ_sendData(1); + rfu_LMAN_REQ_sendData(TRUE); } else { @@ -701,7 +755,7 @@ bool32 sub_800F0F8(void) return FALSE; } -bool32 sub_800F1E0(void) +static bool32 sub_800F1E0(void) { u16 i; u16 flags; @@ -709,12 +763,12 @@ bool32 sub_800F1E0(void) u16 j; u8 retval; - if (Rfu.unk_04 >= 20 && Rfu.unk_0e == 1) + if (Rfu.state >= 20 && Rfu.unk_0e == 1) { rfu_waitREQComplete(); while (Rfu.unk_cdb == 0) { - if (Rfu.unk_ee != 0) + if (Rfu.errorState != 0) { return FALSE; } @@ -726,7 +780,7 @@ bool32 sub_800F1E0(void) Rfu.unk_cdc = 0; gUnknown_02022B44.unk_06++; flags = lman.acceptSlot_flag; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if (flags & 1) { @@ -735,14 +789,14 @@ bool32 sub_800F1E0(void) if (Rfu.unk_cee[i] != 0xFF && (Rfu.unk_14[i][0] >> 5) != ((Rfu.unk_cee[i] + 1) & 7)) { if (++Rfu.unk_cea[i] > 4) - sub_8011170(0x8100); + GetLinkmanErrorParams(0x8100); } else { Rfu.unk_cee[i] = Rfu.unk_14[i][0] / 32; Rfu.unk_cea[i] = 0; Rfu.unk_14[i][0] &= 0x1f; - r0 = Rfu.unk_cde[i]; + r0 = Rfu.linkPlayerIdx[i]; for (j = 0; j < 7; j++) { gRecvCmds[r0][j] = (Rfu.unk_14[i][(j << 1) + 1] << 8) | Rfu.unk_14[i][(j << 1) + 0]; @@ -756,26 +810,26 @@ bool32 sub_800F1E0(void) flags >>= 1; } sub_800F014(); - sub_800F86C(0); - sub_8010528(); + RfuHandleReceiveCommand(0); + CallRfuFunc(); if (Rfu.unk_ce5 && !Rfu.unk_cd9) { gUnknown_02022B44.unk_0e = 0; - rfu_clearSlot(3, Rfu.unk_cda); - for (i = 0; i < 4; i++) + rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, Rfu.unk_cda); + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((Rfu.unk_ce5 >> i) & 1) { - rfu_setRecvBuffer(0x10, i, Rfu.unk_14[i], 14); + rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], 14); } } sub_800E88C(Rfu.unk_ce2, Rfu.unk_ce2 | Rfu.unk_ce5); Rfu.unk_ce9 = Rfu.unk_ce5; Rfu.unk_ce2 |= Rfu.unk_ce5; Rfu.unk_ce5 = 0; - rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.unk_c87, 70); + rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70); Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2); - CreateTask(sub_8010AAC, 0); + CreateTask(Task_ExchangeLinkPlayers, 0); } } else @@ -789,7 +843,7 @@ bool32 sub_800F1E0(void) return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE; } -void sub_800F498(u16 *a0, u8 *a1) +static void sub_800F498(u16 *a0, u8 *a1) { s32 i; @@ -810,7 +864,7 @@ void sub_800F498(u16 *a0, u8 *a1) } } -bool32 sub_800F4F0(void) +static bool32 RfuProcessEnqueuedRecvBlock(void) { u8 i; u8 j; @@ -818,7 +872,7 @@ bool32 sub_800F4F0(void) u8 sp48[2 * (CMD_LENGTH - 1)]; u8 switchval; - sub_800D934(&Rfu.unk_124, sp00); + sub_800D934(&Rfu.recvQueue, sp00); for (i = 0; i < MAX_RFU_PLAYERS; i++) { for (j = 0; j < CMD_LENGTH - 1; j++) @@ -826,7 +880,7 @@ bool32 sub_800F4F0(void) gRecvCmds[i][j] = (sp00[i * 14 + (j << 1) + 1] << 8) | sp00[i * 14 + (j << 1) + 0]; } } - sub_800F86C(0); + RfuHandleReceiveCommand(0); if (lman.childClockSlave_flag == 0 && Rfu.unk_ce4) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); @@ -836,11 +890,11 @@ bool32 sub_800F4F0(void) RfuSetErrorStatus(2, 0x9000); rfu_clearAllSlot(); gReceivedRemoteLinkPlayers = FALSE; - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; if (Rfu.unk_ce4 == 1) { RfuSetErrorStatus(2, 0x9000); - sub_8011170(0x9000); + GetLinkmanErrorParams(0x9000); } lman.state = lman.next_state = 0; Rfu.unk_ce4 = 0; @@ -848,71 +902,71 @@ bool32 sub_800F4F0(void) if (Rfu.unk_cd0) { Rfu.unk_cd0--; - sub_8010528(); + CallRfuFunc(); sub_800F498(gSendCmd, sp48); - sub_800D888(&Rfu.unk_9e8, sp48); + sub_800D888(&Rfu.sendQueue, sp48); for (i = 0; i < CMD_LENGTH - 1; i++) gSendCmd[i] = 0; } return IsRfuRecvQueueEmpty(); } -void sub_800F638(u8 unused, u32 flags) +static void HandleSendFailure(u8 unused, u32 flags) { s32 i, j; - const u8 *r10 = Rfu.unk_6c.unk_04; - for (i = 0; i < Rfu.unk_6c.unk_02; i++) + const u8 *r10 = Rfu.unk_6c.payload; + for (i = 0; i < Rfu.unk_6c.count; i++) { if (!(flags & 1)) { - gUnknown_03000D90[0] = (~0x76ff) | i; + sResendBlock16[0] = RFU_COMMAND_0x8900 | i; for (j = 0; j < 7; j++) { - gUnknown_03000D90[j + 1] = (r10[12 * i + (j << 1) + 1] << 8) | r10[12 * i + (j << 1) + 0]; + sResendBlock16[j + 1] = (r10[12 * i + (j << 1) + 1] << 8) | r10[12 * i + (j << 1) + 0]; } for (j = 0; j < 7; j++) { - gUnknown_03000D80[2 * j + 1] = gUnknown_03000D90[j] >> 8; - gUnknown_03000D80[2 * j + 0] = gUnknown_03000D90[j]; + sResendBlock8[2 * j + 1] = sResendBlock16[j] >> 8; + sResendBlock8[2 * j + 0] = sResendBlock16[j]; j++;j--; // Needed to match; } - sub_800D888(&Rfu.unk_9e8, gUnknown_03000D80); - Rfu.unk_6c.unk_0c |= (1 << i); + sub_800D888(&Rfu.sendQueue, sResendBlock8); + Rfu.unk_6c.failedFlags |= (1 << i); } flags >>= 1; } } -void sub_800F6FC(u8 a0) +void Rfu_SetBlockReceivedFlag(u8 linkPlayerId) { - if (Rfu.unk_0c == 1 && a0) - Rfu.unk_61[a0] = 1; + if (Rfu.parentChild == MODE_PARENT && linkPlayerId) + Rfu.unk_61[linkPlayerId] = TRUE; else - Rfu.unk_5c[a0] = 1; + Rfu.unk_5c[linkPlayerId] = TRUE; } -void sub_800F728(u8 a0) +void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId) { - Rfu.unk_5c[a0] = 0; - Rfu.unk_80[a0].unk_12 = 0; + Rfu.unk_5c[linkPlayerId] = FALSE; + Rfu.unk_80[linkPlayerId].receiving = 0; } -u8 sub_800F74C(const u8 *a0) +static u8 sub_800F74C(const u8 *a0) { u8 i; - if (Rfu.unk_0c == 1) + if (Rfu.parentChild == MODE_PARENT) return FALSE; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - Rfu.unk_cde[i] = a0[i]; + Rfu.linkPlayerIdx[i] = a0[i]; } - return a0[Rfu.unk_c3e]; + return a0[Rfu.childSlot]; } -void rfu_func_080F97B8(void) +static void RfuFunc_SendKeysToRfu(void) { if (gReceivedRemoteLinkPlayers && gHeldKeyCodeToSend != LINK_KEY_CODE_NULL @@ -920,33 +974,33 @@ void rfu_func_080F97B8(void) { gUnknown_03000D78[0]++; gHeldKeyCodeToSend |= (gUnknown_03000D78[0] << 8); - sub_800FD14(0xbe00); + RfuPrepareSendBuffer(RFU_COMMAND_0xBE00); } } struct GFtgtGname *GetHostRFUtgtGname(void) { - return &gUnknown_02022B14; + return &gHostRFUtgtGnameBuffer; } bool32 IsSendingKeysToRfu(void) { - return Rfu.linkRfuCallback == rfu_func_080F97B8; + return Rfu.callback == RfuFunc_SendKeysToRfu; } -void sub_800F804(void) +void StartSendingKeysToRfu(void) { - Rfu.linkRfuCallback = rfu_func_080F97B8; + Rfu.callback = RfuFunc_SendKeysToRfu; } void ClearLinkRfuCallback(void) { - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; } void sub_800F820(void) { - sub_800FD14(0x4400); + RfuPrepareSendBuffer(RFU_COMMAND_0x4400); if (GetMultiplayerId() == 0) gSendCmd[6] = GetBlenderArrowPosition(); gUnknown_020223C0++; @@ -954,11 +1008,11 @@ void sub_800F820(void) void sub_800F850(void) { - if (Rfu.linkRfuCallback == NULL) - Rfu.linkRfuCallback = sub_800F820; + if (Rfu.callback == NULL) + Rfu.callback = sub_800F820; } -void sub_800F86C(u8 unused) +static void RfuHandleReceiveCommand(u8 unused) { u16 i; u16 j; @@ -967,58 +1021,58 @@ void sub_800F86C(u8 unused) { switch (gRecvCmds[i][0] & 0xff00) { - case 0x7800: - if (Rfu.unk_0c == 0 && gReceivedRemoteLinkPlayers != 0) + case RFU_COMMAND_0x7800: + if (Rfu.parentChild == MODE_CHILD && gReceivedRemoteLinkPlayers) return; // fallthrough - case 0x7700: - if (gRfuLinkStatus->parentChild == 0) + case RFU_COMMAND_0x7700: + if (gRfuLinkStatus->parentChild == MODE_CHILD) { Rfu.playerCount = gRecvCmds[i][1]; - Rfu.unk_cce = sub_800F74C((u8 *)(gRecvCmds[i] + 2)); + Rfu.multiplayerId = sub_800F74C((u8 *)(gRecvCmds[i] + 2)); } break; - case 0x8800: - if (Rfu.unk_80[i].unk_12 == 0) + case RFU_COMMAND_0x8800: + if (Rfu.unk_80[i].receiving == 0) { - Rfu.unk_80[i].unk_00 = 0; - Rfu.unk_80[i].unk_02 = gRecvCmds[i][1]; - Rfu.unk_80[i].unk_11 = gRecvCmds[i][2]; - Rfu.unk_80[i].unk_08 = 0; - Rfu.unk_80[i].unk_12 = 1; + Rfu.unk_80[i].next = 0; + Rfu.unk_80[i].count = gRecvCmds[i][1]; + Rfu.unk_80[i].owner = gRecvCmds[i][2]; + Rfu.unk_80[i].receivedFlags = 0; + Rfu.unk_80[i].receiving = 1; Rfu.unk_5c[i] = 0; } break; - case 0x8900: - if (Rfu.unk_80[i].unk_12 == 1) + case RFU_COMMAND_0x8900: + if (Rfu.unk_80[i].receiving == 1) { - Rfu.unk_80[i].unk_00 = gRecvCmds[i][0] & 0xff; - Rfu.unk_80[i].unk_08 |= (1 << Rfu.unk_80[i].unk_00); + Rfu.unk_80[i].next = gRecvCmds[i][0] & 0xff; + Rfu.unk_80[i].receivedFlags |= (1 << Rfu.unk_80[i].next); for (j = 0; j < 6; j++) - gBlockRecvBuffer[i][Rfu.unk_80[i].unk_00 * 6 + j] = gRecvCmds[i][j + 1]; - if (Rfu.unk_80[i].unk_08 == gUnknown_082ED628[Rfu.unk_80[i].unk_02]) + gBlockRecvBuffer[i][Rfu.unk_80[i].next * 6 + j] = gRecvCmds[i][j + 1]; + if (Rfu.unk_80[i].receivedFlags == sAllBlocksReceived[Rfu.unk_80[i].count]) { - Rfu.unk_80[i].unk_12 = 2; - sub_800F6FC(i); - if (GetHostRFUtgtGname()->activity == 0x45 && gReceivedRemoteLinkPlayers != 0 && Rfu.unk_0c == 0) - sub_8010A70(gBlockRecvBuffer); + Rfu.unk_80[i].receiving = 2; + Rfu_SetBlockReceivedFlag(i); + if (GetHostRFUtgtGname()->activity == 0x45 && gReceivedRemoteLinkPlayers != 0 && Rfu.parentChild == MODE_CHILD) + ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer); } } break; - case 0xa100: - sub_800FE84(gUnknown_082ED6B8[gRecvCmds[i][1]].buffer, (u16)gUnknown_082ED6B8[gRecvCmds[i][1]].size); + case RFU_COMMAND_0xA100: + Rfu_InitBlockSend(sUnknown_082ED6B8[gRecvCmds[i][1]].buffer, (u16)sUnknown_082ED6B8[gRecvCmds[i][1]].size); break; - case 0x5f00: + case RFU_COMMAND_0x5F00: Rfu.unk_e4[i] = 1; break; - case 0x6600: + case RFU_COMMAND_0x6600: if (Rfu.unk_100 == gRecvCmds[i][1]) Rfu.unk_e9[i] = 1; break; - case 0xed00: - if (Rfu.unk_0c == 0) + case RFU_COMMAND_0xED00: + if (Rfu.parentChild == MODE_CHILD) { - if (gReceivedRemoteLinkPlayers != 0) + if (gReceivedRemoteLinkPlayers) { if (gRecvCmds[i][1] & gRfuLinkStatus->connSlotFlag) { @@ -1032,26 +1086,26 @@ void sub_800F86C(u8 unused) } else { - sub_800FD14(0xee00); + RfuPrepareSendBuffer(RFU_COMMAND_0xEE00); gSendCmd[1] = gRecvCmds[i][1]; gSendCmd[2] = gRecvCmds[i][2]; gSendCmd[3] = gRecvCmds[i][3]; } break; - case 0xee00: - if (Rfu.unk_0c == 1) + case RFU_COMMAND_0xEE00: + if (Rfu.parentChild == MODE_PARENT) { Rfu.unk_ce3 |= gRecvCmds[i][1]; Rfu.unk_ce4 = gRecvCmds[i][2]; sub_80109E8(gRecvCmds[i][1]); } break; - case 0x4400: - case 0xbe00: + case RFU_COMMAND_0x4400: + case RFU_COMMAND_0xBE00: gLinkPartnersHeldKeys[i] = gRecvCmds[i][1]; break; } - if (Rfu.unk_0c == 1 && Rfu.unk_61[i]) + if (Rfu.parentChild == MODE_PARENT && Rfu.unk_61[i]) { if (Rfu.unk_61[i] == 4) { @@ -1064,49 +1118,49 @@ void sub_800F86C(u8 unused) } } -bool8 sub_800FC60(void) +static bool8 sub_800FC60(void) { s32 i; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.unk_80[i].unk_12) + if (Rfu.unk_80[i].receiving) return FALSE; } return TRUE; } -bool8 sub_800FC88(void) +static bool8 sub_800FC88(void) { s32 i; for (i = 0; i < Rfu.playerCount; i++) { - if (Rfu.unk_80[i].unk_12 != 2 || Rfu.unk_5c[i] != 1) + if (Rfu.unk_80[i].receiving != 2 || Rfu.unk_5c[i] != 1) return FALSE; } return TRUE; } -void sub_800FCC4(struct UnkRfuStruct_2_Sub_6c *data) +static void ResetSendDataManager(struct RfuBlockSend *data) { - data->unk_00 = 0; - data->unk_02 = 0; - data->unk_04 = NULL; - data->unk_08 = 0; - data->unk_10 = 0; - data->unk_11 = 0; - data->unk_12 = 0; + data->next = 0; + data->count = 0; + data->payload = NULL; + data->receivedFlags = 0; + data->sending = FALSE; + data->owner = 0; + data->receiving = 0; } -u8 sub_800FCD8(void) +u8 Rfu_GetBlockReceivedStatus(void) { u8 flags = 0; s32 i; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.unk_80[i].unk_12 == 2 && Rfu.unk_5c[i] == 1) + if (Rfu.unk_80[i].receiving == 2 && Rfu.unk_5c[i] == 1) { flags |= (1 << i); } @@ -1114,7 +1168,7 @@ u8 sub_800FCD8(void) return flags; } -void sub_800FD14(u16 command) +static void RfuPrepareSendBuffer(u16 command) { u8 i; u8 *buff; @@ -1123,41 +1177,41 @@ void sub_800FD14(u16 command) gSendCmd[0] = command; switch (command) { - case 0x8800: - gSendCmd[1] = Rfu.unk_6c.unk_02; - gSendCmd[2] = Rfu.unk_6c.unk_11 + 0x80; + case RFU_COMMAND_0x8800: + gSendCmd[1] = Rfu.unk_6c.count; + gSendCmd[2] = Rfu.unk_6c.owner + 0x80; break; - case 0xa100: + case RFU_COMMAND_0xA100: if (sub_800FC60()) gSendCmd[1] = Rfu.unk_5a; break; - case 0x7700: - case 0x7800: + case RFU_COMMAND_0x7700: + case RFU_COMMAND_0x7800: tmp = Rfu.unk_ce2 ^ Rfu.unk_ce3; - Rfu.playerCount = gUnknown_082ED695[tmp] + 1; + Rfu.playerCount = sUnknown_082ED695[tmp] + 1; gSendCmd[1] = Rfu.playerCount; buff = (u8 *)(gSendCmd + 2); - for (i = 0; i < 4; i++) - buff[i] = Rfu.unk_cde[i]; + for (i = 0; i < RFU_CHILD_MAX; i++) + buff[i] = Rfu.linkPlayerIdx[i]; break; - case 0x6600: - case 0x5f00: + case RFU_COMMAND_0x6600: + case RFU_COMMAND_0x5F00: gSendCmd[1] = Rfu.unk_100; break; - case 0x4400: + case RFU_COMMAND_0x4400: gSendCmd[0] = command; gSendCmd[1] = gMain.heldKeys; break; - case 0x2f00: + case RFU_COMMAND_0x2F00: for (i = 0; i < 6; i++) gSendCmd[1 + i] = Rfu.unk_f2[i]; break; - case 0xbe00: + case RFU_COMMAND_0xBE00: gSendCmd[1] = gHeldKeyCodeToSend; break; - case 0xee00: + case RFU_COMMAND_0xEE00: break; - case 0xed00: + case RFU_COMMAND_0xED00: break; } } @@ -1167,131 +1221,131 @@ void sub_800FE50(void *a0) if (gSendCmd[0] == 0 && !RfuIsErrorStatus1or2()) { memcpy(Rfu.unk_f2, a0, sizeof(Rfu.unk_f2)); - sub_800FD14(0x2f00); + RfuPrepareSendBuffer(RFU_COMMAND_0x2F00); } } -bool32 sub_800FE84(const u8 *src, size_t size) +bool32 Rfu_InitBlockSend(const u8 *src, size_t size) { bool8 r4; - if (Rfu.linkRfuCallback != NULL) + if (Rfu.callback != NULL) return FALSE; if (gSendCmd[0] != 0) return FALSE; - if (Rfu.unk_6c.unk_10 != 0) + if (Rfu.unk_6c.sending) { gUnknown_02022B44.unk_83++; return FALSE; } r4 = (size % 12) != 0; - Rfu.unk_6c.unk_11 = GetMultiplayerId(); - Rfu.unk_6c.unk_10 = 1; - Rfu.unk_6c.unk_02 = (size / 12) + r4; - Rfu.unk_6c.unk_00 = 0; + Rfu.unk_6c.owner = GetMultiplayerId(); + Rfu.unk_6c.sending = TRUE; + Rfu.unk_6c.count = (size / 12) + r4; + Rfu.unk_6c.next = 0; if (size > 0x100) - Rfu.unk_6c.unk_04 = src; + Rfu.unk_6c.payload = src; else { if (src != gBlockSendBuffer) memcpy(gBlockSendBuffer, src, size); - Rfu.unk_6c.unk_04 = gBlockSendBuffer; + Rfu.unk_6c.payload = gBlockSendBuffer; } - sub_800FD14(0x8800); - Rfu.linkRfuCallback = rfufunc_80F9F44; + RfuPrepareSendBuffer(RFU_COMMAND_0x8800); + Rfu.callback = HandleBlockSend; Rfu.unk_5b = 0; return TRUE; } -void rfufunc_80F9F44(void) +static void HandleBlockSend(void) { if (gSendCmd[0] == 0) { - sub_800FD14(0x8800); - if (Rfu.unk_0c == 1) + RfuPrepareSendBuffer(RFU_COMMAND_0x8800); + if (Rfu.parentChild == MODE_PARENT) { if (++Rfu.unk_5b > 2) - Rfu.linkRfuCallback = sub_800FFB0; + Rfu.callback = SendNextBlock; } else { - if ((gRecvCmds[GetMultiplayerId()][0] & 0xff00) == 0x8800) - Rfu.linkRfuCallback = sub_800FFB0; + if ((gRecvCmds[GetMultiplayerId()][0] & 0xff00) == RFU_COMMAND_0x8800) + Rfu.callback = SendNextBlock; } } } -void sub_800FFB0(void) +static void SendNextBlock(void) { s32 i; - const u8 *src = Rfu.unk_6c.unk_04; - gSendCmd[0] = 0x8900 | Rfu.unk_6c.unk_00; + const u8 *src = Rfu.unk_6c.payload; + gSendCmd[0] = RFU_COMMAND_0x8900 | Rfu.unk_6c.next; for (i = 0; i < 7; i++) - gSendCmd[i + 1] = (src[(i << 1) + Rfu.unk_6c.unk_00 * 12 + 1] << 8) | src[(i << 1) + Rfu.unk_6c.unk_00 * 12 + 0]; - Rfu.unk_6c.unk_00++; - if (Rfu.unk_6c.unk_02 <= Rfu.unk_6c.unk_00) + gSendCmd[i + 1] = (src[(i << 1) + Rfu.unk_6c.next * 12 + 1] << 8) | src[(i << 1) + Rfu.unk_6c.next * 12 + 0]; + Rfu.unk_6c.next++; + if (Rfu.unk_6c.count <= Rfu.unk_6c.next) { - Rfu.unk_6c.unk_10 = 0; - Rfu.linkRfuCallback = rfufunc_80FA020; + Rfu.unk_6c.sending = FALSE; + Rfu.callback = SendLastBlock; } } -void rfufunc_80FA020(void) +static void SendLastBlock(void) { - const u8 *src = Rfu.unk_6c.unk_04; + const u8 *src = Rfu.unk_6c.payload; u8 mpId = GetMultiplayerId(); s32 i; - if (Rfu.unk_0c == 0) + if (Rfu.parentChild == MODE_CHILD) { - gSendCmd[0] = (~0x76ff) | (Rfu.unk_6c.unk_02 - 1); + gSendCmd[0] = RFU_COMMAND_0x8900 | (Rfu.unk_6c.count - 1); for (i = 0; i < 7; i++) - gSendCmd[i + 1] = (src[(i << 1) + (Rfu.unk_6c.unk_02 - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.unk_6c.unk_02 - 1) * 12 + 0]; - if ((u8)gRecvCmds[mpId][0] == Rfu.unk_6c.unk_02 - 1) + gSendCmd[i + 1] = (src[(i << 1) + (Rfu.unk_6c.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.unk_6c.count - 1) * 12 + 0]; + if ((u8)gRecvCmds[mpId][0] == Rfu.unk_6c.count - 1) { - if (Rfu.unk_80[mpId].unk_08 != gUnknown_082ED628[Rfu.unk_80[mpId].unk_02]) + if (Rfu.unk_80[mpId].receivedFlags != sAllBlocksReceived[Rfu.unk_80[mpId].count]) { - sub_800F638(mpId, Rfu.unk_80[mpId].unk_08); + HandleSendFailure(mpId, Rfu.unk_80[mpId].receivedFlags); gUnknown_02022B44.unk_64++; } else - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; } } else - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; } -bool8 sub_8010100(u8 a0) +bool8 sub_8010100(u8 blockRequestType) { - Rfu.unk_5a = a0; - sub_800FD14(0xa100); + Rfu.unk_5a = blockRequestType; + RfuPrepareSendBuffer(RFU_COMMAND_0xA100); return TRUE; } -void sub_801011C(void) +static void sub_801011C(void) { rfu_clearAllSlot(); rfu_LMAN_powerDownRFU(); gReceivedRemoteLinkPlayers = 0; - Rfu.unk_ef = 1; - Rfu.linkRfuCallback = NULL; + Rfu.isShuttingDown = TRUE; + Rfu.callback = NULL; } -void sub_8010148(void) +static void sub_8010148(void) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); rfu_waitREQComplete(); sub_801011C(); } -void sub_8010168(void) +static void sub_8010168(void) { - if (Rfu.unk_0c == 0) + if (Rfu.parentChild == MODE_CHILD) { rfu_LMAN_requestChangeAgbClockMaster(); Rfu.unk_ce4 = 2; } else - Rfu.linkRfuCallback = sub_8010148; + Rfu.callback = sub_8010148; } void LinkRfu_FatalError(void) @@ -1301,7 +1355,7 @@ void LinkRfu_FatalError(void) Rfu.unk_ce3 = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag; } -void sub_80101CC(void) +static void sub_80101CC(void) { s32 i; u8 playerCount = Rfu.playerCount; @@ -1315,31 +1369,31 @@ void sub_80101CC(void) if (count == playerCount) { gBattleTypeFlags &= ~BATTLE_TYPE_20; - if (Rfu.unk_0c == 0) + if (Rfu.parentChild == MODE_CHILD) { - Rfu.unk_ee = 3; + Rfu.errorState = 3; sub_8010168(); } else - Rfu.linkRfuCallback = sub_8010168; + Rfu.callback = sub_8010168; } } -void sub_801022C(void) +static void sub_801022C(void) { if (gSendCmd[0] == 0 && Rfu.unk_ce8 == 0) { - sub_800FD14(0x5f00); - Rfu.linkRfuCallback = sub_80101CC; + RfuPrepareSendBuffer(RFU_COMMAND_0x5F00); + Rfu.callback = sub_80101CC; } } -void sub_8010264(u8 taskId) +static void sub_8010264(u8 taskId) { - if (Rfu.linkRfuCallback == NULL) + if (Rfu.callback == NULL) { Rfu.unk_cd9 = 1; - Rfu.linkRfuCallback = sub_801022C; + Rfu.callback = sub_801022C; DestroyTask(taskId); } } @@ -1350,18 +1404,17 @@ void task_add_05_task_del_08FA224_when_no_RfuFunc(void) CreateTask(sub_8010264, 5); } -void sub_80102B8(void) +static void sub_80102B8(void) { u8 playerCount; u8 i; if (GetMultiplayerId() != 0) { - u8 r4 = Rfu.unk_124.unk_8c2; - if (r4 == 0 && Rfu.unk_fe > 0x3c) + if (Rfu.recvQueue.count == 0 && Rfu.unk_fe > 60) { - sub_800FD14(0x6600); - Rfu.unk_fe = r4; + RfuPrepareSendBuffer(RFU_COMMAND_0x6600); + Rfu.unk_fe = 0; } } playerCount = GetLinkPlayerCount(); @@ -1375,31 +1428,31 @@ void sub_80102B8(void) for (i = 0; i < MAX_RFU_PLAYERS; i++) Rfu.unk_e9[i] = 0; Rfu.unk_100++; - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; } Rfu.unk_fe++; } -void sub_8010358(void) +static void sub_8010358(void) { - if (Rfu.unk_124.unk_8c2 == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) { - sub_800FD14(0x6600); - Rfu.linkRfuCallback = sub_80102B8; + RfuPrepareSendBuffer(RFU_COMMAND_0x6600); + Rfu.callback = sub_80102B8; } } -void sub_8010390(void) +static void sub_8010390(void) { u8 i; u8 playerCount; if (GetMultiplayerId() != 0) { - if (Rfu.unk_124.unk_8c2 == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) { - sub_800FD14(0x6600); - Rfu.linkRfuCallback = sub_80102B8; + RfuPrepareSendBuffer(RFU_COMMAND_0x6600); + Rfu.callback = sub_80102B8; } } else @@ -1412,10 +1465,10 @@ void sub_8010390(void) } if (i == playerCount) { - if (Rfu.unk_124.unk_8c2 == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && gSendCmd[0] == 0) { - sub_800FD14(0x6600); - Rfu.linkRfuCallback = sub_8010358; + RfuPrepareSendBuffer(RFU_COMMAND_0x6600); + Rfu.callback = sub_8010358; } } } @@ -1423,19 +1476,19 @@ void sub_8010390(void) void sub_8010434(void) { - if (Rfu.linkRfuCallback == NULL) + if (Rfu.callback == NULL) { - Rfu.linkRfuCallback = sub_8010390; + Rfu.callback = sub_8010390; Rfu.unk_fe = 0; } } -bool32 sub_8010454(u32 a0) +bool32 RfuSerialNumberIsValid(u32 serialNo) { s32 i; - for (i = 0; gUnknown_082ED6E0[i] != a0; i++) + for (i = 0; sAcceptedSerialNos[i] != serialNo; i++) { - if (gUnknown_082ED6E0[i] == 0xFFFF) + if (sAcceptedSerialNos[i] == 0xFFFF) return FALSE; } return TRUE; @@ -1445,7 +1498,7 @@ u8 sub_801048C(bool32 a0) { if (a0 == FALSE) return rfu_LMAN_setLinkRecovery(0, 0); - rfu_LMAN_setLinkRecovery(1, 0x258); + rfu_LMAN_setLinkRecovery(1, 600); return 0; } @@ -1455,53 +1508,54 @@ void sub_80104B0(void) rfu_LMAN_stopManager(FALSE); } -u8 rfu_get_multiplayer_id(void) +u8 Rfu_GetMultiplayerId(void) { - if (Rfu.unk_0c == 1) + if (Rfu.parentChild == MODE_PARENT) return 0; - return Rfu.unk_cce; + return Rfu.multiplayerId; } -u8 sub_80104F4(void) +u8 Rfu_GetLinkPlayerCount(void) { return Rfu.playerCount; } bool8 IsLinkRfuTaskFinished(void) { - if (Rfu.unk_f1 == 2) + if (Rfu.errorStatus == 2) return FALSE; - return Rfu.linkRfuCallback ? FALSE : TRUE; + return Rfu.callback ? FALSE : TRUE; } -void sub_8010528(void) +static void CallRfuFunc(void) { - if (Rfu.linkRfuCallback) - Rfu.linkRfuCallback(); + if (Rfu.callback) + Rfu.callback(); } -bool8 sub_8010540(void) +static bool8 sub_8010540(void) { s32 i; bool8 retval = FALSE; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if (Rfu.unk_cd1[i] < 5 || Rfu.unk_cd1[i] > 6) { - if (gRfuSlotStatusNI[i]->recv.state == 0x46 || gRfuSlotStatusNI[i]->recv.state == 0x48) + if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS + || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { if (Rfu.unk_cd5[i] == 8) { Rfu.unk_cd1[i] = 9; Rfu.unk_cd5[i] = 10; - rfu_clearSlot(8, i); + rfu_clearSlot(TYPE_NI_RECV, i); rfu_NI_setSendData(1 << i, 8, Rfu.unk_cd1 + i, 1); retval = TRUE; } } - else if (gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x47) - rfu_clearSlot(8, i); + else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == 0x47) + rfu_clearSlot(TYPE_NI_RECV, i); { } @@ -1514,7 +1568,7 @@ bool32 sub_80105EC(void) { u8 flags = 0; s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if (Rfu.unk_cd5[i] == 11) { @@ -1527,7 +1581,7 @@ bool32 sub_80105EC(void) rfu_REQ_disconnect(flags); rfu_waitREQComplete(); } - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if (Rfu.unk_cd5[i] == 10 || Rfu.unk_cd5[i] == 11) return TRUE; @@ -1535,148 +1589,259 @@ bool32 sub_80105EC(void) return FALSE; } -bool32 TrainerIdAndNameStillInPartnersList(u16 a0, const u8 *a1) +bool32 TrainerIdAndNameStillInPartnersList(u16 id, const u8 *name) { - u8 r1 = sub_8011CE4(a1, a0); - if (r1 == 0xFF) + u8 idx = GetPartnerIndexByNameAndTrainerID(name, id); + if (idx == 0xFF) return TRUE; - if (Rfu.unk_cd1[r1] == 9) + if (Rfu.unk_cd1[idx] == 9) return TRUE; return FALSE; } -void SendByteToPartnerByIdAndName(u8 a0, u16 a1, const u8 *a2) +void SendByteToPartnerByIdAndName(u8 value, u16 id, const u8 *name) { - u8 r4 = sub_8011CE4(a2, a1); - Rfu.unk_cd1[r4] = a0; - rfu_clearSlot(4, r4); - rfu_NI_setSendData(1 << r4, 8, Rfu.unk_cd1 + r4, 1); + u8 idx = GetPartnerIndexByNameAndTrainerID(name, id); + Rfu.unk_cd1[idx] = value; + rfu_clearSlot(TYPE_NI_SEND, idx); + rfu_NI_setSendData(1 << idx, 8, Rfu.unk_cd1 + idx, 1); } void LinkRfuNIsend8(void) { Rfu.unk_c85 = 8; - rfu_clearSlot(4, Rfu.unk_c3e); - rfu_NI_setSendData(1 << Rfu.unk_c3e, 8, &Rfu.unk_c85, 1); + rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot); + rfu_NI_setSendData(1 << Rfu.childSlot, 8, &Rfu.unk_c85, 1); } -u32 WaitSendByteToPartnerByIdAndName(u16 a0, const u8 *a1) +u32 WaitSendByteToPartnerByIdAndName(u16 id, const u8 *name) { - u8 r0 = sub_8011CE4(a1, a0); - if (r0 == 0xFF) + u8 idx = GetPartnerIndexByNameAndTrainerID(name, id); + if (idx == 0xFF) return 2; - if (gRfuSlotStatusNI[r0]->send.state == 0) + if (gRfuSlotStatusNI[idx]->send.state == 0) return 1; return 0; } -void sub_8010750(void) +static void sub_8010750(void) { s32 i; sub_8010540(); - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (gRfuSlotStatusNI[i]->send.state == 0x26 || gRfuSlotStatusNI[i]->send.state == 0x27) + if (gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_SUCCESS + || gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_FAILED) { if (Rfu.unk_cd5[i] == 10) Rfu.unk_cd5[i] = 11; - rfu_clearSlot(4, i); + rfu_clearSlot(TYPE_NI_SEND, i); } } } -s32 sub_80107A0(void) +static s32 sub_80107A0(void) { s32 retval = 0; if (Rfu.unk_c85 == 8) { - if (gRfuSlotStatusNI[Rfu.unk_c3e]->send.state == 0x26 || gRfuSlotStatusNI[Rfu.unk_c3e]->send.state == 0x27) - rfu_clearSlot(4, Rfu.unk_c3e); + if (gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_SUCCESS + || gRfuSlotStatusNI[Rfu.childSlot]->send.state == SLOT_STATE_SEND_FAILED) + rfu_clearSlot(TYPE_NI_SEND, Rfu.childSlot); } - if (gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x46 || gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x48) + if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS + || gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { - rfu_clearSlot(8, Rfu.unk_c3e); + rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot); RfuSetErrorStatus(Rfu.unk_c86, 0); retval = Rfu.unk_c86; } - else if (gRfuSlotStatusNI[Rfu.unk_c3e]->recv.state == 0x47) + else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == 0x47) { - rfu_clearSlot(8, Rfu.unk_c3e); + rfu_clearSlot(TYPE_NI_RECV, Rfu.childSlot); retval = 6; } return retval; } -void sub_801084C(u8 taskId) +static void sub_801084C(u8 taskId) { s32 i; - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) + if (Rfu.errorStatus == 1 || Rfu.errorStatus == 2) { Rfu.unk_ce8 = 0; DestroyTask(taskId); } switch (gTasks[taskId].data[0]) { - case 0: + case 0: + if (sub_800FC60()) + { + ResetBlockReceivedFlags(); + sub_800B348(); + gTasks[taskId].data[0]++; + } + break; + case 1: + if (Rfu.parentChild == MODE_PARENT) + { + if (gReceivedRemoteLinkPlayers) + RfuPrepareSendBuffer(RFU_COMMAND_0x7800); + else + RfuPrepareSendBuffer(RFU_COMMAND_0x7700); + gTasks[taskId].data[0] = 101; + } + else + gTasks[taskId].data[0] = 2; + break; + case 101: + if (gSendCmd[0] == 0) + gTasks[taskId].data[0] = 2; + break; + case 2: + if (Rfu.playerCount) + gTasks[taskId].data[0]++; + break; + case 3: + if (Rfu.parentChild == MODE_PARENT) + { if (sub_800FC60()) { - ResetBlockReceivedFlags(); - sub_800B348(); + Rfu.unk_5a = 0; + RfuPrepareSendBuffer(RFU_COMMAND_0xA100); gTasks[taskId].data[0]++; } - break; - case 1: - if (Rfu.unk_0c == 1) + } + else + gTasks[taskId].data[0]++; + break; + case 4: + if (sub_800FC88()) + gTasks[taskId].data[0]++; + break; + case 5: + for (i = 0; i < Rfu.playerCount; i++) + { + LinkPlayerFromBlock(i); + Rfu_ResetBlockReceivedFlag(i); + } + gTasks[taskId].data[0]++; + break; + case 6: + DestroyTask(taskId); + gReceivedRemoteLinkPlayers = TRUE; + Rfu.unk_ce8 = FALSE; + rfu_LMAN_setLinkRecovery(1, 600); + if (Rfu.unk_ce6) + { + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (gReceivedRemoteLinkPlayers) - sub_800FD14(0x7800); - else - sub_800FD14(0x7700); - gTasks[taskId].data[0] = 101; - } - else - gTasks[taskId].data[0] = 2; - break; - case 101: - if (gSendCmd[0] == 0) - gTasks[taskId].data[0] = 2; - break; - case 2: - if (Rfu.playerCount) - gTasks[taskId].data[0]++; - break; - case 3: - if (Rfu.unk_0c == 1) - { - if (sub_800FC60()) + if ((Rfu.unk_ce6 >> i) & 1) { - Rfu.unk_5a = 0; - sub_800FD14(0xa100); - gTasks[taskId].data[0]++; + Rfu.unk_ce5 = 1 << i; + Rfu.unk_ce6 ^= (1 << i); } } - else - gTasks[taskId].data[0]++; - break; - case 4: - if (sub_800FC88()) - gTasks[taskId].data[0]++; - break; - case 5: - for (i = 0; i < Rfu.playerCount; i++) - { - sub_800B3A4(i); - sub_800F728(i); - } + } + break; + } +} + +static void sub_80109E8(u16 a0) +{ + s32 i; + + for (i = 0; i < RFU_CHILD_MAX; i++) + { + if ((a0 >> i) & 1) + Rfu.linkPlayerIdx[i] = 0; + } +} + +static void ReceiveRfuLinkPlayers(const struct SioInfo *sioInfo) +{ + s32 i; + Rfu.playerCount = sioInfo->playerCount; + for (i = 0; i < RFU_CHILD_MAX; i++) + Rfu.linkPlayerIdx[i] = sioInfo->linkPlayerIdx[i]; + for (i = 0; i < MAX_RFU_PLAYERS; i++) + { + gLinkPlayers[i] = sioInfo->linkPlayers[i]; + sub_800B524(gLinkPlayers + i); + } +} + +static void ValidateAndReceivePokemonSioInfo(void *recvBuffer) +{ + if (strcmp(sASCII_PokemonSioInfo, recvBuffer) == 0) + { + ReceiveRfuLinkPlayers(recvBuffer); + CpuFill16(0, recvBuffer, sizeof(struct SioInfo)); + ResetBlockReceivedFlag(0); + } +} + +static void Task_ExchangeLinkPlayers(u8 taskId) +{ + s32 i; + struct LinkPlayerBlock *r2; + struct SioInfo *r5; + u8 r4 = Rfu.linkPlayerIdx[sUnknown_082ED68C[Rfu.unk_ce9]]; + if (Rfu.errorStatus == 1 || Rfu.errorStatus == 2) + { + Rfu.unk_ce8 = 0; + DestroyTask(taskId); + } + switch (gTasks[taskId].data[0]) + { + case 0: + if (gSendCmd[0] == 0) + { + ResetBlockReceivedFlag(r4); + RfuPrepareSendBuffer(RFU_COMMAND_0x7800); gTasks[taskId].data[0]++; - break; - case 6: - DestroyTask(taskId); - gReceivedRemoteLinkPlayers = 1; + } + break; + case 1: + if (gSendCmd[0] == 0) + gTasks[taskId].data[0]++; + break; + case 2: + if ((GetBlockReceivedStatus() >> r4) & 1) + { + ResetBlockReceivedFlag(r4); + r2 = (struct LinkPlayerBlock *)gBlockRecvBuffer[r4]; + gLinkPlayers[r4] = r2->linkPlayer; + sub_800B524(gLinkPlayers + r4); + gTasks[taskId].data[0]++; + } + break; + case 3: + r5 = (struct SioInfo *)gBlockSendBuffer; + memcpy(r5->magic, sASCII_PokemonSioInfo, sizeof sASCII_PokemonSioInfo); + r5->playerCount = Rfu.playerCount; + for (i = 0; i < RFU_CHILD_MAX; i++) + r5->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i]; + memcpy(r5->linkPlayers, gLinkPlayers, sizeof gLinkPlayers); + gTasks[taskId].data[0]++; + // fallthrough + case 4: + r5 = (struct SioInfo *)gBlockSendBuffer; + r5->playerCount = Rfu.playerCount; + for (i = 0; i < RFU_CHILD_MAX; i++) + r5->linkPlayerIdx[i] = Rfu.linkPlayerIdx[i]; + memcpy(r5->linkPlayers, gLinkPlayers, sizeof gLinkPlayers); + if (SendBlock(0, gBlockSendBuffer, 0xa0)) + gTasks[taskId].data[0]++; + break; + case 5: + if (IsLinkTaskFinished() && GetBlockReceivedStatus() & 1) + { + CpuFill16(0, gBlockRecvBuffer, sizeof(struct SioInfo)); + ResetBlockReceivedFlag(0); Rfu.unk_ce8 = 0; - rfu_LMAN_setLinkRecovery(1, 0x258); if (Rfu.unk_ce6) { for (i = 0; i < 4; i++) @@ -1685,177 +1850,69 @@ void sub_801084C(u8 taskId) { Rfu.unk_ce5 = 1 << i; Rfu.unk_ce6 ^= (1 << i); + Rfu.unk_ce8 = 1; + break; } } } - break; + DestroyTask(taskId); + } + break; } } -void sub_80109E8(u16 a0) +static void sub_8010D0C(u8 taskId) { - s32 i; - - for (i = 0; i < 4; i++) - { - if ((a0 >> i) & 1) - Rfu.unk_cde[i] = 0; - } -} - -void sub_8010A14(const struct UnkRfuStruct_8010A14 *a0) -{ - s32 i; - Rfu.playerCount = a0->unk_0f; - for (i = 0; i < 4; i++) - Rfu.unk_cde[i] = a0->unk_10[i]; - for (i = 0; i < MAX_RFU_PLAYERS; i++) - { - gLinkPlayers[i] = a0->unk_14[i]; - sub_800B524(gLinkPlayers + i); - } -} - -void sub_8010A70(void *a0) -{ - if (strcmp(gUnknown_082ED7EC, a0) == 0) - { - sub_8010A14(a0); - CpuFill16(0, a0, sizeof(struct UnkRfuStruct_8010A14)); - ResetBlockReceivedFlag(0); - } -} - -void sub_8010AAC(u8 taskId) -{ - s32 i; - struct LinkPlayerBlock *r2; - struct UnkRfuStruct_8010A14 *r5; - u8 r4 = Rfu.unk_cde[gUnknown_082ED68C[Rfu.unk_ce9]]; - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) - { - Rfu.unk_ce8 = 0; + if (Rfu.errorStatus == 1 || Rfu.errorStatus == 2) DestroyTask(taskId); - } switch (gTasks[taskId].data[0]) { - case 0: - if (gSendCmd[0] == 0) - { - ResetBlockReceivedFlag(r4); - sub_800FD14(0x7800); - gTasks[taskId].data[0]++; - } - break; - case 1: - if (gSendCmd[0] == 0) - gTasks[taskId].data[0]++; - break; - case 2: - if ((GetBlockReceivedStatus() >> r4) & 1) - { - ResetBlockReceivedFlag(r4); - r2 = (struct LinkPlayerBlock *)gBlockRecvBuffer[r4]; - gLinkPlayers[r4] = r2->linkPlayer; - sub_800B524(gLinkPlayers + r4); - gTasks[taskId].data[0]++; - } - break; - case 3: - r5 = (struct UnkRfuStruct_8010A14 *)gBlockSendBuffer; - memcpy(r5->unk_00, gUnknown_082ED7EC, sizeof gUnknown_082ED7EC); - r5->unk_0f = Rfu.playerCount; - for (i = 0; i < 4; i++) - r5->unk_10[i] = Rfu.unk_cde[i]; - memcpy(r5->unk_14, gLinkPlayers, sizeof gLinkPlayers); + case 0: + if (Rfu.playerCount) + { + sub_800B348(); + SendBlock(0, gBlockSendBuffer, sizeof(struct LinkPlayerBlock)); gTasks[taskId].data[0]++; - // fallthrough - case 4: - r5 = (struct UnkRfuStruct_8010A14 *)gBlockSendBuffer; - r5->unk_0f = Rfu.playerCount; - for (i = 0; i < 4; i++) - r5->unk_10[i] = Rfu.unk_cde[i]; - memcpy(r5->unk_14, gLinkPlayers, sizeof gLinkPlayers); - if (SendBlock(0, gBlockSendBuffer, 0xa0)) - gTasks[taskId].data[0]++; - break; - case 5: - if (IsLinkTaskFinished() && GetBlockReceivedStatus() & 1) - { - CpuFill16(0, gBlockRecvBuffer, sizeof(struct UnkRfuStruct_8010A14)); - ResetBlockReceivedFlag(0); - Rfu.unk_ce8 = 0; - if (Rfu.unk_ce6) - { - for (i = 0; i < 4; i++) - { - if ((Rfu.unk_ce6 >> i) & 1) - { - Rfu.unk_ce5 = 1 << i; - Rfu.unk_ce6 ^= (1 << i); - Rfu.unk_ce8 = 1; - break; - } - } - } - DestroyTask(taskId); - } - break; + } + break; + case 1: + if (IsLinkTaskFinished()) + gTasks[taskId].data[0]++; + break; + case 2: + if (GetBlockReceivedStatus() & 1) + { + ReceiveRfuLinkPlayers((const struct SioInfo *)gBlockRecvBuffer); + ResetBlockReceivedFlag(0); + gReceivedRemoteLinkPlayers = 1; + DestroyTask(taskId); + } + break; } } -void sub_8010D0C(u8 taskId) +static void RfuCheckErrorStatus(void) { - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) - DestroyTask(taskId); - switch (gTasks[taskId].data[0]) - { - case 0: - if (Rfu.playerCount) - { - sub_800B348(); - SendBlock(0, gBlockSendBuffer, sizeof(struct LinkPlayerBlock)); - gTasks[taskId].data[0]++; - } - break; - case 1: - if (IsLinkTaskFinished()) - gTasks[taskId].data[0]++; - break; - case 2: - if (GetBlockReceivedStatus() & 1) - { - sub_8010A14((const struct UnkRfuStruct_8010A14 *)gBlockRecvBuffer); - ResetBlockReceivedFlag(0); - gReceivedRemoteLinkPlayers = 1; - DestroyTask(taskId); - } - break; - } -} - -void sub_8010DB4(void) -{ - if (Rfu.unk_ee == 1 && lman.childClockSlave_flag == 0) + if (Rfu.errorState == 1 && lman.childClockSlave_flag == 0) { if (gMain.callback2 == c2_mystery_gift_e_reader_run || lman.init_param->mboot_flag) gWirelessCommType = 2; SetMainCallback2(CB2_LinkError); gMain.savedCallback = CB2_LinkError; - sub_800AF18((Rfu.unk_0a << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.unk_124.unk_8c2, Rfu.unk_9e8.unk_232, RfuGetErrorStatus() == 2); - Rfu.unk_ee = 2; + sub_800AF18((Rfu.linkmanMsg << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.recvQueue.count, Rfu.sendQueue.count, RfuGetErrorStatus() == 2); + Rfu.errorState = 2; CloseLink(); } - else if (Rfu.unk_9e8.unk_233 == 1 || Rfu.unk_124.unk_8c3 == 1) + else if (Rfu.sendQueue.full == TRUE || Rfu.recvQueue.full == TRUE) { if (lman.childClockSlave_flag) rfu_LMAN_requestChangeAgbClockMaster(); RfuSetErrorStatus(1, 0x7000); - sub_8011170(0x7000); + GetLinkmanErrorParams(0x7000); } } -void rfu_REQ_recvData_then_sendData(void) +static void rfu_REQ_recvData_then_sendData(void) { if (lman.parent_child == 1) { @@ -1868,21 +1925,21 @@ void rfu_REQ_recvData_then_sendData(void) bool32 sub_8010EC0(void) { bool32 retval = FALSE; - Rfu.unk_ccd = 0; + Rfu.parentId = 0; rfu_LMAN_manager_entity(Random2()); - if (Rfu.unk_ef == 0) + if (!Rfu.isShuttingDown) { - switch (Rfu.unk_0c) + switch (Rfu.parentChild) { - case 1: - sub_800F0F8(); - break; - case 0: - retval = sub_800F4F0(); - break; - case 2: - rfu_REQ_recvData_then_sendData(); - break; + case MODE_PARENT: + sub_800F0F8(); + break; + case MODE_CHILD: + retval = RfuProcessEnqueuedRecvBlock(); + break; + case 2: + rfu_REQ_recvData_then_sendData(); + break; } } return retval; @@ -1891,42 +1948,42 @@ bool32 sub_8010EC0(void) bool32 sub_8010F1C(void) { bool32 retval = FALSE; - if (Rfu.unk_ef == 0) + if (!Rfu.isShuttingDown) { - if (Rfu.unk_0c == 1) + if (Rfu.parentChild == MODE_PARENT) retval = sub_800F1E0(); - sub_8010DB4(); + RfuCheckErrorStatus(); } return retval; } -void sub_8010F48(void) +static void CopyPlayerNameToUnameBuffer(void) { - StringCopy(gUnknown_02022B22, gSaveBlock2Ptr->playerName); + StringCopy(gHostRFUtgtUnameBuffer, gSaveBlock2Ptr->playerName); } void ClearAndInitHostRFUtgtGname(void) { - memset(&gUnknown_02022B14, 0, 0xD); - sub_800DD94(&gUnknown_02022B14, 0, 0, 0); + memset(&gHostRFUtgtGnameBuffer, 0, RFU_GAME_NAME_LENGTH); + sub_800DD94(&gHostRFUtgtGnameBuffer, 0, FALSE, 0); } -void SetHostRFUtgtGname(u8 a0, u32 a1, u32 a2) +void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, u32 started) { - sub_800DD94(&gUnknown_02022B14, a0, a2, a1); + sub_800DD94(&gHostRFUtgtGnameBuffer, activity, started, child_sprite_genders); } -void SetGnameBufferWonderFlags(bool32 a0, bool32 a1) +void SetGnameBufferWonderFlags(bool32 hasNews, bool32 hasCard) { - gUnknown_02022B14.unk_00.hasNews = a0; - gUnknown_02022B14.unk_00.hasCard = a1; + gHostRFUtgtGnameBuffer.unk_00.hasNews = hasNews; + gHostRFUtgtGnameBuffer.unk_00.hasCard = hasCard; } -void sub_8010FCC(u32 type, u32 species, u32 level) +void SetTradeBoardRegisteredMonInfo(u32 type, u32 species, u32 level) { - gUnknown_02022B14.type = type; - gUnknown_02022B14.species = species; - gUnknown_02022B14.level = level; + gHostRFUtgtGnameBuffer.type = type; + gHostRFUtgtGnameBuffer.species = species; + gHostRFUtgtGnameBuffer.level = level; } u8 sub_801100C(s32 a0) @@ -1939,7 +1996,7 @@ u8 sub_801100C(s32 a0) void sub_801103C(void) { - struct GFtgtGname *r5 = &gUnknown_02022B14; + struct GFtgtGname *r5 = &gHostRFUtgtGnameBuffer; s32 i; for (i = 1; i < GetLinkPlayerCount(); i++) @@ -1948,92 +2005,92 @@ void sub_801103C(void) void UpdateGameData_GroupLockedIn(u8 a0) { - gUnknown_02022B14.started = a0; - rfu_REQ_configGameData(0, 2, (const u8 *)&gUnknown_02022B14, gUnknown_02022B22); + gHostRFUtgtGnameBuffer.started = a0; + rfu_REQ_configGameData(0, 2, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer); } void UpdateGameDataWithActivitySpriteGendersFlag(u8 a0, u32 a1, u32 a2) { if (a0) SetHostRFUtgtGname(a0, a1, a2); - rfu_REQ_configGameData(0, 2, (const u8 *)&gUnknown_02022B14, gUnknown_02022B22); + rfu_REQ_configGameData(0, 2, (void *)&gHostRFUtgtGnameBuffer, gHostRFUtgtUnameBuffer); } void sub_80110B8(u32 a0) { s32 i; - u32 r5; - u32 r7; + u32 numConnectedChildren; + u32 child_sprite_genders; s32 r8; - if (GetHostRFUtgtGname()->activity == 0x45) + if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { - r5 = 0; - r7 = 0; + numConnectedChildren = 0; + child_sprite_genders = 0; r8 = Rfu.unk_ce2 ^ Rfu.unk_ce3; for (i = 0; i < 4; i++) { if ((r8 >> i) & 1) { - r7 |= ((0x80 | ((gLinkPlayers[Rfu.unk_cde[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.unk_cde[i]].trainerId & 7)) << (r5 << 3)); - r5++; - if (r5 == a0 - 1) + child_sprite_genders |= ((0x80 | ((gLinkPlayers[Rfu.linkPlayerIdx[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.linkPlayerIdx[i]].trainerId & 7)) << (numConnectedChildren << 3)); + numConnectedChildren++; + if (numConnectedChildren == a0 - 1) break; } } - UpdateGameDataWithActivitySpriteGendersFlag(0x45, r7, 0); + UpdateGameDataWithActivitySpriteGendersFlag((ACTIVITY_CHAT | IN_UNION_ROOM), child_sprite_genders, 0); } } -void sub_8011170(u32 a0) +void GetLinkmanErrorParams(u32 msg) { - if (Rfu.unk_ee == 0) + if (Rfu.errorState == 0) { Rfu.unk_10 = lman.param[0]; Rfu.unk_12 = lman.param[1]; - Rfu.unk_0a = a0; - Rfu.unk_ee = 1; + Rfu.linkmanMsg = msg; + Rfu.errorState = 1; } } -void sub_80111A0(void) +static void ResetErrorState(void) { - Rfu.unk_ee = 0; + Rfu.errorState = 0; } void sub_80111B0(bool32 a0) { if (!a0) - Rfu.unk_ee = 0; + Rfu.errorState = 0; else - Rfu.unk_ee = 4; + Rfu.errorState = 4; } -void sub_80111DC(void) +static void sub_80111DC(void) { sub_8011E94(lman.acceptSlot_flag, 1); - Rfu.linkRfuCallback = NULL; + Rfu.callback = NULL; } -void sub_80111FC(void) +static void sub_80111FC(void) { - Rfu.linkRfuCallback = sub_80111DC; + Rfu.callback = sub_80111DC; } -void sub_801120C(u8 a0, u8 unused1) +static void sub_801120C(u8 msg, u8 paramCount) { u8 i; - u8 r6 = 0; - switch (a0) + u8 disconnectFlag = 0; + switch (msg) { - case 0x00: - Rfu.unk_04 = 2; + case LMAN_MSG_INITIALIZE_COMPLETED: + Rfu.state = 2; break; - case 0x10: + case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: break; - case 0x11: + case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED: sub_80115EC(lman.param[0]); - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((lman.param[0] >> i) & 1) { @@ -2042,141 +2099,149 @@ void sub_801120C(u8 a0, u8 unused1) { Rfu.unk_cd1[i] = 0; Rfu.unk_cd5[i] = 0; - rfu_setRecvBuffer(0x20, i, Rfu.unk_cd5 + i, 1); + rfu_setRecvBuffer(TYPE_NI, i, Rfu.unk_cd5 + i, 1); } else { - r6 |= (1 << i); + disconnectFlag |= (1 << i); } } } - if (r6) + if (disconnectFlag) { - rfu_REQ_disconnect(r6); + rfu_REQ_disconnect(disconnectFlag); rfu_waitREQComplete(); } break; - case 0x12: + case LMAN_MSG_NEW_CHILD_CONNECT_REJECTED: break; - case 0x13: + case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED: break; - case 0x14: - if (Rfu.unk_ce7 != lman.acceptSlot_flag) + case LMAN_MSG_END_WAIT_CHILD_NAME: + if (Rfu.acceptSlot_flag != lman.acceptSlot_flag) { - rfu_REQ_disconnect(Rfu.unk_ce7 ^ lman.acceptSlot_flag); + rfu_REQ_disconnect(Rfu.acceptSlot_flag ^ lman.acceptSlot_flag); rfu_waitREQComplete(); } - Rfu.unk_04 = 0x11; + Rfu.state = 0x11; break; - case 0x31: - Rfu.unk_f0 = 1; + case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: + Rfu.linkLossRecoveryState = 1; break; - case 0x32: - Rfu.unk_f0 = 3; + case LMAN_MSG_LINK_RECOVERY_SUCCESSED: + Rfu.linkLossRecoveryState = 3; break; - case 0x30: - case 0x33: - Rfu.unk_f0 = 4; + case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: + case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: + Rfu.linkLossRecoveryState = 4; Rfu.unk_ce2 &= ~lman.param[0]; if (gReceivedRemoteLinkPlayers == 1) { if (Rfu.unk_ce2 == 0) - sub_8011170(a0); + GetLinkmanErrorParams(msg); else sub_80111FC(); } - RfuSetErrorStatus(2, a0); + RfuSetErrorStatus(2, msg); break; case 0x34: break; - case 0x42 ... 0x44: + case LMAN_MSG_RFU_POWER_DOWN: + case LMAN_MSG_MANAGER_STOPPED: + case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; - case 0xf3: - RfuSetErrorStatus(1, a0); - sub_8011170(a0); - Rfu.unk_ef = 1; + case LMAN_MSG_LMAN_API_ERROR_RETURN: + RfuSetErrorStatus(1, msg); + GetLinkmanErrorParams(msg); + Rfu.isShuttingDown = TRUE; break; - case 0xf0 ... 0xf2: - case 0xff: - sub_8011170(a0); - RfuSetErrorStatus(1, a0); + case LMAN_MSG_REQ_API_ERROR: + case LMAN_MSG_WATCH_DOG_TIMER_ERROR: + case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA: + case LMAN_MSG_RFU_FATAL_ERROR: + GetLinkmanErrorParams(msg); + RfuSetErrorStatus(1, msg); Rfu.unk_cdb = 1; break; } } -void sub_8011404(u8 a0, u8 unused1) +void sub_8011404(u8 msg, u8 unused1) { - switch (a0) + switch (msg) { - case 0x00: - Rfu.unk_04 = 6; + case LMAN_MSG_INITIALIZE_COMPLETED: + Rfu.state = 6; break; - case 0x20: - Rfu.unk_ccd = lman.param[0]; + case LMAN_MSG_PARENT_FOUND: + Rfu.parentId = lman.param[0]; break; - case 0x21: + case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED: break; - case 0x22: - Rfu.unk_c3e = lman.param[0]; + case LMAN_MSG_CONNECT_PARENT_SUCCESSED: + Rfu.childSlot = lman.param[0]; break; - case 0x23: - RfuSetErrorStatus(2, a0); + case LMAN_MSG_CONNECT_PARENT_FAILED: + RfuSetErrorStatus(2, msg); break; - case 0x24: - Rfu.unk_04 = 11; + case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: + Rfu.state = 11; Rfu.unk_c85 = 0; Rfu.unk_c86 = 0; - rfu_setRecvBuffer(0x20, Rfu.unk_c3e, &Rfu.unk_c86, 1); - rfu_setRecvBuffer(0x10, Rfu.unk_c3e, Rfu.unk_c3f, 70); + rfu_setRecvBuffer(TYPE_NI, Rfu.childSlot, &Rfu.unk_c86, 1); + rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70); break; - case 0x25: - RfuSetErrorStatus(2, 0x25); + case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: + RfuSetErrorStatus(2, msg); break; - case 0x30: - Rfu.unk_f0 = 2; + case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: + Rfu.linkLossRecoveryState = 2; if (Rfu.unk_c86 == 6) break; - case 0x33: - if (Rfu.unk_f0 != 2) - Rfu.unk_f0 = 4; + case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: + if (Rfu.linkLossRecoveryState != 2) + Rfu.linkLossRecoveryState = 4; if (Rfu.unk_c86 != 9) - RfuSetErrorStatus(2, a0); - nullsub_5(gUnknown_082ED7FC, 5, 5); + RfuSetErrorStatus(2, msg); + Debug_PrintString(sASCII_LinkLossDisconnect, 5, 5); if (gReceivedRemoteLinkPlayers == 1) - sub_8011170(a0); + GetLinkmanErrorParams(msg); break; - case 0x31: - Rfu.unk_f0 = 1; - nullsub_5(gUnknown_082ED814, 5, 5); + case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: + Rfu.linkLossRecoveryState = 1; + Debug_PrintString(sASCII_LinkLossRecoveryNow, 5, 5); break; - case 0x32: - Rfu.unk_f0 = 3; + case LMAN_MSG_LINK_RECOVERY_SUCCESSED: + Rfu.linkLossRecoveryState = 3; Rfu.unk_c3c = 1; break; case 0x34: break; - case 0x42 ... 0x44: + case LMAN_MSG_RFU_POWER_DOWN: + case LMAN_MSG_MANAGER_STOPPED: + case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; - case 0xF3: - RfuSetErrorStatus(1, a0); - sub_8011170(a0); - Rfu.unk_ef = 1; + case LMAN_MSG_LMAN_API_ERROR_RETURN: + RfuSetErrorStatus(1, msg); + GetLinkmanErrorParams(msg); + Rfu.isShuttingDown = TRUE; break; - case 0xF0 ... 0xF2: - case 0xFF: - RfuSetErrorStatus(1, a0); - sub_8011170(a0); + case LMAN_MSG_REQ_API_ERROR: + case LMAN_MSG_WATCH_DOG_TIMER_ERROR: + case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA: + case LMAN_MSG_RFU_FATAL_ERROR: + RfuSetErrorStatus(1, msg); + GetLinkmanErrorParams(msg); Rfu.unk_cdb = 1; break; } } -void sub_80115EC(s32 a0) +static void sub_80115EC(s32 a0) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((a0 >> i) & 1) { @@ -2186,7 +2251,7 @@ void sub_80115EC(s32 a0) } } -u8 sub_8011628(s32 a0) +static u8 GetNewChildrenInUnionRoomChat(s32 a0) { u8 ret = 0; u8 i; @@ -2196,7 +2261,7 @@ u8 sub_8011628(s32 a0) if ((a0 >> i) & 1) { struct GFtgtGname *structPtr = (void *)gRfuLinkStatus->partner[i].gname; - if (structPtr->activity == 0x45) + if (structPtr->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) ret |= (1 << i); } } @@ -2204,22 +2269,22 @@ u8 sub_8011628(s32 a0) return ret; } -void sub_8011674(u8 a0, u8 unused1) +static void sub_8011674(u8 msg, u8 paramCount) { u8 r1; - switch (a0) + switch (msg) { - case 0x00: - Rfu.unk_04 = 0x11; + case LMAN_MSG_INITIALIZE_COMPLETED: + Rfu.state = 17; break; - case 0x10: + case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: RfuSetErrorStatus(4, 0); break; - case 0x11: - if (GetHostRFUtgtGname()->activity == 0x45 && Rfu.unk_cd9 == 0) + case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED: + if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && Rfu.unk_cd9 == 0) { - u8 idx = sub_8011628(lman.param[0]); + u8 idx = GetNewChildrenInUnionRoomChat(lman.param[0]); if (idx != 0) { r1 = 1 << sub_800E87C(idx); @@ -2227,7 +2292,7 @@ void sub_8011674(u8 a0, u8 unused1) { Rfu.unk_ce5 = r1; Rfu.unk_ce6 |= (r1 ^ idx); - Rfu.unk_ce8 = 1; + Rfu.unk_ce8 = TRUE; } else { @@ -2247,31 +2312,31 @@ void sub_8011674(u8 a0, u8 unused1) } sub_80115EC(lman.param[0]); break; - case 0x12: + case LMAN_MSG_NEW_CHILD_CONNECT_REJECTED: break; - case 0x13: + case LMAN_MSG_SEARCH_CHILD_PERIOD_EXPIRED: break; - case 0x14: - if (GetHostRFUtgtGname()->activity != 0x45 && lman.acceptCount > 1) + case LMAN_MSG_END_WAIT_CHILD_NAME: + if (GetHostRFUtgtGname()->activity != (ACTIVITY_CHAT | IN_UNION_ROOM) && lman.acceptCount > 1) { r1 = 1 << sub_800E87C(lman.param[0]); rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1); rfu_waitREQComplete(); } - if (Rfu.unk_04 == 0xF) - Rfu.unk_04 = 0x10; + if (Rfu.state == 15) + Rfu.state = 16; break; break; - case 0x20: - Rfu.unk_ccd = lman.param[0]; + case LMAN_MSG_PARENT_FOUND: + Rfu.parentId = lman.param[0]; break; - case 0x21: + case LMAN_MSG_SEARCH_PARENT_PERIOD_EXPIRED: break; - case 0x22: - Rfu.unk_c3e = lman.param[0]; + case LMAN_MSG_CONNECT_PARENT_SUCCESSED: + Rfu.childSlot = lman.param[0]; break; - case 0x23: - Rfu.unk_04 = 0x12; + case LMAN_MSG_CONNECT_PARENT_FAILED: + Rfu.state = 18; if (Rfu.unk_ccf < 2) { Rfu.unk_ccf++; @@ -2279,67 +2344,71 @@ void sub_8011674(u8 a0, u8 unused1) } else { - RfuSetErrorStatus(2, a0); + RfuSetErrorStatus(2, msg); } break; - case 0x24: - Rfu.unk_04 = 0xD; + case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: + Rfu.state = 13; RfuSetErrorStatus(3, 0); - rfu_setRecvBuffer(0x10, Rfu.unk_c3e, Rfu.unk_c3f, 70); + rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70); break; - case 0x25: - RfuSetErrorStatus(2, a0); + case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: + RfuSetErrorStatus(2, msg); break; - case 0x31: + case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: if (lman.acceptSlot_flag & lman.param[0]) - Rfu.unk_f0 = 1; + Rfu.linkLossRecoveryState = 1; break; - case 0x32: - Rfu.unk_f0 = 3; - if (gRfuLinkStatus->parentChild == 0) + case LMAN_MSG_LINK_RECOVERY_SUCCESSED: + Rfu.linkLossRecoveryState = 3; + if (gRfuLinkStatus->parentChild == MODE_CHILD) Rfu.unk_c3c = 1; break; - case 0x30: - Rfu.unk_f0 = 2; - case 0x33: - if (Rfu.unk_f0 != 2) - Rfu.unk_f0 = 4; - if (Rfu.unk_0c == 1) + case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: + Rfu.linkLossRecoveryState = 2; + case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: + if (Rfu.linkLossRecoveryState != 2) + Rfu.linkLossRecoveryState = 4; + if (Rfu.parentChild == MODE_PARENT) { if (gReceivedRemoteLinkPlayers == 1) { Rfu.unk_ce2 &= ~(lman.param[0]); if (Rfu.unk_ce2 == 0) - sub_8011170(a0); + GetLinkmanErrorParams(msg); else sub_80111FC(); } } else if (Rfu.unk_ce4 != 2 && gReceivedRemoteLinkPlayers == 1) { - sub_8011170(a0); + GetLinkmanErrorParams(msg); rfu_LMAN_stopManager(0); } - if (gRfuLinkStatus->parentChild == 0xFF && lman.pcswitch_flag == 0 && FuncIsActiveTask(sub_800EB44) == TRUE) - Rfu.unk_04 = 0x11; + if (gRfuLinkStatus->parentChild == MODE_NEUTRAL && lman.pcswitch_flag == 0 && FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) + Rfu.state = 17; - RfuSetErrorStatus(2, a0); + RfuSetErrorStatus(2, msg); break; - case 0x40: + case LMAN_MSG_LINK_DISCONNECTED_BY_USER: Rfu.unk_ce3 = 0; break; - case 0x42 ... 0x44: + case LMAN_MSG_RFU_POWER_DOWN: + case LMAN_MSG_MANAGER_STOPPED: + case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; - case 0xF3: - RfuSetErrorStatus(1, a0); - sub_8011170(a0); - Rfu.unk_ef = 1; + case LMAN_MSG_LMAN_API_ERROR_RETURN: + RfuSetErrorStatus(1, msg); + GetLinkmanErrorParams(msg); + Rfu.isShuttingDown = TRUE; break; - case 0xF0 ... 0xF2: - case 0xFF: - sub_8011170(a0); - RfuSetErrorStatus(1, a0); + case LMAN_MSG_REQ_API_ERROR: + case LMAN_MSG_WATCH_DOG_TIMER_ERROR: + case LMAN_MSG_CLOCK_SLAVE_MS_CHANGE_ERROR_BY_DMA: + case LMAN_MSG_RFU_FATAL_ERROR: + GetLinkmanErrorParams(msg); + RfuSetErrorStatus(1, msg); Rfu.unk_cdb = 0; break; } @@ -2350,15 +2419,15 @@ void sub_8011A50(void) Rfu.unk_ce4 = 2; } -void RfuSetErrorStatus(u8 a0, u16 a1) +void RfuSetErrorStatus(u8 status, u16 msg) { - Rfu.unk_f1 = a0; - Rfu.unk_0a = a1; + Rfu.errorStatus = status; + Rfu.linkmanMsg = msg; } u8 RfuGetErrorStatus(void) { - return Rfu.unk_f1; + return Rfu.errorStatus; } bool32 RfuIsErrorStatus1or2(void) @@ -2377,7 +2446,7 @@ bool32 sub_8011A9C(void) bool8 Rfu_IsMaster(void) { - return Rfu.unk_0c; + return Rfu.parentChild; } void RfuVSync(void) @@ -2390,14 +2459,14 @@ void sub_8011AC8(void) CpuFill32(0, gRecvCmds, sizeof(gRecvCmds)); } -void sub_8011AE8(void) +static void sub_8011AE8(void) { LoadOam(); ProcessSpriteCopyRequests(); TransferPlttBuffer(); } -void sub_8011AFC(void) +static void sub_8011AFC(void) { s32 i; @@ -2420,29 +2489,29 @@ void sub_8011AFC(void) AnimateSprites(); BuildOamBuffer(); UpdatePaletteFade(); - sub_8011BA4(); + CreateTask_RfuIdle(); SetMainCallback2(sub_8011BF8); } } bool32 IsUnionRoomListenTaskActive(void) { - return FuncIsActiveTask(sub_800EB44); + return FuncIsActiveTask(Task_LinkRfu_UnionRoomListen); } -void sub_8011BA4(void) +void CreateTask_RfuIdle(void) { - if (!FuncIsActiveTask(nullsub_89)) - Rfu.unk_66 = CreateTask(nullsub_89, 0); + if (!FuncIsActiveTask(Task_Idle)) + Rfu.idleTaskId = CreateTask(Task_Idle, 0); } -void sub_8011BD0(void) +void DestroyTask_RfuIdle(void) { - if (FuncIsActiveTask(nullsub_89) == TRUE) - DestroyTask(Rfu.unk_66); + if (FuncIsActiveTask(Task_Idle) == TRUE) + DestroyTask(Rfu.idleTaskId); } -void sub_8011BF8(void) +static void sub_8011BF8(void) { RunTasks(); AnimateSprites(); @@ -2452,75 +2521,75 @@ void sub_8011BF8(void) void InitializeRfuLinkManager_LinkLeader(u32 a0) { - Rfu.unk_0c = 1; - sub_8010F48(); + Rfu.parentChild = MODE_PARENT; + CopyPlayerNameToUnameBuffer(); rfu_LMAN_initializeManager(sub_801120C, NULL); - gUnknown_02022B2C = gUnknown_082ED608; - gUnknown_02022B2C.availSlot_flag = gUnknown_082ED620[a0 - 1]; - sub_800EE78(); + sRfuReqConfig = sRfuReqConfigTemplate; + sRfuReqConfig.availSlot_flag = sAvailSlots[a0 - 1]; + CreateTask_LinkLeaderSearchForChildren(); } void InitializeRfuLinkManager_JoinGroup(void) { - Rfu.unk_0c = 0; - sub_8010F48(); + Rfu.parentChild = MODE_CHILD; + CopyPlayerNameToUnameBuffer(); rfu_LMAN_initializeManager(sub_8011404, sub_800ED34); - sub_800EF00(); + CreateTask_JoinGroupSearchForParent(); } void InitializeRfuLinkManager_EnterUnionRoom(void) { - Rfu.unk_0c = 2; - sub_8010F48(); + Rfu.parentChild = 2; + CopyPlayerNameToUnameBuffer(); rfu_LMAN_initializeManager(sub_8011674, NULL); - gUnknown_02022B2C = gUnknown_082ED608; - gUnknown_02022B2C.linkRecovery_enable = 0; - gUnknown_02022B2C.linkRecovery_period = 0x258; - Rfu.unk_67 = CreateTask(sub_800EB44, 1); + sRfuReqConfig = sRfuReqConfigTemplate; + sRfuReqConfig.linkRecovery_enable = 0; + sRfuReqConfig.linkRecovery_period = 600; + Rfu.searchTaskId = CreateTask(Task_LinkRfu_UnionRoomListen, 1); } -u16 ReadU16(const void *ptr) +static u16 ReadU16(const void *ptr) { const u8 *ptr_ = ptr; return (ptr_[1] << 8) | (ptr_[0]); } -u8 sub_8011CE4(const u8 *a0, u16 a1) +static u8 GetPartnerIndexByNameAndTrainerID(const u8 *name, u16 id) { u8 i; - u8 ret = 0xFF; + u8 idx = 0xFF; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { u16 trainerId = ReadU16(gRfuLinkStatus->partner[i].gname + 2); - if (sub_8010454(gRfuLinkStatus->partner[i].serialNo) - && !StringCompare(a0, gRfuLinkStatus->partner[i].uname) - && a1 == trainerId) + if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[i].serialNo) + && !StringCompare(name, gRfuLinkStatus->partner[i].uname) + && id == trainerId) { - ret = i; + idx = i; if (gRfuLinkStatus->partner[i].slot != 0xFF) break; } } - return ret; + return idx; } -void sub_8011D6C(u32 a0) +static void RfuReqDisconnectSlot(u32 slot) { - rfu_REQ_disconnect(a0); + rfu_REQ_disconnect(slot); rfu_waitREQComplete(); - Rfu.unk_ce2 &= ~(a0); + Rfu.unk_ce2 &= ~(slot); rfu_clearSlot(1, Rfu.unk_cda); - rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.unk_c87, 70); + rfu_UNI_setSendData(Rfu.unk_ce2, Rfu.recvCmds, 70); Rfu.unk_cda = sub_800E87C(Rfu.unk_ce2); } -void RequestDisconnectSlotByTrainerNameAndId(const u8 *ptr, u16 a1) +void RequestDisconnectSlotByTrainerNameAndId(const u8 *name, u16 id) { - u8 var = sub_8011CE4(ptr, a1); + u8 var = GetPartnerIndexByNameAndTrainerID(name, id); if (var != 0xFF) - sub_8011D6C(1 << var); + RfuReqDisconnectSlot(1 << var); } void sub_8011DE0(u32 a0) @@ -2530,9 +2599,9 @@ void sub_8011DE0(u32 a0) s32 i; u8 var = 0; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.unk_cde[i] == a0 && (Rfu.unk_ce2 >> i) & 1) + if (Rfu.linkPlayerIdx[i] == a0 && (Rfu.unk_ce2 >> i) & 1) var |= 1 << i; } if (var) @@ -2540,20 +2609,20 @@ void sub_8011DE0(u32 a0) } } -void sub_8011E2C(u8 taskId) +static void sub_8011E2C(u8 taskId) { if (gSendCmd[0] == 0 && Rfu.unk_ce8 == 0) { - sub_800FD14(0xED00); + RfuPrepareSendBuffer(RFU_COMMAND_0xED00); gSendCmd[1] = gTasks[taskId].data[0]; gSendCmd[2] = gTasks[taskId].data[1]; - Rfu.playerCount -= gUnknown_082ED695[gTasks[taskId].data[0]]; + Rfu.playerCount -= sUnknown_082ED695[gTasks[taskId].data[0]]; gSendCmd[3] = Rfu.playerCount; DestroyTask(taskId); } } -void sub_8011E94(u32 a0, u32 a1) +static void sub_8011E94(u32 a0, u32 a1) { u8 taskId = FindTaskIdByFunc(sub_8011E2C); if (taskId == 0xFF) @@ -2569,22 +2638,23 @@ void sub_8011E94(u32 a0, u32 a1) gTasks[taskId].data[1] = a1; } -void sub_8011EF4(u8 taskId) +static void Task_RfuReconnectWithParent(u8 taskId) { s16 *data = gTasks[taskId].data; if (sub_800EE94()) { - u8 id = sub_8011CE4((u8*)data, ReadU16(&data[8])); + u8 id = GetPartnerIndexByNameAndTrainerID((u8*)data, ReadU16(&data[8])); if (id != 0xFF) { if (gRfuLinkStatus->partner[id].slot != 0xFF) { Rfu.unk_c3d = id; - if (sub_800EEBC()) + if (IsParentSuccessfullyReconnected()) DestroyTask(taskId); } - else if (GetHostRFUtgtGname()->activity == 0x15 || GetHostRFUtgtGname()->activity == 0x16) + else if (GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_CARD2 + || GetHostRFUtgtGname()->activity == ACTIVITY_WONDER_NEWS2) { data[15]++; } @@ -2612,42 +2682,42 @@ void sub_8011EF4(u8 taskId) } } -void CreateTask_RfuReconnectWithParent(const u8 *src, u16 trainerId) +void CreateTask_RfuReconnectWithParent(const u8 *name, u16 trainerId) { u8 taskId; s16 *data; - Rfu.unk_f1 = 0; - taskId = CreateTask(sub_8011EF4, 3); + Rfu.errorStatus = 0; + taskId = CreateTask(Task_RfuReconnectWithParent, 3); data = gTasks[taskId].data; - StringCopy((u8*)(data), src); + StringCopy((u8*)(data), name); data[8] = trainerId; } -bool32 sub_801200C(s16 a1, struct GFtgtGname *structPtr) +static bool32 ShouldRejectPartnerConnectionBasedOnActivity(s16 activity, struct GFtgtGname *partnerGname) { - if (GetHostRFUtgtGname()->activity == 0x45) + if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { - if (structPtr->activity != 0x45) + if (partnerGname->activity != (ACTIVITY_CHAT | IN_UNION_ROOM)) return TRUE; } - else if (structPtr->activity != 0x40) + else if (partnerGname->activity != IN_UNION_ROOM) { return TRUE; } - else if (a1 == 0x44) + else if (activity == (ACTIVITY_TRADE | IN_UNION_ROOM)) { - struct GFtgtGname *structPtr2 = &Rfu.unk_10A; - if (structPtr2->species == SPECIES_EGG) + struct GFtgtGname *tradeGname = &Rfu.unk_10A; + if (tradeGname->species == SPECIES_EGG) { - if (structPtr->species == structPtr2->species) + if (partnerGname->species == tradeGname->species) return FALSE; else return TRUE; } - else if (structPtr->species != structPtr2->species - || structPtr->level != structPtr2->level - || structPtr->type != structPtr2->type) + else if (partnerGname->species != tradeGname->species + || partnerGname->level != tradeGname->level + || partnerGname->type != tradeGname->type) { return TRUE; } @@ -2656,9 +2726,9 @@ bool32 sub_801200C(s16 a1, struct GFtgtGname *structPtr) return FALSE; } -void sub_801209C(u8 taskId) +static void sub_801209C(u8 taskId) { - if (Rfu.unk_f1 == 4) + if (Rfu.errorStatus == 4) DestroyTask(taskId); if (++gTasks[taskId].data[0] > 300) @@ -2667,17 +2737,17 @@ void sub_801209C(u8 taskId) DestroyTask(taskId); } - if (Rfu.unk_ccd != 0 && lman.parent_child == 0) + if (Rfu.parentId != 0 && lman.parent_child == 0) { u16 trainerId = ReadU16(Rfu.unk_10A.unk_00.playerTrainerId); - u8 id = sub_8011CE4(Rfu.playerName, trainerId); + u8 id = GetPartnerIndexByNameAndTrainerID(Rfu.playerName, trainerId); if (id != 0xFF) { - if (!sub_801200C(gTasks[taskId].data[1], (void *)gRfuLinkStatus->partner[id].gname)) + if (!ShouldRejectPartnerConnectionBasedOnActivity(gTasks[taskId].data[1], (void *)gRfuLinkStatus->partner[id].gname)) { if (gRfuLinkStatus->partner[id].slot != 0xFF && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[id].id, 0x5A)) { - Rfu.unk_04 = 0xA; + Rfu.state = 0xA; DestroyTask(taskId); } } @@ -2690,19 +2760,19 @@ void sub_801209C(u8 taskId) } } -void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2) +void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 activity) { u8 taskId, taskId2; Rfu.unk_ccf = 0; - Rfu.unk_f1 = 0; + Rfu.errorStatus = 0; StringCopy(Rfu.playerName, name); - memcpy(&Rfu.unk_10A, structPtr, 0xD); + memcpy(&Rfu.unk_10A, structPtr, RFU_GAME_NAME_LENGTH); rfu_LMAN_forceChangeSP(); taskId = CreateTask(sub_801209C, 2); - gTasks[taskId].data[1] = a2; - taskId2 = FindTaskIdByFunc(sub_800EB44); - if (a2 == 0x45) + gTasks[taskId].data[1] = activity; + taskId2 = FindTaskIdByFunc(Task_LinkRfu_UnionRoomListen); + if (activity == (ACTIVITY_CHAT | IN_UNION_ROOM)) { if (taskId2 != 0xFF) gTasks[taskId2].data[7] = 1; @@ -2716,7 +2786,7 @@ void sub_8012188(const u8 *name, struct GFtgtGname *structPtr, u8 a2) bool8 sub_8012224(void) { - if (Rfu.unk_f0 == 1) + if (Rfu.linkLossRecoveryState == 1) return TRUE; else return FALSE; @@ -2726,7 +2796,7 @@ bool32 sub_8012240(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((lman.acceptSlot_flag >> i) & 1 && Rfu.unk_cd1[i] == 0) return FALSE; @@ -2735,52 +2805,52 @@ bool32 sub_8012240(void) return TRUE; } -void sub_801227C(void) +static void Debug_PrintEmpty(void) { s32 i; for (i = 0; i < 20; i++) - nullsub_5(gUnknown_082ED82C, 0, i); + Debug_PrintString(sASCII_30Commas, 0, i); } -void sub_801229C(void) +static void Debug_PrintStatus(void) { s32 i, j; - nullsub_13(GetBlockReceivedStatus(), 0x1C, 0x13, 2); - nullsub_13(gRfuLinkStatus->connSlotFlag, 0x14, 1, 1); - nullsub_13(gRfuLinkStatus->linkLossSlotFlag, 0x17, 1, 1); - if (Rfu.unk_0c == 1) + Debug_PrintNum(GetBlockReceivedStatus(), 0x1C, 0x13, 2); + Debug_PrintNum(gRfuLinkStatus->connSlotFlag, 0x14, 1, 1); + Debug_PrintNum(gRfuLinkStatus->linkLossSlotFlag, 0x17, 1, 1); + if (Rfu.parentChild == MODE_PARENT) { - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { if ((gRfuLinkStatus->getNameFlag >> i) & 1) { - nullsub_13(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); - nullsub_5((void*)gRfuLinkStatus->partner[i].gname, 6, i + 3); - nullsub_5(gRfuLinkStatus->partner[i].uname, 0x16, i + 3); + Debug_PrintNum(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); + Debug_PrintString((void*)gRfuLinkStatus->partner[i].gname, 6, i + 3); + Debug_PrintString(gRfuLinkStatus->partner[i].uname, 0x16, i + 3); } } - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { for (j = 0; j < 14; j++) { - nullsub_13(Rfu.unk_14[i][j], j * 2, i + 11, 2); + Debug_PrintNum(Rfu.unk_14[i][j], j * 2, i + 11, 2); } } - nullsub_5(gUnknown_082ED868, 1, 0xF); + Debug_PrintString(sASCII_NowSlot, 1, 0xF); } else if (gRfuLinkStatus->connSlotFlag != 0 && gRfuLinkStatus->getNameFlag != 0) { - for (i = 0; i < 4; i++) + for (i = 0; i < RFU_CHILD_MAX; i++) { - nullsub_13(0, 1, i + 3, 4); - nullsub_5(gUnknown_082ED84B, 6, i + 3); - nullsub_5(gUnknown_082ED85B, 0x16, i + 3); + Debug_PrintNum(0, 1, i + 3, 4); + Debug_PrintString(sASCII_15Commas, 6, i + 3); + Debug_PrintString(sASCII_8Commas, 0x16, i + 3); } - nullsub_13(gRfuLinkStatus->partner[Rfu.unk_c3e].serialNo, 1, 3, 4); - nullsub_5((void*)gRfuLinkStatus->partner[Rfu.unk_c3e].gname, 6, 3); - nullsub_5(gRfuLinkStatus->partner[Rfu.unk_c3e].uname, 0x16, 3); + Debug_PrintNum(gRfuLinkStatus->partner[Rfu.childSlot].serialNo, 1, 3, 4); + Debug_PrintString((void*)gRfuLinkStatus->partner[Rfu.childSlot].gname, 6, 3); + Debug_PrintString(gRfuLinkStatus->partner[Rfu.childSlot].uname, 0x16, 3); } else { @@ -2788,31 +2858,31 @@ void sub_801229C(void) { if (gRfuLinkStatus->partner[i].slot != 0xFF) { - nullsub_13(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); - nullsub_13(gRfuLinkStatus->partner[i].id, 6, i + 3, 4); - nullsub_5(gRfuLinkStatus->partner[i].uname, 0x16, i + 3); + Debug_PrintNum(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); + Debug_PrintNum(gRfuLinkStatus->partner[i].id, 6, i + 3, 4); + Debug_PrintString(gRfuLinkStatus->partner[i].uname, 0x16, i + 3); } } - for (; i < 4; i++) + for (; i < RFU_CHILD_MAX; i++) { - nullsub_13(0, 1, i + 3, 4); - nullsub_5(gUnknown_082ED84B, 6, i + 3); - nullsub_5(gUnknown_082ED85B, 0x16, i + 3); + Debug_PrintNum(0, 1, i + 3, 4); + Debug_PrintString(sASCII_15Commas, 6, i + 3); + Debug_PrintString(sASCII_8Commas, 0x16, i + 3); } } } -u32 sub_80124C0(void) +static u32 GetRfuSendQueueLength(void) { - return Rfu.unk_9e8.unk_232; + return Rfu.sendQueue.count; } u32 GetRfuRecvQueueLength(void) { - return Rfu.unk_124.unk_8c2; + return Rfu.recvQueue.count; } -void nullsub_89(u8 taskId) +static void Task_Idle(u8 taskId) { } diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index b7d3e808c..dc032b403 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -165,7 +165,7 @@ const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { SpriteCallbackDummy }; -void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr) +void sub_800D6C8(struct RfuRecvQueue *ptr) { s32 i; s32 j; @@ -179,11 +179,11 @@ void sub_800D6C8(struct UnkRfuStruct_2_Sub_124 *ptr) } ptr->unk_8c1 = 0; ptr->unk_8c0 = 0; - ptr->unk_8c2 = 0; - ptr->unk_8c3 = 0; + ptr->count = 0; + ptr->full = FALSE; } -void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr) +void sub_800D724(struct RfuSendQueue *ptr) { s32 i; s32 j; @@ -197,8 +197,8 @@ void sub_800D724(struct UnkRfuStruct_2_Sub_9e8 *ptr) } ptr->unk_231 = 0; ptr->unk_230 = 0; - ptr->unk_232 = 0; - ptr->unk_233 = 0; + ptr->count = 0; + ptr->full = FALSE; } void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr) @@ -219,13 +219,13 @@ void sub_800D780(struct UnkRfuStruct_Sub_Unused *ptr) ptr->unk_203 = 0; } -void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2) +void sub_800D7D8(struct RfuRecvQueue *q1, u8 *q2) { s32 i; u16 imeBak; u8 count; - if (q1->unk_8c2 < 32) + if (q1->count < 32) { imeBak = REG_IME; REG_IME = 0; @@ -245,7 +245,7 @@ void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2) } q1->unk_8c0++; q1->unk_8c0 %= 32; - q1->unk_8c2++; + q1->count++; for (i = 0; i < 70; i++) { q2[i] = 0; @@ -255,16 +255,16 @@ void sub_800D7D8(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2) } else { - q1->unk_8c3 = 1; + q1->full = TRUE; } } -void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2) +void sub_800D888(struct RfuSendQueue *q1, u8 *q2) { s32 i; u16 imeBak; - if (q1->unk_232 < 40) + if (q1->count < 40) { imeBak = REG_IME; REG_IME = 0; @@ -283,7 +283,7 @@ void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2) } q1->unk_230++; q1->unk_230 %= 40; - q1->unk_232++; + q1->count++; for (i = 0; i < 14; i++) { q2[i] = 0; @@ -293,18 +293,18 @@ void sub_800D888(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2) } else { - q1->unk_233 = 1; + q1->full = TRUE; } } -bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2) +bool8 sub_800D934(struct RfuRecvQueue *q1, u8 *q2) { u16 imeBak; s32 i; imeBak = REG_IME; REG_IME = 0; - if (q1->unk_8c0 == q1->unk_8c1 || q1->unk_8c3 != 0) + if (q1->unk_8c0 == q1->unk_8c1 || q1->full) { for (i = 0; i < 70; i++) { @@ -319,17 +319,17 @@ bool8 sub_800D934(struct UnkRfuStruct_2_Sub_124 *q1, u8 *q2) } q1->unk_8c1++; q1->unk_8c1 %= 32; - q1->unk_8c2--; + q1->count--; REG_IME = imeBak; return TRUE; } -bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2) +bool8 sub_800D9DC(struct RfuSendQueue *q1, u8 *q2) { s32 i; u16 imeBak; - if (q1->unk_230 == q1->unk_231 || q1->unk_233 != 0) + if (q1->unk_230 == q1->unk_231 || q1->full) { return FALSE; } @@ -341,7 +341,7 @@ bool8 sub_800D9DC(struct UnkRfuStruct_2_Sub_9e8 *q1, u8 *q2) } q1->unk_231++; q1->unk_231 %= 40; - q1->unk_232--; + q1->count--; REG_IME = imeBak; return TRUE; } @@ -362,9 +362,9 @@ void sub_800DA68(struct UnkRfuStruct_2_Sub_c1c *q1, const u8 *q2) } q1->unk_1c++; q1->unk_1c %= 2; - if (q1->unk_1e < 2) + if (q1->count < 2) { - q1->unk_1e++; + q1->count++; } else { @@ -377,7 +377,7 @@ bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2) { s32 i; - if (q1->unk_1e == 0) + if (q1->count == 0) { return FALSE; } @@ -390,7 +390,7 @@ bool8 sub_800DAC8(struct UnkRfuStruct_2_Sub_c1c *q1, u8 *q2) } q1->unk_1d++; q1->unk_1d %= 2; - q1->unk_1e--; + q1->count--; return TRUE; } @@ -632,7 +632,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) if (lman.parent_child == 1) { retVal = TRUE; - if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1)) + if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1)) { memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD); memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); @@ -646,7 +646,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx) else { retVal = FALSE; - if (sub_8010454(gRfuLinkStatus->partner[idx].serialNo)) + if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[idx].serialNo)) { memcpy(buff1, gRfuLinkStatus->partner[idx].gname, 0xD); memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); @@ -679,8 +679,8 @@ bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx) void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2) { - memcpy(buff1, &gUnknown_02022B14, 0xD); - memcpy(buff2, gUnknown_02022B22, 8); + memcpy(buff1, &gHostRFUtgtGnameBuffer, 0xD); + memcpy(buff2, gHostRFUtgtUnameBuffer, 8); } void CreateWirelessStatusIndicatorSprite(u8 x, u8 y) diff --git a/src/main.c b/src/main.c index cf19f39b3..b95839e82 100644 --- a/src/main.c +++ b/src/main.c @@ -113,7 +113,7 @@ void AgbMain() InitIntrHandlers(); m4aSoundInit(); EnableVCountIntrAtLine150(); - sub_800E6D0(); + InitRFU(); RtcInit(); CheckForFlashMemory(); InitMainCallbacks(); diff --git a/src/overworld.c b/src/overworld.c index 72bc38693..87e394e39 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2913,7 +2913,7 @@ bool32 sub_808766C(void) static u32 GetLinkSendQueueLength(void) { if (gWirelessCommType != 0) - return Rfu.unk_9e8.unk_232; + return Rfu.sendQueue.count; else return gLink.sendQueue.count; } diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index acfd4d545..738e0089d 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -216,7 +216,7 @@ static bool32 sub_802C618(void); static bool32 sub_802C650(void); static void sub_802C688(int); static int sub_802C6B0(void); -static bool32 sub_802C70C(void); +static bool32 AreLinkQueuesEmpty(void); static int sub_802C73C(u8 *); static void sub_802C780(void); static int sub_802C790(int); @@ -876,7 +876,7 @@ static bool32 sub_802B31C(void) gUnknown_02022CFC->unk8++; // fall through case 1: - if (sub_802C70C()) + if (AreLinkQueuesEmpty()) return FALSE; break; } @@ -1146,7 +1146,7 @@ static bool32 sub_802B720(void) } break; case 2: - if (sub_802C70C()) + if (AreLinkQueuesEmpty()) { CreateTask(Task_LinkSave, 6); gUnknown_02022CFC->unk8++; @@ -2025,9 +2025,9 @@ static int sub_802C6B0(void) return count; } -static bool32 sub_802C70C(void) +static bool32 AreLinkQueuesEmpty(void) { - return !Rfu.unk_124.unk_8c2 && !Rfu.unk_9e8.unk_232; + return !Rfu.recvQueue.count && !Rfu.sendQueue.count; } static int sub_802C73C(u8 *arg0) diff --git a/src/trade.c b/src/trade.c index 624f6eae9..3a0f07ac6 100644 --- a/src/trade.c +++ b/src/trade.c @@ -396,7 +396,7 @@ static void CB2_CreateTradeMenu(void) { SetWirelessCommType1(); OpenLink(); - sub_8011BA4(); + CreateTask_RfuIdle(); } else { @@ -438,7 +438,7 @@ static void CB2_CreateTradeMenu(void) case 4: if (gReceivedRemoteLinkPlayers == TRUE && IsLinkPlayerDataExchangeComplete() == TRUE) { - sub_8011BD0(); + DestroyTask_RfuIdle(); CalculatePlayerPartyCount(); gMain.state++; sTradeMenuData->timer = 0; diff --git a/src/union_room.c b/src/union_room.c index 8f49add80..ac32e15f2 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -2338,7 +2338,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case 2: SetHostRFUtgtGname(IN_UNION_ROOM, 0, 0); - sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); + SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); SetWirelessCommType1(); OpenLink(); InitializeRfuLinkManager_EnterUnionRoom(); @@ -2361,7 +2361,7 @@ static void Task_RunUnionRoom(u8 taskId) if (id >= PARTY_SIZE) { ResetUnionRoomTrade(&sUnionRoomTrade); - sub_8010FCC(0, 0, 0); + SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0); ScheduleFieldMessageAndExit(sText_RegistrationCanceled); } else if (!RegisterTradeMonAndGetIsEgg(GetCursorSelectionMonId(), &sUnionRoomTrade)) @@ -2453,7 +2453,7 @@ static void Task_RunUnionRoom(u8 taskId) case 4: data->state = 11; UR_EnableScriptContext2AndFreezeObjectEvents(); - sub_8010FCC(0, 0, 0); + SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0); UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_NPCTALK | IN_UNION_ROOM, GetActivePartnerSpriteGenderParam(data), 0); break; } @@ -2931,7 +2931,7 @@ static void Task_RunUnionRoom(u8 taskId) case -2: case 18: ResetUnionRoomTrade(&sUnionRoomTrade); - sub_8010FCC(0, 0, 0); + SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0); ScheduleFieldMessageAndExit(sText_RegistrationCanceled); break; default: @@ -2942,7 +2942,7 @@ static void Task_RunUnionRoom(u8 taskId) } break; case 55: - sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); + SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); ScheduleFieldMessageAndExit(sText_RegistraionCompleted); break; case 44: @@ -2961,7 +2961,7 @@ static void Task_RunUnionRoom(u8 taskId) case 56: if (PrintOnTextbox(&data->textState, sText_RegistrationCanceled2)) { - sub_8010FCC(0, 0, 0); + SetTradeBoardRegisteredMonInfo(TYPE_NORMAL, SPECIES_NONE, 0); ResetUnionRoomTrade(&sUnionRoomTrade); HandleCancelTrade(TRUE); data->state = 4; @@ -4265,7 +4265,7 @@ static void HandleCancelTrade(bool32 unlockObjs) gPlayerCurrActivity = 0; if (unlockObjs) { - sub_8010FCC(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); + SetTradeBoardRegisteredMonInfo(sUnionRoomTrade.type, sUnionRoomTrade.playerSpecies, sUnionRoomTrade.playerLevel); UpdateGameDataWithActivitySpriteGendersFlag(IN_UNION_ROOM, 0, 0); } }