diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cable_club.c | 4 | ||||
-rw-r--r-- | src/link.c | 18 | ||||
-rw-r--r-- | src/link_rfu_2.c | 953 | ||||
-rw-r--r-- | src/link_rfu_3.c | 498 | ||||
-rw-r--r-- | src/mystery_gift_menu.c | 4 | ||||
-rw-r--r-- | src/pokemon_jump_2.c | 2 | ||||
-rw-r--r-- | src/union_room.c | 52 | ||||
-rw-r--r-- | src/union_room_chat.c | 24 |
8 files changed, 879 insertions, 676 deletions
diff --git a/src/cable_club.c b/src/cable_club.c index 34b023281..c3de9dd26 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -516,7 +516,7 @@ u8 CreateTask_ReestablishLinkInCableClubRoom(void) gLinkType = LINKTYPE_MULTI_BATTLE; break; case USING_TRADE_CENTER: - gLinkType = LINKTYPE_0x1111; + gLinkType = LINKTYPE_TRADE; break; case USING_RECORD_CORNER: gLinkType = LINKTYPE_0x3322; @@ -859,7 +859,7 @@ static void Task_StartWirelessCableClubTrade(u8 taskId) case 0: ScriptContext2_Enable(); FadeScreen(FADE_TO_BLACK, 0); - Rfu_set_zero(); + ClearLinkRfuCallback(); data[0]++; break; case 1: diff --git a/src/link.c b/src/link.c index d3c0cccec..8122aafc0 100644 --- a/src/link.c +++ b/src/link.c @@ -226,7 +226,7 @@ bool8 IsWirelessAdapterConnected(void) return FALSE; SetWirelessCommType1(); - sub_80F86F4(); + InitRFUAPI(); sub_80FB128(TRUE); if (rfu_LMAN_REQBN_softReset_and_checkID() == RFU_ID) { @@ -378,7 +378,7 @@ void OpenLink(void) } else { - sub_80F86F4(); + InitRFUAPI(); } gReceivedRemoteLinkPlayers = FALSE; for (i = 0; i < MAX_LINK_PLAYERS; i++) @@ -749,7 +749,7 @@ void ClearLinkCallback_2(void) { if (gWirelessCommType) { - Rfu_set_zero(); + ClearLinkRfuCallback(); } else { @@ -1003,7 +1003,7 @@ bool8 Link_PrepareCmd0xCCCC_Rfu0xA100(u8 blockRequestType) { if (gWirelessCommType == 1) { - return LinkRfu_PrepareCmd0xA100(blockRequestType); + return Rfu_SendBlockRequest(blockRequestType); } if (gLinkCallback == NULL) { @@ -1309,7 +1309,7 @@ void Link_StartSend5FFFwithParam(u16 a0) { if (gWirelessCommType == 1) { - Rfu_BeginBuildAndSendCommand5F(); + Rfu_SetCloseLinkCallback(); } else { @@ -1326,7 +1326,7 @@ void SetCloseLinkCallback(void) { if (gWirelessCommType == 1) { - Rfu_BeginBuildAndSendCommand5F(); + Rfu_SetCloseLinkCallback(); } else { @@ -1441,12 +1441,12 @@ static void CheckErrorStatus(void) } } -void SetLinkErrorFromRfu(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06) +void SetLinkErrorFromRfu(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 isConnectionError) { sLinkErrorBuffer.status = status; sLinkErrorBuffer.lastSendQueueCount = lastSendQueueCount; sLinkErrorBuffer.lastRecvQueueCount = lastRecvQueueCount; - sLinkErrorBuffer.unk_06 = unk_06; + sLinkErrorBuffer.unk_06 = isConnectionError; } void CB2_LinkError(void) @@ -1619,7 +1619,7 @@ bool8 HasLinkErrorOccurred(void) return gLinkErrorOccurred; } -void PrepareLocalLinkPlayerBlock(void) +void LocalLinkPlayerToBlock(void) { struct LinkPlayerBlock * block; diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 8c7447264..76db5d1b0 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -20,8 +20,22 @@ struct SioInfo u8 fill_a0[0x5c]; }; -static EWRAM_DATA struct InitializeParametersTag sRfuReqConfig = {}; -static EWRAM_DATA struct UnkLinkRfuStruct_02022B44 gUnknown_203AC08 = {}; +struct RfuDebug +{ + u8 fill_00[6]; + u16 unk_06; + u8 fill_08[6]; + vu8 unk_0e; + u8 unk_0f; + u8 fill_10[0x54]; + u16 unk_64; + u8 fill_66[0x1d]; + u8 unk_83; + u8 fill_84[0x58]; +}; + +static EWRAM_DATA INIT_PARAM sRfuReqConfig = {}; +static EWRAM_DATA struct RfuDebug sRfuDebug = {}; static u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4]; static u8 sResendBlock8[14]; @@ -35,18 +49,18 @@ static void sub_80F8AA4(void); static void sub_80F8AEC(void); static void MscCallback_Child(u16 a0); static void MSCCallback_SetUnkCDB(u16 a0); -static void sub_80F906C(void); +static void UpdateBackupQueue(void); static void RfuHandleReceiveCommand(u8 unused); static void ResetSendDataManager(struct RfuBlockSend *data); static void RfuPrepareSendBuffer(u16 command); -static void RfuFunc_HandleBlockSend(void); -static void RfuFunc_SendNextBlock(void); -static void RfuFunc_SendLastBlock(void); +static void HandleBlockSend(void); +static void SendNextBlock(void); +static void SendLastBlock(void); static void CallRfuFunc(void); -static void sub_80FA738(void); -static s32 sub_80FA788(void); +static void UpdateChildStatuses(void); +static s32 GetRfuRecvStatus(void); static void sub_80FA834(u8 taskId); -static void sub_80FA9D0(u16 a0); +static void ClearSelectedLinkPlayerIds(u16 disconnectMask); static void ValidateAndReceivePokemonSioInfo(void * a0); static void Task_ExchangeLinkPlayers(u8 taskId); static void sub_80FACF0(u8 taskId); @@ -57,10 +71,10 @@ static u8 GetPartnerIndexByNameAndTrainerID(const u8 *trainerName, u16 trainerId static void RfuReqDisconnectSlot(u32 bmDisconnectSlot); static void sub_80FBE20(u32 a0, u32 a1); static void sub_80FC028(u8 taskId); -static void rfu_dbg_clear(void); +static void Debug_PrintEmpty(void); static void Task_idle(u8 taskId); -static const struct InitializeParametersTag sRfuReqConfigTemplate = { +static const INIT_PARAM sRfuReqConfigTemplate = { .maxMFrame = 4, .MC_TimerCount = 32, .availSlot_flag = 0, @@ -115,21 +129,45 @@ static const u8 gUnknown_843EC38[] = { 2, 2, 3 }; -static const u8 gUnknown_843EC41[] = { - 0, 1, 1, 2, - 1, 2, 2, 3, - 1, 2, 2, 3, - 2, 3, 3, 4 +static const u8 sNumSetBits[] = { + [0x0] = 0, + [0x1] = 1, + [0x2] = 1, + [0x3] = 2, + [0x4] = 1, + [0x5] = 2, + [0x6] = 2, + [0x7] = 3, + [0x8] = 1, + [0x9] = 2, + [0xA] = 2, + [0xB] = 3, + [0xC] = 2, + [0xD] = 3, + [0xE] = 3, + [0xF] = 4 }; -static const u8 gUnknown_843EC51[] = { - 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 +static const u8 sNumTrailingZeroes[] = { + [0x0] = 0, + [0x1] = 0, + [0x2] = 1, + [0x3] = 0, + [0x4] = 2, + [0x5] = 0, + [0x6] = 1, + [0x7] = 0, + [0x8] = 3, + [0x9] = 0, + [0xA] = 1, + [0xB] = 0, + [0xC] = 2, + [0xD] = 0, + [0xE] = 1, + [0xF] = 0 }; -static const struct { - u8 *buffer; - u32 size; -} gUnknown_843EC64[] = { +static const struct BlockRequest sBlockRequests[] = { { gBlockSendBuffer, 200 }, { gBlockSendBuffer, 200 }, { gBlockSendBuffer, 100 }, @@ -139,7 +177,7 @@ static const struct { static const u16 sAcceptedSerialNos[] = { 0x0002, // Pokemon FR/LG/EM - 0x7f7d, + RFU_SERIAL_7F7D, 0xFFFF }; @@ -171,12 +209,12 @@ static const TaskFunc gUnknown_843ED88[] = { sub_80FACF0 }; -static void rfu_dbg_print_str(const void *string, u8 x, u8 y) +static void Debug_PrintString(const void *string, u8 x, u8 y) { // debug? } -static void rfu_dbg_print_num(u16 num, u8 x, u8 y, u8 ndigits) +static void Debug_PrintNum(u16 num, u8 x, u8 y, u8 ndigits) { } @@ -192,13 +230,13 @@ void ResetLinkRfuGFLayer(void) { Rfu.errorState = 0; } - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { - ResetSendDataManager(Rfu.cmd_8800_recvbuf + i); + ResetSendDataManager(&Rfu.recvBlock[i]); } - ResetSendDataManager(&Rfu.cmd_8800_sendbuf); - RFU_queue_20_70_reset(&Rfu.unk_124); - RFU_queue_40_14_reset(&Rfu.sendQueue); + ResetSendDataManager(&Rfu.sendBlock); + RfuRecvQueue_Reset(&Rfu.recvQueue); + RfuSendQueue_Reset(&Rfu.sendQueue); CpuFill16(0, gSendCmd, sizeof gSendCmd); CpuFill16(0, gRecvCmds, sizeof gRecvCmds); CpuFill16(0, gLinkPlayers, sizeof gLinkPlayers); @@ -208,7 +246,7 @@ void InitRFU(void) { IntrFunc serialIntr = gIntrTable[1]; IntrFunc timerIntr = gIntrTable[2]; - sub_80F86F4(); + InitRFUAPI(); rfu_REQ_stopMode(); rfu_waitREQComplete(); REG_IME = 0; @@ -217,11 +255,12 @@ void InitRFU(void) REG_IME = INTR_FLAG_VBLANK; } -void sub_80F86F4(void) +void InitRFUAPI(void) { if (!rfu_initializeAPI(gf_rfu_REQ_api, RFU_API_BUFF_SIZE_RAM, gIntrTable + 1, TRUE)) { gLinkType = 0; + // ClearSavedLinkPlayers(); // Em fix sub_80FB128(FALSE); ResetLinkRfuGFLayer(); rfu_setTimerInterrupt(3, gIntrTable + 2); @@ -230,7 +269,7 @@ void sub_80F86F4(void) static void Task_LinkLeaderSearchForChildren(u8 taskId) { - sub_80FA738(); + UpdateChildStatuses(); switch (Rfu.state) { case 0: @@ -248,13 +287,13 @@ static void Task_LinkLeaderSearchForChildren(u8 taskId) case 3: break; case 4: - rfu_LMAN_stopManager(0); + rfu_LMAN_stopManager(FALSE); Rfu.state = 5; break; case 5: break; case 18: - Rfu.unk_cdb = 0; + Rfu.unk_cdb = FALSE; rfu_LMAN_setMSCCallback(MSCCallback_SetUnkCDB); sub_80F8AA4(); sub_80F8AEC(); @@ -266,22 +305,24 @@ static void Task_LinkLeaderSearchForChildren(u8 taskId) } } -static u8 sub_80F886C(u8 idx) +static u8 CountTrailingZeroes(u8 acceptSlot) { - return gUnknown_843EC51[idx]; + return sNumTrailingZeroes[acceptSlot]; } -static void sub_80F887C(s32 r2, s32 r5) +static void ReassignPartnerIds(s32 before, s32 after) { u8 i; u8 r4 = 1; - s32 r1 = r2; + s32 beforeBak = before; s32 r6 = 0; - if (r5 == -1) + if (after == -1) { - for (i = 0; i < RFU_CHILD_MAX; r2 >>= 1, i++) + // First Time Init + // UB: linkPlayerIdx may be uninitialized + for (i = 0; i < RFU_CHILD_MAX; before >>= 1, i++) { - if (r2 & 1) + if (before & 1) { Rfu.linkPlayerIdx[i] = r4; r4++; @@ -290,13 +331,15 @@ static void sub_80F887C(s32 r2, s32 r5) } else { - for (i = 0; i < RFU_CHILD_MAX; r1 >>= 1, i++) + // Delete before flags + for (i = 0; i < RFU_CHILD_MAX; beforeBak >>= 1, i++) { - if (!(r1 & 1)) + if (!(beforeBak & 1)) { Rfu.linkPlayerIdx[i] = 0; } } + // Get highest retained index for (r4 = 4; r4 != 0; r4--) { for (i = 0; i < RFU_CHILD_MAX && Rfu.linkPlayerIdx[i] != r4; i++); @@ -305,9 +348,10 @@ static void sub_80F887C(s32 r2, s32 r5) r6 = r4; } } - for (r5 &= ~r2, i = 0; i < RFU_CHILD_MAX; r5 >>= 1, i++) + // Replace with new flags + for (after &= ~before, i = 0; i < RFU_CHILD_MAX; after >>= 1, i++) { - if (r5 & 1) + if (after & 1) { Rfu.linkPlayerIdx[i] = r6++; } @@ -337,13 +381,13 @@ static void Task_JoinGroupSearchForParent(u8 taskId) gTasks[taskId].data[1] = 10; break; case 11: - switch (sub_80FA788()) + switch (GetRfuRecvStatus()) { - case 5: + case RFU_STATUS_JOIN_GROUP_OK: Rfu.state = 12; break; - case 6: - case 9: + case RFU_STATUS_JOIN_GROUP_NO: + case RFU_STATUS_LEAVE_GROUP: rfu_LMAN_requestChangeAgbClockMaster(); Rfu.unk_ce4 = 2; DestroyTask(taskId); @@ -355,13 +399,13 @@ static void Task_JoinGroupSearchForParent(u8 taskId) u8 bmChildSlot = 1 << Rfu.child_slot; rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.child_slot); rfu_setRecvBuffer(TYPE_UNI, Rfu.child_slot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); - rfu_UNI_setSendData(bmChildSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)); + rfu_UNI_setSendData(bmChildSlot, Rfu.lastCmdBeforeCommInterrupt, sizeof(Rfu.lastCmdBeforeCommInterrupt)); gTasks[taskId].data[1] = 8; DestroyTask(taskId); - if (gUnknown_203AC08.unk_0f == 0) + if (sRfuDebug.unk_0f == 0) { - rfu_dbg_clear(); - gUnknown_203AC08.unk_0f++; + Debug_PrintEmpty(); + sRfuDebug.unk_0f++; } CreateTask(sub_80FA834, 5); break; @@ -377,7 +421,7 @@ static void sub_80F8AA4(void) { if (acceptSlot & 1) { - rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], sizeof(Rfu.unk_14[i])); + rfu_setRecvBuffer(TYPE_UNI, i, Rfu.main_UNI_recvBuffer[i], sizeof(Rfu.main_UNI_recvBuffer[i])); rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, i); } acceptSlot >>= 1; @@ -388,19 +432,19 @@ static void sub_80F8AEC(void) { u8 acceptSlot = lman.acceptSlot_flag; rfu_UNI_setSendData(acceptSlot, Rfu.recvCmds, sizeof(Rfu.recvCmds)); - Rfu.unk_cda = sub_80F886C(acceptSlot); + Rfu.unk_cda = CountTrailingZeroes(acceptSlot); Rfu.bm_PartnerFlags = acceptSlot; - sub_80F887C(acceptSlot, -1); + ReassignPartnerIds(acceptSlot, -1); Rfu.parent_child = MODE_PARENT; } static void Task_LinkRfu_UnionRoomListen(u8 taskId) { - if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetErrorStatus() == 4) + if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM) && RfuGetStatus() == 4) { rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_waitREQComplete(); - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); } switch (Rfu.state) { @@ -412,14 +456,14 @@ static void Task_LinkRfu_UnionRoomListen(u8 taskId) case 1: break; case 17: - rfu_LMAN_establishConnection(2, 0, 240, (u16*)sAcceptedSerialNos); + rfu_LMAN_establishConnection(MODE_P_C_SWITCH, 0, 240, (u16*)sAcceptedSerialNos); rfu_LMAN_setMSCCallback(MscCallback_Child); Rfu.state = 18; break; case 18: break; case 13: - if (rfu_UNI_setSendData(1 << Rfu.child_slot, Rfu.unk_4c, sizeof(Rfu.unk_4c)) == 0) + if (rfu_UNI_setSendData(1 << Rfu.child_slot, Rfu.lastCmdBeforeCommInterrupt, sizeof(Rfu.lastCmdBeforeCommInterrupt)) == 0) { Rfu.parent_child = MODE_CHILD; DestroyTask(taskId); @@ -440,7 +484,7 @@ static void Task_LinkRfu_UnionRoomListen(u8 taskId) case 15: break; case 16: - Rfu.unk_cdb = 0; + Rfu.unk_cdb = FALSE; rfu_LMAN_setMSCCallback(MSCCallback_SetUnkCDB); UpdateGameData_GroupLockedIn(1); sub_80F8AA4(); @@ -449,7 +493,7 @@ static void Task_LinkRfu_UnionRoomListen(u8 taskId) gTasks[taskId].data[1] = 8; Rfu.parent_child = MODE_PARENT; CreateTask(sub_80FA834, 5); - Rfu.unk_ce8 = TRUE; + Rfu.foundNewLeaderMaybe = TRUE; DestroyTask(taskId); break; } @@ -462,25 +506,25 @@ void LinkRfu_CreateConnectionAsParent(void) void LinkRfu_StopManagerBeforeEnteringChat(void) { - rfu_LMAN_stopManager(0); + rfu_LMAN_stopManager(FALSE); } static void MscCallback_Child(u16 unused) { s32 i; - for (i = 0; i < 14; i++) + for (i = 0; i < BACKUP_QUEUE_SLOT_LENGTH; i++) { - Rfu.unk_4c[i] = 0; + Rfu.lastCmdBeforeCommInterrupt[i] = 0; } rfu_REQ_recvData(); rfu_waitREQComplete(); if (gRfuSlotStatusUNI[Rfu.child_slot]->recv.newDataFlag) { - Rfu.unk_cd0++; - RFU_queue_20_70_recv(&Rfu.unk_124, Rfu.unk_c3f); - gUnknown_203AC08.unk_06++; - sub_80F906C(); + Rfu.sem_UNI_SendRecv++; + RfuRecvQueue_Enqueue(&Rfu.recvQueue, Rfu.unk_c3f); + sRfuDebug.unk_06++; + UpdateBackupQueue(); rfu_UNI_readySendData(Rfu.child_slot); rfu_UNI_clearRecvNewDataFlag(Rfu.child_slot); } @@ -489,7 +533,7 @@ static void MscCallback_Child(u16 unused) static void MSCCallback_SetUnkCDB(u16 unused) { - Rfu.unk_cdb = 1; + Rfu.unk_cdb = TRUE; } void LinkRfu_Shutdown(void) @@ -504,7 +548,7 @@ void LinkRfu_Shutdown(void) { if (FuncIsActiveTask(Task_LinkLeaderSearchForChildren) == TRUE) { - DestroyTask(Rfu.unk_67); + DestroyTask(Rfu.searchTaskId); ResetLinkRfuGFLayer(); } } @@ -512,7 +556,7 @@ void LinkRfu_Shutdown(void) { if (FuncIsActiveTask(Task_JoinGroupSearchForParent) == TRUE) { - DestroyTask(Rfu.unk_67); + DestroyTask(Rfu.searchTaskId); ResetLinkRfuGFLayer(); } } @@ -520,7 +564,7 @@ void LinkRfu_Shutdown(void) { if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) { - DestroyTask(Rfu.unk_67); + DestroyTask(Rfu.searchTaskId); ResetLinkRfuGFLayer(); } } @@ -537,10 +581,10 @@ static void CreateTask_LinkLeaderSearchForChildren(void) { if (QL_IS_PLAYBACK_STATE) return; - Rfu.unk_67 = CreateTask(Task_LinkLeaderSearchForChildren, 1); + Rfu.searchTaskId = CreateTask(Task_LinkLeaderSearchForChildren, 1); } -static bool8 RfuStateIs7AndPlayerIsChild(void) +static bool8 ContactedByParentAttemptingToReconnect(void) { if (Rfu.state == 7 && Rfu.parentId) { @@ -563,7 +607,7 @@ static void CreateTask_JoinGroupSearchForParent(void) { if (QL_IS_PLAYBACK_STATE) return; - Rfu.unk_67 = CreateTask(Task_JoinGroupSearchForParent, 1); + Rfu.searchTaskId = CreateTask(Task_JoinGroupSearchForParent, 1); } bool8 LmanAcceptSlotFlagIsNotZero(void) @@ -596,6 +640,7 @@ void sub_80F8FA0(void) Rfu.state = 14; } +UNUSED static void sub_80F8FAC(u8 a0) { u8 i; @@ -611,14 +656,14 @@ static void sub_80F8FAC(u8 a0) } } -static void sub_80F8FD4(void) +static void MoveRecvCmdsToRfuBuffer(void) { s32 i, j; - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { GF_RFU_MANAGER *ptr = &Rfu; - for (j = 0; j < 7; j++) + for (j = 0; j < CMD_LENGTH - 1; j++) { ptr->recvCmds[i][j][1] = gRecvCmds[i][j] >> 8; ptr->recvCmds[i][j][0] = gRecvCmds[i][j]; @@ -627,37 +672,37 @@ static void sub_80F8FD4(void) CpuFill16(0, gRecvCmds, sizeof gRecvCmds); } -static void sub_80F9038(void) +static void MoveSendCmdToFirstRecvCmd(void) { s32 i; - for (i = 0; i < 7; i++) + for (i = 0; i < CMD_LENGTH - 1; i++) { gRecvCmds[0][i] = gSendCmd[i]; } - for (i = 0; i < 7; i++) + for (i = 0; i < CMD_LENGTH - 1; i++) { gSendCmd[i] = 0; } } -static void sub_80F906C(void) +static void UpdateBackupQueue(void) { - if (Rfu.unk_c3c) + if (Rfu.linkRecovered) { - u8 r2 = RFU_queue_2_14_send(&Rfu.unk_c1c, Rfu.unk_4c); - if (Rfu.unk_c1c.count == 0) + bool8 backupEmpty = RfuBackupQueue_Dequeue(&Rfu.backupQueue, Rfu.lastCmdBeforeCommInterrupt); + if (Rfu.backupQueue.count == 0) { - Rfu.unk_c3c = 0; + Rfu.linkRecovered = FALSE; } - if (r2) + if (backupEmpty) { return; } } - if (Rfu.unk_c3c == 0) + if (!Rfu.linkRecovered) { - RFU_queue_40_14_send(&Rfu.sendQueue, Rfu.unk_4c); - RFU_queue_2_14_recv(&Rfu.unk_c1c, Rfu.unk_4c); + RfuSendQueue_Dequeue(&Rfu.sendQueue, Rfu.lastCmdBeforeCommInterrupt); + RfuBackupQueue_Enqueue(&Rfu.backupQueue, Rfu.lastCmdBeforeCommInterrupt); } } @@ -670,9 +715,9 @@ bool32 IsRfuRecvQueueEmpty(void) { return FALSE; } - for (i = 0; i < 5; i++) + for (i = 0; i < MAX_RFU_PLAYERS; i++) { - for (j = 0; j < 7; j++) + for (j = 0; j < CMD_LENGTH - 1; j++) { if (gRecvCmds[i][j] != 0) { @@ -693,7 +738,7 @@ static bool32 sub_80F911C(void) } else { - Rfu.unk_cdb = 0; + Rfu.unk_cdb = FALSE; if ((Rfu.bm_PartnerFlags & gRfuLinkStatus->connSlotFlag) == Rfu.bm_PartnerFlags && (Rfu.bm_PartnerFlags & gRfuLinkStatus->connSlotFlag)) { if (!Rfu.unk_cdc) @@ -704,7 +749,7 @@ static bool32 sub_80F911C(void) Rfu.bm_DisconnectSlot = 0; if (Rfu.unk_ce4 == 1) { - RfuSetErrorStatus(2, 0x8000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x8000); GetLinkmanErrorParams(0x8000); return FALSE; } @@ -715,7 +760,7 @@ static bool32 sub_80F911C(void) return FALSE; } } - sub_80F8FD4(); + MoveRecvCmdsToRfuBuffer(); rfu_UNI_readySendData(Rfu.unk_cda); rfu_LMAN_REQ_sendData(TRUE); } @@ -723,7 +768,7 @@ static bool32 sub_80F911C(void) { rfu_REQ_PARENT_resumeRetransmitAndChange(); } - Rfu.unk_0e = 1; + Rfu.unk_0e = TRUE; } } return FALSE; @@ -737,10 +782,10 @@ static bool32 sub_80F9204(void) u16 j; u8 retval; - if (Rfu.state >= 20 && Rfu.unk_0e == 1) + if (Rfu.state >= 20 && Rfu.unk_0e == TRUE) { rfu_waitREQComplete(); - while (Rfu.unk_cdb == 0) + while (!Rfu.unk_cdb) { if (Rfu.errorState != 0) { @@ -752,30 +797,30 @@ static bool32 sub_80F9204(void) if ((lman.parentAck_flag & Rfu.bm_PartnerFlags) == Rfu.bm_PartnerFlags) { Rfu.unk_cdc = 0; - gUnknown_203AC08.unk_06++; + sRfuDebug.unk_06++; flags = lman.acceptSlot_flag; for (i = 0; i < RFU_CHILD_MAX; i++) { if (flags & 1) { - if (Rfu.unk_14[i][1]) + if (Rfu.main_UNI_recvBuffer[i][1]) { - if (Rfu.unk_cee[i] != 0xFF && (Rfu.unk_14[i][0] >> 5) != ((Rfu.unk_cee[i] + 1) & 7)) + if (Rfu.unk_cee[i] != 0xFF && (Rfu.main_UNI_recvBuffer[i][0] >> 5) != ((Rfu.unk_cee[i] + 1) & 7)) { if (++Rfu.unk_cea[i] > 4) GetLinkmanErrorParams(0x8100); } else { - Rfu.unk_cee[i] = Rfu.unk_14[i][0] / 32; + Rfu.unk_cee[i] = Rfu.main_UNI_recvBuffer[i][0] / 32; Rfu.unk_cea[i] = 0; - Rfu.unk_14[i][0] &= 0x1f; + Rfu.main_UNI_recvBuffer[i][0] &= 0x1f; 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]; - Rfu.unk_14[i][(j << 1) + 1] = 0; - Rfu.unk_14[i][(j << 1) + 0] = 0; + gRecvCmds[r0][j] = (Rfu.main_UNI_recvBuffer[i][(j << 1) + 1] << 8) | Rfu.main_UNI_recvBuffer[i][(j << 1) + 0]; + Rfu.main_UNI_recvBuffer[i][(j << 1) + 1] = 0; + Rfu.main_UNI_recvBuffer[i][(j << 1) + 0] = 0; } } } @@ -783,58 +828,58 @@ static bool32 sub_80F9204(void) } flags >>= 1; } - sub_80F9038(); + MoveSendCmdToFirstRecvCmd(); RfuHandleReceiveCommand(0); CallRfuFunc(); - if (Rfu.unk_ce5 && !Rfu.unk_cd9) + if (Rfu.bmChatLeaderMaybe && !Rfu.linkClosing) { - gUnknown_203AC08.unk_0e = 0; + sRfuDebug.unk_0e = FALSE; 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) + if ((Rfu.bmChatLeaderMaybe >> i) & 1) { - rfu_setRecvBuffer(TYPE_UNI, i, Rfu.unk_14[i], sizeof(Rfu.unk_14[i])); + rfu_setRecvBuffer(TYPE_UNI, i, Rfu.main_UNI_recvBuffer[i], sizeof(Rfu.main_UNI_recvBuffer[i])); } } - sub_80F887C(Rfu.bm_PartnerFlags, Rfu.bm_PartnerFlags | Rfu.unk_ce5); - Rfu.unk_ce9 = Rfu.unk_ce5; - Rfu.bm_PartnerFlags |= Rfu.unk_ce5; - Rfu.unk_ce5 = 0; + ReassignPartnerIds(Rfu.bm_PartnerFlags, Rfu.bm_PartnerFlags | Rfu.bmChatLeaderMaybe); + Rfu.unk_ce9 = Rfu.bmChatLeaderMaybe; + Rfu.bm_PartnerFlags |= Rfu.bmChatLeaderMaybe; + Rfu.bmChatLeaderMaybe = 0; rfu_UNI_setSendData(Rfu.bm_PartnerFlags, Rfu.recvCmds, sizeof(Rfu.recvCmds)); - Rfu.unk_cda = sub_80F886C(Rfu.bm_PartnerFlags); + Rfu.unk_cda = CountTrailingZeroes(Rfu.bm_PartnerFlags); CreateTask(Task_ExchangeLinkPlayers, 0); } } else { Rfu.unk_cdc = 1; - Rfu.unk_0e = 0; + Rfu.unk_0e = FALSE; } - Rfu.unk_0e = 0; + Rfu.unk_0e = FALSE; } retval = Rfu.unk_cdc; return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE; } -static void sub_80F94BC(u16 *a0, u8 *a1) +static void RfuBufferSendCmd(u16 *sendCmd, u8 *rfuSendBuf) { s32 i; - if (a0[0]) + if (sendCmd[0]) { - a0[0] |= (Rfu.unk_102 << 5); + sendCmd[0] |= (Rfu.unk_102 << 5); Rfu.unk_102 = (Rfu.unk_102 + 1) & 7; for (i = 0; i < 7; i++) { - a1[2 * i + 1] = a0[i] >> 8; - a1[2 * i + 0] = a0[i]; + rfuSendBuf[2 * i + 1] = sendCmd[i] >> 8; + rfuSendBuf[2 * i + 0] = sendCmd[i]; } } else { for (i = 0; i < 14; i++) - a1[i] = 0; + rfuSendBuf[i] = 0; } } @@ -842,16 +887,16 @@ static bool32 RfuProcessEnqueuedRecvBlock(void) { u8 i; u8 j; - u8 sp00[MAX_RFU_PLAYERS * (2 * (CMD_LENGTH - 1))]; - u8 sp48[2 * (CMD_LENGTH - 1)]; - u8 switchval; + u8 recvBuf[MAX_RFU_PLAYERS * (2 * (CMD_LENGTH - 1))]; + u8 sendBuf[2 * (CMD_LENGTH - 1)]; + u8 status; - RFU_queue_20_70_send(&Rfu.unk_124, sp00); + RfuRecvQueue_Dequeue(&Rfu.recvQueue, recvBuf); for (i = 0; i < MAX_RFU_PLAYERS; i++) { for (j = 0; j < CMD_LENGTH - 1; j++) { - gRecvCmds[i][j] = (sp00[i * 14 + (j << 1) + 1] << 8) | sp00[i * 14 + (j << 1) + 0]; + gRecvCmds[i][j] = (recvBuf[i * 14 + (j << 1) + 1] << 8) | recvBuf[i * 14 + (j << 1) + 0]; } } RfuHandleReceiveCommand(0); @@ -859,26 +904,28 @@ static bool32 RfuProcessEnqueuedRecvBlock(void) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); rfu_waitREQComplete(); - switchval = RfuGetErrorStatus(); - if (switchval != 1 && switchval != 6 && switchval != 9) - RfuSetErrorStatus(2, 0x9000); + status = RfuGetStatus(); + if (status != RFU_STATUS_FATAL_ERROR + && status != RFU_STATUS_JOIN_GROUP_NO + && status != RFU_STATUS_LEAVE_GROUP) + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000); rfu_clearAllSlot(); gReceivedRemoteLinkPlayers = FALSE; Rfu.RfuFunc = NULL; if (Rfu.unk_ce4 == 1) { - RfuSetErrorStatus(2, 0x9000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x9000); GetLinkmanErrorParams(0x9000); } lman.state = lman.next_state = 0; Rfu.unk_ce4 = 0; } - if (Rfu.unk_cd0) + if (Rfu.sem_UNI_SendRecv) { - Rfu.unk_cd0--; + Rfu.sem_UNI_SendRecv--; CallRfuFunc(); - sub_80F94BC(gSendCmd, sp48); - RFU_queue_40_14_recv(&Rfu.sendQueue, sp48); + RfuBufferSendCmd(gSendCmd, sendBuf); + RfuSendQueue_Enqueue(&Rfu.sendQueue, sendBuf); for (i = 0; i < CMD_LENGTH - 1; i++) gSendCmd[i] = 0; } @@ -887,47 +934,47 @@ static bool32 RfuProcessEnqueuedRecvBlock(void) static void HandleSendFailure(u8 unused, u32 flags) { - s32 i, j; + s32 i, j, temp; - const u8 *r10 = Rfu.cmd_8800_sendbuf.payload; - for (i = 0; i < Rfu.cmd_8800_sendbuf.count; i++) + const u8 *payload = Rfu.sendBlock.payload; + for (i = 0; i < Rfu.sendBlock.count; i++) { if (!(flags & 1)) { - sResendBlock16[0] = RFUCMD_0x8900 | i; + sResendBlock16[0] = RFUCMD_SEND_BLOCK_STEP | i; for (j = 0; j < 7; j++) { - sResendBlock16[j + 1] = (r10[12 * i + (j << 1) + 1] << 8) | r10[12 * i + (j << 1) + 0]; + temp = j << 1; + sResendBlock16[j + 1] = (payload[12 * i + temp + 1] << 8) | payload[12 * i + temp + 0]; } for (j = 0; j < 7; j++) { - sResendBlock8[2 * j + 1] = sResendBlock16[j] >> 8; - sResendBlock8[2 * j + 0] = sResendBlock16[j]; - - j++;j--; // Needed to match; + temp = j << 1; + sResendBlock8[temp + 1] = sResendBlock16[j] >> 8; + sResendBlock8[temp + 0] = sResendBlock16[j]; } - RFU_queue_40_14_recv(&Rfu.sendQueue, sResendBlock8); - Rfu.cmd_8800_sendbuf.failedFlags |= (1 << i); + RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); + Rfu.sendBlock.failedFlags |= (1 << i); } flags >>= 1; } } -void Rfu_SetBlockReceivedFlag(u8 a0) +void Rfu_SetBlockReceivedFlag(u8 linkPlayerId) { - if (Rfu.parent_child == MODE_PARENT && a0) - Rfu.unk_61[a0] = 1; + if (Rfu.parent_child == MODE_PARENT && linkPlayerId != 0) + Rfu.numBlocksReceived[linkPlayerId] = 1; else - Rfu.unk_5c[a0] = 1; + Rfu.blockReceived[linkPlayerId] = TRUE; } -void Rfu_ResetBlockReceivedFlag(u8 a0) +void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId) { - Rfu.unk_5c[a0] = 0; - Rfu.cmd_8800_recvbuf[a0].receiving = 0; + Rfu.blockReceived[linkPlayerId] = FALSE; + Rfu.recvBlock[linkPlayerId].receiving = RFU_RECV_IDLE; } -static u8 sub_80F9770(const u8 *a0) +static u8 RfuChildSetReceivedPlayerOrder(const u8 *template) { u8 i; @@ -935,20 +982,20 @@ static u8 sub_80F9770(const u8 *a0) return FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) { - Rfu.linkPlayerIdx[i] = a0[i]; + Rfu.linkPlayerIdx[i] = template[i]; } - return a0[Rfu.child_slot]; + return template[Rfu.child_slot]; } static void RfuFunc_SendKeysToRfu(void) { - static u8 gUnknown_3001188; + static u8 heldKeyCount; if (gReceivedRemoteLinkPlayers && gHeldKeyCodeToSend != LINK_KEY_CODE_NULL && gLinkTransferringData != TRUE) { - gUnknown_3001188++; - gHeldKeyCodeToSend |= (gUnknown_3001188 << 8); + heldKeyCount++; + gHeldKeyCodeToSend |= (heldKeyCount << 8); RfuPrepareSendBuffer(RFUCMD_SEND_HELD_KEYS); } } @@ -969,7 +1016,7 @@ void StartSendingKeysToRfu(void) Rfu.RfuFunc = RfuFunc_SendKeysToRfu; } -void Rfu_set_zero(void) +void ClearLinkRfuCallback(void) { Rfu.RfuFunc = NULL; } @@ -983,38 +1030,38 @@ static void RfuHandleReceiveCommand(u8 unused) { switch (gRecvCmds[i][0] & 0xff00) { - case RFUCMD_0x7800: + case RFUCMD_PLAYERS_LIST_2: if (Rfu.parent_child == MODE_CHILD && gReceivedRemoteLinkPlayers) return; // fallthrough - case RFUCMD_0x7700: + case RFUCMD_PLAYERS_LIST: if (gRfuLinkStatus->parentChild == MODE_CHILD) { Rfu.playerCount = gRecvCmds[i][1]; - Rfu.unk_cce = sub_80F9770((u8 *)(gRecvCmds[i] + 2)); + Rfu.multiplayerId = RfuChildSetReceivedPlayerOrder((u8 *)(gRecvCmds[i] + 2)); } break; - case RFUCMD_0x8800: - if (Rfu.cmd_8800_recvbuf[i].receiving == 0) + case RFUCMD_SEND_BLOCK_INIT: + if (Rfu.recvBlock[i].receiving == RFU_RECV_IDLE) { - Rfu.cmd_8800_recvbuf[i].next = 0; - Rfu.cmd_8800_recvbuf[i].count = gRecvCmds[i][1]; - Rfu.cmd_8800_recvbuf[i].owner = gRecvCmds[i][2]; - Rfu.cmd_8800_recvbuf[i].receivedFlags = 0; - Rfu.cmd_8800_recvbuf[i].receiving = 1; - Rfu.unk_5c[i] = 0; + Rfu.recvBlock[i].next = 0; + Rfu.recvBlock[i].count = gRecvCmds[i][1]; + Rfu.recvBlock[i].owner = gRecvCmds[i][2]; + Rfu.recvBlock[i].receivedFlags = 0; + Rfu.recvBlock[i].receiving = RFU_RECV_RECEIVING; + Rfu.blockReceived[i] = FALSE; } break; - case RFUCMD_0x8900: - if (Rfu.cmd_8800_recvbuf[i].receiving == 1) + case RFUCMD_SEND_BLOCK_STEP: + if (Rfu.recvBlock[i].receiving == RFU_RECV_RECEIVING) { - Rfu.cmd_8800_recvbuf[i].next = gRecvCmds[i][0] & 0xff; - Rfu.cmd_8800_recvbuf[i].receivedFlags |= (1 << Rfu.cmd_8800_recvbuf[i].next); + Rfu.recvBlock[i].next = gRecvCmds[i][0] & 0xff; + Rfu.recvBlock[i].receivedFlags |= (1 << Rfu.recvBlock[i].next); for (j = 0; j < 6; j++) - gBlockRecvBuffer[i][Rfu.cmd_8800_recvbuf[i].next * 6 + j] = gRecvCmds[i][j + 1]; - if (Rfu.cmd_8800_recvbuf[i].receivedFlags == sAllBlocksReceived[Rfu.cmd_8800_recvbuf[i].count]) + gBlockRecvBuffer[i][Rfu.recvBlock[i].next * 6 + j] = gRecvCmds[i][j + 1]; + if (Rfu.recvBlock[i].receivedFlags == sAllBlocksReceived[Rfu.recvBlock[i].count]) { - Rfu.cmd_8800_recvbuf[i].receiving = 2; + Rfu.recvBlock[i].receiving = RFU_RECV_FINISHED; Rfu_SetBlockReceivedFlag(i); if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && gReceivedRemoteLinkPlayers && Rfu.parent_child == MODE_CHILD) ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer); @@ -1022,16 +1069,16 @@ static void RfuHandleReceiveCommand(u8 unused) } break; case RFUCMD_SEND_BLOCK_REQ: - Rfu_InitBlockSend(gUnknown_843EC64[gRecvCmds[i][1]].buffer, (u16)gUnknown_843EC64[gRecvCmds[i][1]].size); + Rfu_InitBlockSend(sBlockRequests[gRecvCmds[i][1]].address, (u16)sBlockRequests[gRecvCmds[i][1]].size); break; case RFUCMD_READY_CLOSE_LINK: - Rfu.cmd5f00Ack[i] = 1; + Rfu.readyCloseLink[i] = TRUE; break; case RFUCMD_READY_EXIT_STANDBY: - if (Rfu.cmd_6600_count == gRecvCmds[i][1]) - Rfu.cmd_6600_recvd[i] = 1; + if (Rfu.resendExitStandbyCount == gRecvCmds[i][1]) + Rfu.readyExitStandby[i] = TRUE; break; - case RFUCMD_0xED00: + case RFUCMD_PARENT_DISCONNECT: if (Rfu.parent_child == MODE_CHILD) { if (gReceivedRemoteLinkPlayers) @@ -1043,61 +1090,61 @@ static void RfuHandleReceiveCommand(u8 unused) Rfu.unk_ce4 = gRecvCmds[i][2]; } Rfu.playerCount = gRecvCmds[i][3]; - sub_80FA9D0(gRecvCmds[i][1]); + ClearSelectedLinkPlayerIds(gRecvCmds[i][1]); } } else { - RfuPrepareSendBuffer(RFUCMD_0xEE00); + RfuPrepareSendBuffer(RFUCMD_CHILD_DISCONNECT); gSendCmd[1] = gRecvCmds[i][1]; gSendCmd[2] = gRecvCmds[i][2]; gSendCmd[3] = gRecvCmds[i][3]; } break; - case RFUCMD_0xEE00: + case RFUCMD_CHILD_DISCONNECT: if (Rfu.parent_child == MODE_PARENT) { Rfu.bm_DisconnectSlot |= gRecvCmds[i][1]; Rfu.unk_ce4 = gRecvCmds[i][2]; - sub_80FA9D0(gRecvCmds[i][1]); + ClearSelectedLinkPlayerIds(gRecvCmds[i][1]); } break; case RFUCMD_SEND_HELD_KEYS: gLinkPartnersHeldKeys[i] = gRecvCmds[i][1]; break; } - if (Rfu.parent_child == MODE_PARENT && Rfu.unk_61[i]) + if (Rfu.parent_child == MODE_PARENT && Rfu.numBlocksReceived[i]) { - if (Rfu.unk_61[i] == 4) + if (Rfu.numBlocksReceived[i] == 4) { - Rfu.unk_5c[i] = 1; - Rfu.unk_61[i] = 0; + Rfu.blockReceived[i] = TRUE; + Rfu.numBlocksReceived[i] = 0; } else - Rfu.unk_61[i]++; + Rfu.numBlocksReceived[i]++; } } } -static bool8 Cmd8000recvIsFinished(void) +static bool8 AreNoPlayersReceiving(void) { s32 i; for (i = 0; i < 5; i++) { - if (Rfu.cmd_8800_recvbuf[i].receiving) + if (Rfu.recvBlock[i].receiving != RFU_RECV_IDLE) return FALSE; } return TRUE; } -static bool8 sub_80F9C78(void) +static bool8 AreAllPlayersFinishedReceiving(void) { s32 i; for (i = 0; i < Rfu.playerCount; i++) { - if (Rfu.cmd_8800_recvbuf[i].receiving != 2 || Rfu.unk_5c[i] != 1) + if (Rfu.recvBlock[i].receiving != RFU_RECV_FINISHED || Rfu.blockReceived[i] != TRUE) return FALSE; } return TRUE; @@ -1111,7 +1158,7 @@ static void ResetSendDataManager(struct RfuBlockSend *data) data->receivedFlags = 0; data->sending = 0; data->owner = 0; - data->receiving = 0; + data->receiving = RFU_RECV_IDLE; } u8 Rfu_GetBlockReceivedStatus(void) @@ -1121,7 +1168,7 @@ u8 Rfu_GetBlockReceivedStatus(void) for (i = 0; i < 5; i++) { - if (Rfu.cmd_8800_recvbuf[i].receiving == 2 && Rfu.unk_5c[i] == 1) + if (Rfu.recvBlock[i].receiving == RFU_RECV_FINISHED && Rfu.blockReceived[i] == TRUE) { flags |= (1 << i); } @@ -1138,18 +1185,18 @@ static void RfuPrepareSendBuffer(u16 command) gSendCmd[0] = command; switch (command) { - case RFUCMD_0x8800: - gSendCmd[1] = Rfu.cmd_8800_sendbuf.count; - gSendCmd[2] = Rfu.cmd_8800_sendbuf.owner + 0x80; + case RFUCMD_SEND_BLOCK_INIT: + gSendCmd[1] = Rfu.sendBlock.count; + gSendCmd[2] = Rfu.sendBlock.owner + 0x80; break; case RFUCMD_SEND_BLOCK_REQ: - if (Cmd8000recvIsFinished()) + if (AreNoPlayersReceiving()) gSendCmd[1] = Rfu.cmdA100_blockRequestType; break; - case RFUCMD_0x7700: - case RFUCMD_0x7800: + case RFUCMD_PLAYERS_LIST: + case RFUCMD_PLAYERS_LIST_2: tmp = Rfu.bm_PartnerFlags ^ Rfu.bm_DisconnectSlot; - Rfu.playerCount = gUnknown_843EC41[tmp] + 1; + Rfu.playerCount = sNumSetBits[tmp] + 1; gSendCmd[1] = Rfu.playerCount; buff = (u8 *)(gSendCmd + 2); for (i = 0; i < RFU_CHILD_MAX; i++) @@ -1157,111 +1204,111 @@ static void RfuPrepareSendBuffer(u16 command) break; case RFUCMD_READY_EXIT_STANDBY: case RFUCMD_READY_CLOSE_LINK: - gSendCmd[1] = Rfu.cmd_6600_count; + gSendCmd[1] = Rfu.resendExitStandbyCount; break; case RFUCMD_SEND_PACKET: for (i = 0; i < 6; i++) - gSendCmd[1 + i] = Rfu.unk_f2[i]; + gSendCmd[1 + i] = Rfu.packet[i]; break; case RFUCMD_SEND_HELD_KEYS: gSendCmd[1] = gHeldKeyCodeToSend; break; - case RFUCMD_0xEE00: + case RFUCMD_CHILD_DISCONNECT: break; - case RFUCMD_0xED00: + case RFUCMD_PARENT_DISCONNECT: break; } } void Rfu_SendPacket(void * data) { - if (gSendCmd[0] == 0 && !RfuIsErrorStatus1or2()) + if (IsSendCmdComplete() && !RfuHasErrored()) { - memcpy(Rfu.unk_f2, data, sizeof(Rfu.unk_f2)); + memcpy(Rfu.packet, data, sizeof(Rfu.packet)); RfuPrepareSendBuffer(RFUCMD_SEND_PACKET); } } bool32 Rfu_InitBlockSend(const u8 *src, size_t size) { - bool8 r4; + bool8 sizeHasModulo; AGB_ASSERT_EX(size<=252, ABSPATH("rfu.c"), 1793); if (Rfu.RfuFunc != NULL) return FALSE; if (gSendCmd[0] != 0) return FALSE; - if (Rfu.cmd_8800_sendbuf.sending != 0) + if (Rfu.sendBlock.sending != 0) { - gUnknown_203AC08.unk_83++; + sRfuDebug.unk_83++; return FALSE; } - r4 = (size % 12) != 0; - Rfu.cmd_8800_sendbuf.owner = GetMultiplayerId(); - Rfu.cmd_8800_sendbuf.sending = 1; - Rfu.cmd_8800_sendbuf.count = (size / 12) + r4; - Rfu.cmd_8800_sendbuf.next = 0; + sizeHasModulo = (size % 12) != 0; + Rfu.sendBlock.owner = GetMultiplayerId(); + Rfu.sendBlock.sending = 1; + Rfu.sendBlock.count = (size / 12) + sizeHasModulo; + Rfu.sendBlock.next = 0; if (size > 0x100) // should never be reached - Rfu.cmd_8800_sendbuf.payload = src; + Rfu.sendBlock.payload = src; else { if (src != gBlockSendBuffer) memcpy(gBlockSendBuffer, src, size); - Rfu.cmd_8800_sendbuf.payload = gBlockSendBuffer; + Rfu.sendBlock.payload = gBlockSendBuffer; } - RfuPrepareSendBuffer(RFUCMD_0x8800); - Rfu.RfuFunc = RfuFunc_HandleBlockSend; - Rfu.unk_5b = 0; + RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_INIT); + Rfu.RfuFunc = HandleBlockSend; + Rfu.sendBlockInitDelay = 0; return TRUE; } -static void RfuFunc_HandleBlockSend(void) +static void HandleBlockSend(void) { - if (gSendCmd[0] == 0) + if (IsSendCmdComplete()) { - RfuPrepareSendBuffer(RFUCMD_0x8800); + RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_INIT); if (Rfu.parent_child == MODE_PARENT) { - if (++Rfu.unk_5b > 2) - Rfu.RfuFunc = RfuFunc_SendNextBlock; + if (++Rfu.sendBlockInitDelay > 2) + Rfu.RfuFunc = SendNextBlock; } else { - if ((gRecvCmds[GetMultiplayerId()][0] & 0xff00) == RFUCMD_0x8800) - Rfu.RfuFunc = RfuFunc_SendNextBlock; + if ((gRecvCmds[GetMultiplayerId()][0] & 0xff00) == RFUCMD_SEND_BLOCK_INIT) + Rfu.RfuFunc = SendNextBlock; } } } -static void RfuFunc_SendNextBlock(void) +static void SendNextBlock(void) { s32 i; - const u8 *src = Rfu.cmd_8800_sendbuf.payload; - gSendCmd[0] = RFUCMD_0x8900 | Rfu.cmd_8800_sendbuf.next; + const u8 *src = Rfu.sendBlock.payload; + gSendCmd[0] = RFUCMD_SEND_BLOCK_STEP | Rfu.sendBlock.next; for (i = 0; i < 7; i++) - gSendCmd[i + 1] = (src[(i << 1) + Rfu.cmd_8800_sendbuf.next * 12 + 1] << 8) | src[(i << 1) + Rfu.cmd_8800_sendbuf.next * 12 + 0]; - Rfu.cmd_8800_sendbuf.next++; - if (Rfu.cmd_8800_sendbuf.count <= Rfu.cmd_8800_sendbuf.next) + gSendCmd[i + 1] = (src[(i << 1) + Rfu.sendBlock.next * 12 + 1] << 8) | src[(i << 1) + Rfu.sendBlock.next * 12 + 0]; + Rfu.sendBlock.next++; + if (Rfu.sendBlock.count <= Rfu.sendBlock.next) { - Rfu.cmd_8800_sendbuf.sending = 0; - Rfu.RfuFunc = RfuFunc_SendLastBlock; + Rfu.sendBlock.sending = 0; + Rfu.RfuFunc = SendLastBlock; } } -static void RfuFunc_SendLastBlock(void) +static void SendLastBlock(void) { - const u8 *src = Rfu.cmd_8800_sendbuf.payload; + const u8 *src = Rfu.sendBlock.payload; u8 mpId = GetMultiplayerId(); s32 i; if (Rfu.parent_child == MODE_CHILD) { - gSendCmd[0] = RFUCMD_0x8900 | (Rfu.cmd_8800_sendbuf.count - 1); + gSendCmd[0] = RFUCMD_SEND_BLOCK_STEP | (Rfu.sendBlock.count - 1); for (i = 0; i < 7; i++) - gSendCmd[i + 1] = (src[(i << 1) + (Rfu.cmd_8800_sendbuf.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.cmd_8800_sendbuf.count - 1) * 12 + 0]; - if ((u8)gRecvCmds[mpId][0] == Rfu.cmd_8800_sendbuf.count - 1) + gSendCmd[i + 1] = (src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.sendBlock.count - 1) * 12 + 0]; + if ((u8)gRecvCmds[mpId][0] == Rfu.sendBlock.count - 1) { - if (Rfu.cmd_8800_recvbuf[mpId].receivedFlags != sAllBlocksReceived[Rfu.cmd_8800_recvbuf[mpId].count]) + if (Rfu.recvBlock[mpId].receivedFlags != sAllBlocksReceived[Rfu.recvBlock[mpId].count]) { - HandleSendFailure(mpId, Rfu.cmd_8800_recvbuf[mpId].receivedFlags); - gUnknown_203AC08.unk_64++; + HandleSendFailure(mpId, Rfu.recvBlock[mpId].receivedFlags); + sRfuDebug.unk_64++; } else Rfu.RfuFunc = NULL; @@ -1271,14 +1318,14 @@ static void RfuFunc_SendLastBlock(void) Rfu.RfuFunc = NULL; } -bool8 LinkRfu_PrepareCmd0xA100(u8 blockRequestType) +bool8 Rfu_SendBlockRequest(u8 blockRequestType) { Rfu.cmdA100_blockRequestType = blockRequestType; RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_REQ); return TRUE; } -static void RfuFunc_End5F00_PowerDownRfu(void) +static void OnDisconnect_PowerDownRfu(void) { rfu_clearAllSlot(); rfu_LMAN_powerDownRFU(); @@ -1287,14 +1334,14 @@ static void RfuFunc_End5F00_PowerDownRfu(void) Rfu.RfuFunc = NULL; } -static void RfuFunc_End5F00_ParentDisconnect(void) +static void DisconnectRfu(void) { rfu_REQ_disconnect(gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag); rfu_waitREQComplete(); - RfuFunc_End5F00_PowerDownRfu(); + OnDisconnect_PowerDownRfu(); } -static void RfuFunc_End5F00(void) +static void TryDisconnectRfu(void) { if (Rfu.parent_child == MODE_CHILD) { @@ -1302,7 +1349,7 @@ static void RfuFunc_End5F00(void) Rfu.unk_ce4 = 2; } else - Rfu.RfuFunc = RfuFunc_End5F00_ParentDisconnect; + Rfu.RfuFunc = DisconnectRfu; } void LinkRfu_FatalError(void) @@ -1312,7 +1359,8 @@ void LinkRfu_FatalError(void) Rfu.bm_DisconnectSlot = gRfuLinkStatus->connSlotFlag | gRfuLinkStatus->linkLossSlotFlag; } -static void RfuFunc_WaitAck5F00(void) +// RFU equivalent of LinkCB_WaitCloseLink +static void WaitAllReadyToCloseLink(void) { s32 i; u8 playerCount = Rfu.playerCount; @@ -1320,7 +1368,7 @@ static void RfuFunc_WaitAck5F00(void) for (i = 0; i < MAX_RFU_PLAYERS; i++) { - if (Rfu.cmd5f00Ack[i]) + if (Rfu.readyCloseLink[i]) count++; } if (count == playerCount) @@ -1329,87 +1377,88 @@ static void RfuFunc_WaitAck5F00(void) if (Rfu.parent_child == MODE_CHILD) { Rfu.errorState = 3; - RfuFunc_End5F00(); + TryDisconnectRfu(); } else - Rfu.RfuFunc = RfuFunc_End5F00; + Rfu.RfuFunc = TryDisconnectRfu; } } -static void RfuFunc_BuildCommand5F00(void) +static void SendReadyCloseLink(void) { - if (gSendCmd[0] == 0 && !Rfu.unk_ce8) + if (IsSendCmdComplete() && !Rfu.foundNewLeaderMaybe) { RfuPrepareSendBuffer(RFUCMD_READY_CLOSE_LINK); - Rfu.RfuFunc = RfuFunc_WaitAck5F00; + Rfu.RfuFunc = WaitAllReadyToCloseLink; } } -static void Task_WaitRfuFuncAndSetBuildCmd5F00(u8 taskId) +static void Task_TryReadyCloseLink(u8 taskId) { if (Rfu.RfuFunc == NULL) { - Rfu.unk_cd9 = 1; - Rfu.RfuFunc = RfuFunc_BuildCommand5F00; + Rfu.linkClosing = TRUE; + Rfu.RfuFunc = SendReadyCloseLink; DestroyTask(taskId); } } -void Rfu_BeginBuildAndSendCommand5F(void) +void Rfu_SetCloseLinkCallback(void) { - if (!FuncIsActiveTask(Task_WaitRfuFuncAndSetBuildCmd5F00)) - CreateTask(Task_WaitRfuFuncAndSetBuildCmd5F00, 5); + if (!FuncIsActiveTask(Task_TryReadyCloseLink)) + CreateTask(Task_TryReadyCloseLink, 5); } -static void RfuFunc_Send6600_3(void) +static void SendReadyExitStandbyUntilAllReady(void) { u8 playerCount; u8 i; if (GetMultiplayerId() != 0) // child { - if (Rfu.unk_124.count == 0 && Rfu.cmd_6600_timer > 60) + if (Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.cmd_6600_timer = 0; + Rfu.resendExitStandbyTimer = 0; } } playerCount = GetLinkPlayerCount(); for (i = 0; i < playerCount; i++) { - if (Rfu.cmd_6600_recvd[i] == 0) + if (Rfu.readyExitStandby[i] == 0) break; } if (i == playerCount) { for (i = 0; i < MAX_RFU_PLAYERS; i++) - Rfu.cmd_6600_recvd[i] = 0; - Rfu.cmd_6600_count++; + Rfu.readyExitStandby[i] = 0; + Rfu.resendExitStandbyCount++; Rfu.RfuFunc = NULL; } - Rfu.cmd_6600_timer++; + Rfu.resendExitStandbyTimer++; } -static void RfuFunc_Send6600_2(void) +static void LinkLeaderReadyToExitStandby(void) { - if (Rfu.unk_124.count == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && IsSendCmdComplete()) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.RfuFunc = RfuFunc_Send6600_3; + Rfu.RfuFunc = SendReadyExitStandbyUntilAllReady; } } -static void RfuFunc_Send6600_1(void) +// RFU equivalent of LinkCB_Standby and LinkCB_StandbyForAll +static void Rfu_LinkStandby(void) { u8 i; u8 playerCount; if (GetMultiplayerId() != 0) // child { - if (Rfu.unk_124.count == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && IsSendCmdComplete()) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.RfuFunc = RfuFunc_Send6600_3; + Rfu.RfuFunc = SendReadyExitStandbyUntilAllReady; } } else // parent @@ -1417,15 +1466,15 @@ static void RfuFunc_Send6600_1(void) playerCount = GetLinkPlayerCount(); for (i = 1; i < playerCount; i++) { - if (Rfu.cmd_6600_recvd[i] == 0) + if (Rfu.readyExitStandby[i] == 0) break; } if (i == playerCount) { - if (Rfu.unk_124.count == 0 && gSendCmd[0] == 0) + if (Rfu.recvQueue.count == 0 && IsSendCmdComplete()) { RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.RfuFunc = RfuFunc_Send6600_2; + Rfu.RfuFunc = LinkLeaderReadyToExitStandby; } } } @@ -1435,12 +1484,12 @@ void Rfu_SetLinkStandbyCallback(void) { if (Rfu.RfuFunc == NULL) { - Rfu.RfuFunc = RfuFunc_Send6600_1; - Rfu.cmd_6600_timer = 0; + Rfu.RfuFunc = Rfu_LinkStandby; + Rfu.resendExitStandbyTimer = 0; } } -bool32 RfuSerialNumberIsValid(u32 serialNo) +bool32 IsRfuSerialNumberValid(u32 serialNo) { s32 i; for (i = 0; sAcceptedSerialNos[i] != serialNo; i++) @@ -1451,25 +1500,25 @@ bool32 RfuSerialNumberIsValid(u32 serialNo) return TRUE; } -u8 ToggleLMANlinkRecovery(bool32 a0) +u8 ToggleLMANlinkRecovery(bool32 enable) { - if (!a0) - return rfu_LMAN_setLinkRecovery(0, 0); - rfu_LMAN_setLinkRecovery(1, 600); + if (!enable) + return rfu_LMAN_setLinkRecovery(FALSE, 0); + rfu_LMAN_setLinkRecovery(TRUE, 600); return 0; } -void sub_80FA4A8(void) +void Rfu_UnionRoomChat_StopLinkManager(void) { - Rfu.unk_cd9 = 1; - rfu_LMAN_stopManager(0); + Rfu.linkClosing = TRUE; + rfu_LMAN_stopManager(FALSE); } u8 LinkRfu_GetMultiplayerId(void) { if (Rfu.parent_child == MODE_PARENT) return 0; - return Rfu.unk_cce; + return Rfu.multiplayerId; } u8 GetRfuPlayerCount(void) @@ -1488,22 +1537,23 @@ static void CallRfuFunc(void) Rfu.RfuFunc(); } -static bool8 sub_80FA528(void) +static bool8 CheckForLeavingGroupMembers(void) { s32 i; bool8 retval = FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.unk_cd1[i] < 5 || Rfu.unk_cd1[i] > 6) + if (Rfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK + || Rfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO) { 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) + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) { - Rfu.unk_cd1[i] = 9; - Rfu.unk_cd5[i] = 10; + Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; + Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; rfu_clearSlot(TYPE_NI_RECV, i); - rfu_NI_setSendData(1 << i, 8, Rfu.unk_cd1 + i, 1); + rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); retval = TRUE; } @@ -1523,10 +1573,10 @@ bool32 sub_80FA5D4(void) s32 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.unk_cd5[i] == 11) + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_11) { flags |= (1 << i); - Rfu.unk_cd5[i] = 0; + Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK; } } if (flags) @@ -1536,18 +1586,18 @@ bool32 sub_80FA5D4(void) } for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.unk_cd5[i] == 10 || Rfu.unk_cd5[i] == 11) + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10 || Rfu.partnerRecvStatuses[i] == RFU_STATUS_11) return TRUE; } return FALSE; } -bool32 TrainerIdAndNameStillInPartnersList(u16 trainerId, const u8 *trainerName) +bool32 CheckTrainerHasLeftByIdAndName(u16 trainerId, const u8 *trainerName) { u8 r1 = GetPartnerIndexByNameAndTrainerID(trainerName, trainerId); if (r1 == 0xFF) return TRUE; - if (Rfu.unk_cd1[r1] == 9) + if (Rfu.partnerSendStatuses[r1] == RFU_STATUS_LEAVE_GROUP) return TRUE; return FALSE; } @@ -1555,16 +1605,16 @@ bool32 TrainerIdAndNameStillInPartnersList(u16 trainerId, const u8 *trainerName) void SendByteToPartnerByIdAndName(u8 value, u16 trainerId, const u8 *trainerName) { u8 slotNo = GetPartnerIndexByNameAndTrainerID(trainerName, trainerId); - Rfu.unk_cd1[slotNo] = value; + Rfu.partnerSendStatuses[slotNo] = value; rfu_clearSlot(TYPE_NI_SEND, slotNo); - rfu_NI_setSendData(1 << slotNo, 8, Rfu.unk_cd1 + slotNo, 1); + rfu_NI_setSendData(1 << slotNo, 8, Rfu.partnerSendStatuses + slotNo, 1); } -void LinkRfuNIsend8(void) +void SendLeaveGroupNotice(void) { - Rfu.unk_c85 = 8; + Rfu.sendStatus = RFU_STATUS_LEAVE_GROUP_NOTICE; rfu_clearSlot(TYPE_NI_SEND, Rfu.child_slot); - rfu_NI_setSendData(1 << Rfu.child_slot, 8, &Rfu.unk_c85, 1); + rfu_NI_setSendData(1 << Rfu.child_slot, 8, &Rfu.sendStatus, 1); } u32 WaitSendByteToPartnerByIdAndName(u16 trainerId, const u8 *trainerName) @@ -1577,26 +1627,26 @@ u32 WaitSendByteToPartnerByIdAndName(u16 trainerId, const u8 *trainerName) return 0; } -static void sub_80FA738(void) +static void UpdateChildStatuses(void) { s32 i; - sub_80FA528(); + CheckForLeavingGroupMembers(); for (i = 0; i < RFU_CHILD_MAX; i++) { 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; + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10) + Rfu.partnerRecvStatuses[i] = RFU_STATUS_11; rfu_clearSlot(TYPE_NI_SEND, i); } } } -static s32 sub_80FA788(void) +static s32 GetRfuRecvStatus(void) { - s32 retval = 0; - if (Rfu.unk_c85 == 8) + s32 retval = RFU_STATUS_OK; + if (Rfu.sendStatus == RFU_STATUS_LEAVE_GROUP_NOTICE) { if (gRfuSlotStatusNI[Rfu.child_slot]->send.state == SLOT_STATE_SEND_SUCCESS || gRfuSlotStatusNI[Rfu.child_slot]->send.state == SLOT_STATE_SEND_FAILED) rfu_clearSlot(TYPE_NI_SEND, Rfu.child_slot); @@ -1604,13 +1654,13 @@ static s32 sub_80FA788(void) if (gRfuSlotStatusNI[Rfu.child_slot]->recv.state == SLOT_STATE_RECV_SUCCESS || gRfuSlotStatusNI[Rfu.child_slot]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { rfu_clearSlot(TYPE_NI_RECV, Rfu.child_slot); - RfuSetErrorStatus(Rfu.unk_c86, 0); - retval = Rfu.unk_c86; + RfuSetStatus(Rfu.recvStatus, 0); + retval = Rfu.recvStatus; } else if (gRfuSlotStatusNI[Rfu.child_slot]->recv.state == SLOT_STATE_RECV_FAILED) { rfu_clearSlot(TYPE_NI_RECV, Rfu.child_slot); - retval = 6; + retval = RFU_STATUS_JOIN_GROUP_NO; } return retval; } @@ -1619,18 +1669,18 @@ static void sub_80FA834(u8 taskId) { s32 i; - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) + if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR) { - Rfu.unk_ce8 = FALSE; + Rfu.foundNewLeaderMaybe = FALSE; DestroyTask(taskId); } switch (gTasks[taskId].data[0]) { case 0: - if (Cmd8000recvIsFinished()) + if (AreNoPlayersReceiving()) { ResetBlockReceivedFlags(); - PrepareLocalLinkPlayerBlock(); + LocalLinkPlayerToBlock(); gTasks[taskId].data[0]++; } break; @@ -1638,16 +1688,16 @@ static void sub_80FA834(u8 taskId) if (Rfu.parent_child == MODE_PARENT) { if (gReceivedRemoteLinkPlayers) - RfuPrepareSendBuffer(RFUCMD_0x7800); + RfuPrepareSendBuffer(RFUCMD_PLAYERS_LIST_2); else - RfuPrepareSendBuffer(RFUCMD_0x7700); + RfuPrepareSendBuffer(RFUCMD_PLAYERS_LIST); gTasks[taskId].data[0] = 101; } else gTasks[taskId].data[0] = 2; break; case 101: - if (gSendCmd[0] == 0) + if (IsSendCmdComplete()) gTasks[taskId].data[0] = 2; break; case 2: @@ -1657,7 +1707,7 @@ static void sub_80FA834(u8 taskId) case 3: if (Rfu.parent_child == MODE_PARENT) { - if (Cmd8000recvIsFinished()) + if (AreNoPlayersReceiving()) { Rfu.cmdA100_blockRequestType = 0; RfuPrepareSendBuffer(RFUCMD_SEND_BLOCK_REQ); @@ -1668,7 +1718,7 @@ static void sub_80FA834(u8 taskId) gTasks[taskId].data[0]++; break; case 4: - if (sub_80F9C78()) + if (AreAllPlayersFinishedReceiving()) gTasks[taskId].data[0]++; break; case 5: @@ -1682,7 +1732,7 @@ static void sub_80FA834(u8 taskId) case 6: DestroyTask(taskId); gReceivedRemoteLinkPlayers = TRUE; - Rfu.unk_ce8 = FALSE; + Rfu.foundNewLeaderMaybe = FALSE; rfu_LMAN_setLinkRecovery(1, 600); if (Rfu.unionRoomChatters) { @@ -1690,7 +1740,7 @@ static void sub_80FA834(u8 taskId) { if ((Rfu.unionRoomChatters >> i) & 1) { - Rfu.unk_ce5 = 1 << i; + Rfu.bmChatLeaderMaybe = 1 << i; Rfu.unionRoomChatters ^= (1 << i); } } @@ -1699,13 +1749,13 @@ static void sub_80FA834(u8 taskId) } } -static void sub_80FA9D0(u16 a0) +static void ClearSelectedLinkPlayerIds(u16 disconnectMask) { s32 i; for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((a0 >> i) & 1) + if ((disconnectMask >> i) & 1) Rfu.linkPlayerIdx[i] = 0; } } @@ -1739,23 +1789,23 @@ static void Task_ExchangeLinkPlayers(u8 taskId) struct LinkPlayerBlock *r2; struct SioInfo *r5; u8 r4 = Rfu.linkPlayerIdx[gUnknown_843EC38[Rfu.unk_ce9]]; - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) + if (Rfu.status == 1 || Rfu.status == 2) { - Rfu.unk_ce8 = FALSE; + Rfu.foundNewLeaderMaybe = FALSE; DestroyTask(taskId); } switch (gTasks[taskId].data[0]) { case 0: - if (gSendCmd[0] == 0) + if (IsSendCmdComplete()) { ResetBlockReceivedFlag(r4); - RfuPrepareSendBuffer(RFUCMD_0x7800); + RfuPrepareSendBuffer(RFUCMD_PLAYERS_LIST_2); gTasks[taskId].data[0]++; } break; case 1: - if (gSendCmd[0] == 0) + if (IsSendCmdComplete()) gTasks[taskId].data[0]++; break; case 2: @@ -1792,16 +1842,16 @@ static void Task_ExchangeLinkPlayers(u8 taskId) { CpuFill16(0, gBlockRecvBuffer, sizeof(struct SioInfo)); ResetBlockReceivedFlag(0); - Rfu.unk_ce8 = FALSE; + Rfu.foundNewLeaderMaybe = FALSE; if (Rfu.unionRoomChatters) { for (i = 0; i < RFU_CHILD_MAX; i++) { if ((Rfu.unionRoomChatters >> i) & 1) { - Rfu.unk_ce5 = 1 << i; + Rfu.bmChatLeaderMaybe = 1 << i; Rfu.unionRoomChatters ^= (1 << i); - Rfu.unk_ce8 = TRUE; + Rfu.foundNewLeaderMaybe = TRUE; break; } } @@ -1814,14 +1864,14 @@ static void Task_ExchangeLinkPlayers(u8 taskId) static void sub_80FACF0(u8 taskId) { - if (Rfu.unk_f1 == 1 || Rfu.unk_f1 == 2) + if (Rfu.status == RFU_STATUS_FATAL_ERROR || Rfu.status == RFU_STATUS_CONNECTION_ERROR) DestroyTask(taskId); switch (gTasks[taskId].data[0]) { case 0: - if (Rfu.playerCount) + if (Rfu.playerCount != 0) { - PrepareLocalLinkPlayerBlock(); + LocalLinkPlayerToBlock(); SendBlock(0, gBlockSendBuffer, sizeof(struct LinkPlayerBlock)); gTasks[taskId].data[0]++; } @@ -1850,15 +1900,20 @@ static void RfuCheckErrorStatus(void) gWirelessCommType = 2; SetMainCallback2(CB2_LinkError); gMain.savedCallback = CB2_LinkError; - SetLinkErrorFromRfu((Rfu.linkman_msg << 16) | (Rfu.linkman_param[0] << 8) | Rfu.linkman_param[1], Rfu.unk_124.count, Rfu.sendQueue.count, RfuGetErrorStatus() == 2); + SetLinkErrorFromRfu( + (Rfu.linkman_msg << 16) | (Rfu.linkman_param[0] << 8) | Rfu.linkman_param[1], + Rfu.recvQueue.count, + Rfu.sendQueue.count, + RfuGetStatus() == RFU_STATUS_CONNECTION_ERROR + ); Rfu.errorState = 2; CloseLink(); } - else if (Rfu.sendQueue.full == 1 || Rfu.unk_124.full == 1) + else if (Rfu.sendQueue.full == TRUE || Rfu.recvQueue.full == TRUE) { if (lman.childClockSlave_flag) rfu_LMAN_requestChangeAgbClockMaster(); - RfuSetErrorStatus(1, 0x7000); + RfuSetStatus(RFU_STATUS_FATAL_ERROR, 0x7000); GetLinkmanErrorParams(0x7000); } } @@ -1882,13 +1937,13 @@ bool32 LinkRfuMain1(void) { switch (Rfu.parent_child) { - case 1: + case MODE_PARENT: sub_80F911C(); break; - case 0: + case MODE_CHILD: retval = RfuProcessEnqueuedRecvBlock(); break; - case 2: + case MODE_P_C_SWITCH: rfu_REQ_recvData_then_sendData(); break; } @@ -1916,7 +1971,7 @@ static void CopyPlayerNameToUnameBuffer(void) void ClearAndInitHostRFUtgtGname(void) { memset(&gHostRFUtgtGnameBuffer, 0, RFU_GAME_NAME_LENGTH); - InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, 0, FALSE, 0); + InitHostRFUtgtGname(&gHostRFUtgtGnameBuffer, ACTIVITY_NONE, FALSE, 0); } void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, u32 started) @@ -2034,9 +2089,9 @@ static void LmanCallback_Parent2(u8 msg, u8 param_count) struct GFtgtGname *structPtr = (void *)&gRfuLinkStatus->partner[i].gname; if (structPtr->activity == GetHostRFUtgtGname()->activity) { - Rfu.unk_cd1[i] = 0; - Rfu.unk_cd5[i] = 0; - rfu_setRecvBuffer(TYPE_NI, i, Rfu.unk_cd5 + i, 1); + Rfu.partnerSendStatuses[i] = RFU_STATUS_OK; + Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK; + rfu_setRecvBuffer(TYPE_NI, i, Rfu.partnerRecvStatuses + i, 1); } else { @@ -2079,7 +2134,7 @@ static void LmanCallback_Parent2(u8 msg, u8 param_count) else sub_80FB174(); } - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case 0x34: break; @@ -2088,7 +2143,7 @@ static void LmanCallback_Parent2(u8 msg, u8 param_count) case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; case LMAN_MSG_LMAN_API_ERROR_RETURN: - RfuSetErrorStatus(1, msg); + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); Rfu.isShuttingDown = TRUE; break; @@ -2097,8 +2152,8 @@ static void LmanCallback_Parent2(u8 msg, u8 param_count) 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; + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); + Rfu.unk_cdb = TRUE; break; } } @@ -2121,38 +2176,38 @@ static void LmanCallback_Child(u8 msg, u8 param_count) Rfu.child_slot = lman.param[0]; break; case LMAN_MSG_CONNECT_PARENT_FAILED: - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: Rfu.state = 11; - Rfu.unk_c85 = 0; - Rfu.unk_c86 = 0; - rfu_setRecvBuffer(TYPE_NI, Rfu.child_slot, &Rfu.unk_c86, 1); + Rfu.sendStatus = RFU_STATUS_OK; + Rfu.recvStatus = RFU_STATUS_OK; + rfu_setRecvBuffer(TYPE_NI, Rfu.child_slot, &Rfu.recvStatus, 1); rfu_setRecvBuffer(TYPE_UNI, Rfu.child_slot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); break; case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: Rfu.linkLossRecoveryState = 2; - if (Rfu.unk_c86 == 6) + if (Rfu.recvStatus == RFU_STATUS_JOIN_GROUP_NO) break; case LMAN_MSG_LINK_RECOVERY_FAILED_AND_DISCONNECTED: if (Rfu.linkLossRecoveryState != 2) Rfu.linkLossRecoveryState = 4; - if (Rfu.unk_c86 != 9) - RfuSetErrorStatus(2, msg); - rfu_dbg_print_str("LINK LOSS DISCONNECT!", 5, 5); + if (Rfu.recvStatus != RFU_STATUS_LEAVE_GROUP) + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); + Debug_PrintString("LINK LOSS DISCONNECT!", 5, 5); if (gReceivedRemoteLinkPlayers == 1) GetLinkmanErrorParams(msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: Rfu.linkLossRecoveryState = 1; - rfu_dbg_print_str("LINK LOSS RECOVERY NOW", 5, 5); + Debug_PrintString("LINK LOSS RECOVERY NOW", 5, 5); break; case LMAN_MSG_LINK_RECOVERY_SUCCESSED: Rfu.linkLossRecoveryState = 3; - Rfu.unk_c3c = 1; + Rfu.linkRecovered = 1; break; case 0x34: break; @@ -2161,7 +2216,7 @@ static void LmanCallback_Child(u8 msg, u8 param_count) case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; case LMAN_MSG_LMAN_API_ERROR_RETURN: - RfuSetErrorStatus(1, msg); + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); Rfu.isShuttingDown = TRUE; break; @@ -2169,9 +2224,9 @@ static void LmanCallback_Child(u8 msg, u8 param_count) 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); + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); - Rfu.unk_cdb = 1; + Rfu.unk_cdb = TRUE; break; } } @@ -2218,20 +2273,20 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) Rfu.state = 17; break; case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: - RfuSetErrorStatus(4, 0); + RfuSetStatus(RFU_STATUS_NEW_CHILD_DETECTED, 0); break; case LMAN_MSG_NEW_CHILD_CONNECT_ACCEPTED: - if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && Rfu.unk_cd9 == 0) + if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && !Rfu.linkClosing) { u8 bmAcceptSlot = GetNewChildrenInUnionRoomChat(lman.param[0]); if (bmAcceptSlot != 0) { - r1 = 1 << sub_80F886C(bmAcceptSlot); - if (Rfu.unionRoomChatters == 0 && !Rfu.unk_ce8) + r1 = 1 << CountTrailingZeroes(bmAcceptSlot); + if (Rfu.unionRoomChatters == 0 && !Rfu.foundNewLeaderMaybe) { - Rfu.unk_ce5 = r1; + Rfu.bmChatLeaderMaybe = r1; Rfu.unionRoomChatters |= (r1 ^ bmAcceptSlot); - Rfu.unk_ce8 = TRUE; + Rfu.foundNewLeaderMaybe = TRUE; } else { @@ -2258,11 +2313,11 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) case LMAN_MSG_END_WAIT_CHILD_NAME: if (GetHostRFUtgtGname()->activity != (ACTIVITY_CHAT | IN_UNION_ROOM) && lman.acceptCount > 1) { - r1 = 1 << sub_80F886C(lman.param[0]); + r1 = 1 << CountTrailingZeroes(lman.param[0]); rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1); rfu_waitREQComplete(); } - if (Rfu.state == 0xF) + if (Rfu.state == 15) Rfu.state = 16; break; case LMAN_MSG_PARENT_FOUND: @@ -2282,16 +2337,16 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) } else { - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); } break; case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: Rfu.state = 13; - RfuSetErrorStatus(3, 0); + RfuSetStatus(RFU_STATUS_CHILD_SEND_COMPLETE, 0); rfu_setRecvBuffer(TYPE_UNI, Rfu.child_slot, Rfu.unk_c3f, sizeof(Rfu.unk_c3f)); break; case LMAN_MSG_CHILD_NAME_SEND_FAILED_AND_DISCONNECTED: - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: if (lman.acceptSlot_flag & lman.param[0]) @@ -2300,7 +2355,7 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) case LMAN_MSG_LINK_RECOVERY_SUCCESSED: Rfu.linkLossRecoveryState = 3; if (gRfuLinkStatus->parentChild == MODE_CHILD) - Rfu.unk_c3c = 1; + Rfu.linkRecovered = 1; break; case LMAN_MSG_LINK_LOSS_DETECTED_AND_DISCONNECTED: Rfu.linkLossRecoveryState = 2; @@ -2328,7 +2383,7 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) if (gRfuLinkStatus->parentChild == MODE_NEUTRAL && lman.pcswitch_flag == 0 && FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) Rfu.state = 17; - RfuSetErrorStatus(2, msg); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); break; case LMAN_MSG_LINK_DISCONNECTED_BY_USER: Rfu.bm_DisconnectSlot = 0; @@ -2338,7 +2393,7 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: break; case LMAN_MSG_LMAN_API_ERROR_RETURN: - RfuSetErrorStatus(1, msg); + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); GetLinkmanErrorParams(msg); Rfu.isShuttingDown = TRUE; break; @@ -2347,8 +2402,8 @@ static void LmanCallback_Parent(u8 msg, u8 param_count) 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; + RfuSetStatus(RFU_STATUS_FATAL_ERROR, msg); + Rfu.unk_cdb = FALSE; break; } } @@ -2358,29 +2413,29 @@ void sub_80FB9D0(void) Rfu.unk_ce4 = 2; } -void RfuSetErrorStatus(u8 a0, u16 msg) +void RfuSetStatus(u8 status, u16 msg) { - Rfu.unk_f1 = a0; + Rfu.status = status; Rfu.linkman_msg = msg; } -u8 RfuGetErrorStatus(void) +u8 RfuGetStatus(void) { - return Rfu.unk_f1; + return Rfu.status; } -bool32 RfuIsErrorStatus1or2(void) +bool32 RfuHasErrored(void) { - u32 var = RfuGetErrorStatus(); - if (var == 1 || var == 2) + u32 status = RfuGetStatus(); + if (status == RFU_STATUS_FATAL_ERROR || status == RFU_STATUS_CONNECTION_ERROR) return TRUE; else return FALSE; } -bool32 GetRfuUnkCE8(void) +bool32 RfuHasFoundNewLeader(void) { - return Rfu.unk_ce8; + return Rfu.foundNewLeaderMaybe; } bool8 Rfu_IsMaster(void) @@ -2416,7 +2471,7 @@ static void sub_80FBA78(void) SetVBlankCallback(sub_80FBA64); if (IsWirelessAdapterConnected()) { - gLinkType = LINKTYPE_0x1111; + gLinkType = LINKTYPE_TRADE; SetWirelessCommType1(); OpenLink(); SeedRng(gMain.vblankCounter2); @@ -2441,13 +2496,13 @@ bool32 IsUnionRoomListenTaskActive(void) void LinkRfu_CreateIdleTask(void) { if (!FuncIsActiveTask(Task_idle)) - Rfu.unk_66 = CreateTask(Task_idle, 0); + Rfu.idleTaskId = CreateTask(Task_idle, 0); } void LinkRfu_DestroyIdleTask(void) { if (FuncIsActiveTask(Task_idle) == TRUE) - DestroyTask(Rfu.unk_66); + DestroyTask(Rfu.idleTaskId); } static void sub_80FBB74(void) @@ -2486,7 +2541,7 @@ void InitializeRfuLinkManager_EnterUnionRoom(void) sRfuReqConfig = sRfuReqConfigTemplate; sRfuReqConfig.linkRecovery_enable = 0; sRfuReqConfig.linkRecovery_period = 600; - Rfu.unk_67 = CreateTask(Task_LinkRfu_UnionRoomListen, 1); + Rfu.searchTaskId = CreateTask(Task_LinkRfu_UnionRoomListen, 1); } static u16 ReadU16(const void *ptr) @@ -2510,7 +2565,7 @@ static u8 GetPartnerIndexByNameAndTrainerID(const u8 *trainerName, u16 trainerId for (i = 0; i < RFU_CHILD_MAX; i++) { u16 partnerTrainerId = ReadU16(((struct GFtgtGname *)gRfuLinkStatus->partner[i].gname)->unk_00.playerTrainerId); - if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[i].serialNo) + if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[i].serialNo) && !StringCompare(trainerName, gRfuLinkStatus->partner[i].uname) && trainerId == partnerTrainerId) { @@ -2530,7 +2585,7 @@ static void RfuReqDisconnectSlot(u32 bmDisconnectSlot) Rfu.bm_PartnerFlags &= ~(bmDisconnectSlot); rfu_clearSlot(TYPE_UNI_SEND, Rfu.unk_cda); rfu_UNI_setSendData(Rfu.bm_PartnerFlags, Rfu.recvCmds, 70); - Rfu.unk_cda = sub_80F886C(Rfu.bm_PartnerFlags); + Rfu.unk_cda = CountTrailingZeroes(Rfu.bm_PartnerFlags); } void RequestDisconnectSlotByTrainerNameAndId(const u8 *trainerName, u16 trainerId) @@ -2559,12 +2614,12 @@ void sub_80FBD6C(u32 a0) static void sub_80FBDB8(u8 taskId) { - if (gSendCmd[0] == 0 && !Rfu.unk_ce8) + if (IsSendCmdComplete() && !Rfu.foundNewLeaderMaybe) { - RfuPrepareSendBuffer(RFUCMD_0xED00); + RfuPrepareSendBuffer(RFUCMD_PARENT_DISCONNECT); gSendCmd[1] = gTasks[taskId].data[0]; gSendCmd[2] = gTasks[taskId].data[1]; - Rfu.playerCount -= gUnknown_843EC41[gTasks[taskId].data[0]]; + Rfu.playerCount -= sNumSetBits[gTasks[taskId].data[0]]; gSendCmd[3] = Rfu.playerCount; DestroyTask(taskId); } @@ -2590,7 +2645,7 @@ static void Task_RfuReconnectWithParent(u8 taskId) { s16 *data = gTasks[taskId].data; - if (RfuStateIs7AndPlayerIsChild()) + if (ContactedByParentAttemptingToReconnect()) { u8 id = GetPartnerIndexByNameAndTrainerID((u8*)data, ReadU16(&data[8])); if (id != 0xFF) @@ -2607,7 +2662,7 @@ static void Task_RfuReconnectWithParent(u8 taskId) } else { - RfuSetErrorStatus(2, 0x7000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000); DestroyTask(taskId); } } @@ -2624,7 +2679,7 @@ static void Task_RfuReconnectWithParent(u8 taskId) if (data[15] > 240) { - RfuSetErrorStatus(2, 0x7000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000); DestroyTask(taskId); } } @@ -2634,7 +2689,7 @@ void CreateTask_RfuReconnectWithParent(const u8 *trainerName, u16 trainerId) u8 taskId; s16 *data; - Rfu.unk_f1 = 0; + Rfu.status = RFU_STATUS_OK; taskId = CreateTask(Task_RfuReconnectWithParent, 3); data = gTasks[taskId].data; StringCopy((u8*)(data), trainerName); @@ -2654,7 +2709,7 @@ static bool32 ShouldRejectPartnerConnectionBasedOnActivity(s16 activity, struct } else if (activity == (ACTIVITY_TRADE | IN_UNION_ROOM)) { - struct GFtgtGname *myTradeGname = (struct GFtgtGname *)&Rfu.unk_104.gname; + struct GFtgtGname *myTradeGname = (struct GFtgtGname *)&Rfu.tgtData.gname; if (myTradeGname->species == SPECIES_EGG) { if (partnerGname->species == myTradeGname->species) @@ -2675,19 +2730,19 @@ static bool32 ShouldRejectPartnerConnectionBasedOnActivity(s16 activity, struct static void sub_80FC028(u8 taskId) { - if (Rfu.unk_f1 == 4) + if (Rfu.status == RFU_STATUS_NEW_CHILD_DETECTED) DestroyTask(taskId); if (++gTasks[taskId].data[0] > 300) { - RfuSetErrorStatus(2, 0x7000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000); DestroyTask(taskId); } if (Rfu.parentId != 0 && lman.parent_child == MODE_CHILD) { - u16 trainerId = ReadU16(((struct GFtgtGname *)&Rfu.unk_104.gname)->unk_00.playerTrainerId); - u8 id = GetPartnerIndexByNameAndTrainerID(Rfu.unk_104.uname, trainerId); + u16 trainerId = ReadU16(((struct GFtgtGname *)&Rfu.tgtData.gname)->unk_00.playerTrainerId); + u8 id = GetPartnerIndexByNameAndTrainerID(Rfu.tgtData.uname, trainerId); if (id != 0xFF) { if (!ShouldRejectPartnerConnectionBasedOnActivity(gTasks[taskId].data[1], (struct GFtgtGname *)&gRfuLinkStatus->partner[id].gname)) @@ -2700,7 +2755,7 @@ static void sub_80FC028(u8 taskId) } else { - RfuSetErrorStatus(2, 0x7000); + RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, 0x7000); DestroyTask(taskId); } } @@ -2712,9 +2767,9 @@ void sub_80FC114(const u8 *name, struct GFtgtGname *structPtr, u8 activity) u8 taskId, taskId2; Rfu.unk_ccf = 0; - Rfu.unk_f1 = 0; - StringCopy(Rfu.unk_104.uname, name); - memcpy(Rfu.unk_104.gname, structPtr, RFU_GAME_NAME_LENGTH); + Rfu.status = RFU_STATUS_OK; + StringCopy(Rfu.tgtData.uname, name); + memcpy(Rfu.tgtData.gname, structPtr, RFU_GAME_NAME_LENGTH); rfu_LMAN_forceChangeSP(); taskId = CreateTask(sub_80FC028, 2); gTasks[taskId].data[1] = activity; @@ -2731,7 +2786,7 @@ void sub_80FC114(const u8 *name, struct GFtgtGname *structPtr, u8 activity) } } -bool8 sub_80FC1B0(void) +bool8 IsRfuRecoveringFromLinkLoss(void) { if (Rfu.linkLossRecoveryState == 1) return TRUE; @@ -2745,19 +2800,19 @@ bool32 sub_80FC1CC(void) for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((lman.acceptSlot_flag >> i) & 1 && Rfu.unk_cd1[i] == 0) + if ((lman.acceptSlot_flag >> i) & 1 && Rfu.partnerSendStatuses[i] == 0) return FALSE; } return TRUE; } -static void rfu_dbg_clear(void) +static void Debug_PrintEmpty(void) { s32 i; for (i = 0; i < 20; i++) - rfu_dbg_print_str(" ", 0, i); + Debug_PrintString(" ", 0, i); } static const char gUnknown_843EE47[16] = { @@ -2773,44 +2828,44 @@ static const char gUnknown_843EE57[9] = { static const char gUnknown_843EE60[] = {' ', '\0'}; static const char gUnknown_843EE62[] = {'*', '\0'}; -static void rfu_dbg_print_status(void) +static void Debug_PrintStatus(void) { s32 i, j; - rfu_dbg_print_num(GetBlockReceivedStatus(), 0x1C, 0x13, 2); - rfu_dbg_print_num(gRfuLinkStatus->connSlotFlag, 0x14, 1, 1); - rfu_dbg_print_num(gRfuLinkStatus->linkLossSlotFlag, 0x17, 1, 1); + Debug_PrintNum(GetBlockReceivedStatus(), 0x1C, 0x13, 2); + Debug_PrintNum(gRfuLinkStatus->connSlotFlag, 0x14, 1, 1); + Debug_PrintNum(gRfuLinkStatus->linkLossSlotFlag, 0x17, 1, 1); if (Rfu.parent_child == MODE_PARENT) { for (i = 0; i < RFU_CHILD_MAX; i++) { if ((gRfuLinkStatus->getNameFlag >> i) & 1) { - rfu_dbg_print_num(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); - rfu_dbg_print_str((void*) &gRfuLinkStatus->partner[i].gname, 6, i + 3); - rfu_dbg_print_str(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 < RFU_CHILD_MAX; i++) { for (j = 0; j < 14; j++) { - rfu_dbg_print_num(Rfu.unk_14[i][j], j * 2, i + 11, 2); + Debug_PrintNum(Rfu.main_UNI_recvBuffer[i][j], j * 2, i + 11, 2); } } - rfu_dbg_print_str("NOWSLOT", 1, 0xF); + Debug_PrintString("NOWSLOT", 1, 0xF); } else if (gRfuLinkStatus->connSlotFlag != 0 && gRfuLinkStatus->getNameFlag != 0) { for (i = 0; i < RFU_CHILD_MAX; i++) { - rfu_dbg_print_num(0, 1, i + 3, 4); - rfu_dbg_print_str(gUnknown_843EE47, 6, i + 3); - rfu_dbg_print_str(gUnknown_843EE57, 0x16, i + 3); + Debug_PrintNum(0, 1, i + 3, 4); + Debug_PrintString(gUnknown_843EE47, 6, i + 3); + Debug_PrintString(gUnknown_843EE57, 0x16, i + 3); } - rfu_dbg_print_num(gRfuLinkStatus->partner[Rfu.child_slot].serialNo, 1, 3, 4); - rfu_dbg_print_str(gRfuLinkStatus->partner[Rfu.child_slot].gname, 6, 3); - rfu_dbg_print_str(gRfuLinkStatus->partner[Rfu.child_slot].uname, 0x16, 3); + Debug_PrintNum(gRfuLinkStatus->partner[Rfu.child_slot].serialNo, 1, 3, 4); + Debug_PrintString(gRfuLinkStatus->partner[Rfu.child_slot].gname, 6, 3); + Debug_PrintString(gRfuLinkStatus->partner[Rfu.child_slot].uname, 0x16, 3); } else { @@ -2818,16 +2873,16 @@ static void rfu_dbg_print_status(void) { if (gRfuLinkStatus->partner[i].slot != 0xFF) { - rfu_dbg_print_num(gRfuLinkStatus->partner[i].serialNo, 1, i + 3, 4); - rfu_dbg_print_num(gRfuLinkStatus->partner[i].id, 6, i + 3, 4); - rfu_dbg_print_str(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 < RFU_CHILD_MAX; i++) { - rfu_dbg_print_num(0, 1, i + 3, 4); - rfu_dbg_print_str(gUnknown_843EE47, 6, i + 3); - rfu_dbg_print_str(gUnknown_843EE57, 0x16, i + 3); + Debug_PrintNum(0, 1, i + 3, 4); + Debug_PrintString(gUnknown_843EE47, 6, i + 3); + Debug_PrintString(gUnknown_843EE57, 0x16, i + 3); } } } @@ -2846,14 +2901,14 @@ static const char gUnknown_843EEA8[][8] = { "SEARCH" }; -static u32 sub_80FC44C(void) +static u32 GetRfuSendQueueLength(void) { return Rfu.sendQueue.count; } u32 GetRfuRecvQueueLength(void) { - return Rfu.unk_124.count; + return Rfu.recvQueue.count; } static void Task_idle(u8 taskId) diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index 7aac44593..91695dfc9 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -13,22 +13,83 @@ static const u16 gWirelessLinkIconPalette[] = INCBIN_U16("graphics/interface/wir static const u32 gWirelessLinkIconPic[] = INCBIN_U32("graphics/interface/wireless_link_icon.4bpp.lz"); static const u8 sWireless_ASCIItoRSETable[] = { - 0xff, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x37, + EOS, + 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x00, 0xab, 0xb5, 0xb6, 0xb1, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xb2, 0xf1, 0x00, 0xae, 0xad, 0xba, - 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, - 0xa9, 0xaa, 0x00, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, - 0x00, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, 0xc1, - 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, - 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, - 0xd2, 0xd3, 0xd4, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, - 0x00, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, - 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, - 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, - 0xec, 0xed, 0xee, 0x2d, 0x2f, 0x30, 0x31, 0x32, + [' '] = CHAR_SPACE, + ['!'] = CHAR_EXCL_MARK, + 0xb5, 0xb6, 0xb1, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xb2, 0xf1, 0x00, + ['-'] = CHAR_HYPHEN, + ['.'] = CHAR_PERIOD, + ['/'] = CHAR_SLASH, + ['0'] = CHAR_0, + ['1'] = CHAR_1, + ['2'] = CHAR_2, + ['3'] = CHAR_3, + ['4'] = CHAR_4, + ['5'] = CHAR_5, + ['6'] = CHAR_6, + ['7'] = CHAR_7, + ['8'] = CHAR_8, + ['9'] = CHAR_9, + 0x00, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0x00, + ['A'] = CHAR_A, + ['B'] = CHAR_B, + ['C'] = CHAR_C, + ['D'] = CHAR_D, + ['E'] = CHAR_E, + ['F'] = CHAR_F, + ['G'] = CHAR_G, + ['H'] = CHAR_H, + ['I'] = CHAR_I, + ['J'] = CHAR_J, + ['K'] = CHAR_K, + ['L'] = CHAR_L, + ['M'] = CHAR_M, + ['N'] = CHAR_N, + ['O'] = CHAR_O, + ['P'] = CHAR_P, + ['Q'] = CHAR_Q, + ['R'] = CHAR_R, + ['S'] = CHAR_S, + ['T'] = CHAR_T, + ['U'] = CHAR_U, + ['V'] = CHAR_V, + ['W'] = CHAR_W, + ['X'] = CHAR_X, + ['Y'] = CHAR_Y, + ['Z'] = CHAR_Z, + 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0x00, + ['a'] = CHAR_a, + ['b'] = CHAR_b, + ['c'] = CHAR_c, + ['d'] = CHAR_d, + ['e'] = CHAR_e, + ['f'] = CHAR_f, + ['g'] = CHAR_g, + ['h'] = CHAR_h, + ['i'] = CHAR_i, + ['j'] = CHAR_j, + ['k'] = CHAR_k, + ['l'] = CHAR_l, + ['m'] = CHAR_m, + ['n'] = CHAR_n, + ['o'] = CHAR_o, + ['p'] = CHAR_p, + ['q'] = CHAR_q, + ['r'] = CHAR_r, + ['s'] = CHAR_s, + ['t'] = CHAR_t, + ['u'] = CHAR_u, + ['v'] = CHAR_v, + ['w'] = CHAR_w, + ['x'] = CHAR_x, + ['y'] = CHAR_y, + ['z'] = CHAR_z, + 0x2d, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x50, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, @@ -48,53 +109,118 @@ static const u8 sWireless_ASCIItoRSETable[] = { }; static const u8 sWireless_RSEtoASCIITable[] = { - 0x20, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, - 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, - 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, - 0x9d, 0x9e, 0x9f, 0xa0, 0xe0, 0xe1, 0xe2, 0xe3, - 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, - 0xec, 0xed, 0xee, 0xef, 0xf0, 0x7b, 0xf1, 0x7c, - 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - 0x84, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, - 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, - 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, - 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, - 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, - 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xa6, 0xdd, 0xa7, - 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xf2, - 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, - 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0xaf, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x21, 0xdf, 0xa1, 0xb0, 0xa5, - 0xde, 0x24, 0x2a, 0xa2, 0xa3, 0x22, 0x23, 0x20, - 0xa4, 0x20, 0x2f, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, - 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, - 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, - 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, - 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, - 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x20, - 0x20, 0x2b, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00 + [CHAR_SPACE] = ' ', + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, + 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, + 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, + 0x9e, 0x9f, 0xa0, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, + 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, + 0xed, 0xee, 0xef, 0xf0, 0x7b, 0xf1, 0x7c, 0x7d, + 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, + 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x84, + 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, + 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0, + 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, + 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, + 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + 0xd9, 0xda, 0xdb, 0xdc, 0xa6, 0xdd, 0xa7, 0xa8, + 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xf2, 0xf3, + 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, + 0xfc, 0xfd, 0xfe, 0xff, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0xaf, + [CHAR_0] = '0', + [CHAR_1] = '1', + [CHAR_2] = '2', + [CHAR_3] = '3', + [CHAR_4] = '4', + [CHAR_5] = '5', + [CHAR_6] = '6', + [CHAR_7] = '7', + [CHAR_8] = '8', + [CHAR_9] = '9', + [CHAR_EXCL_MARK] = '!', + 0xdf, 0xa1, 0xb0, 0xa5, 0xde, 0x24, 0x2a, + 0xa2, 0xa3, 0x22, 0x23, 0x20, 0xa4, 0x20, + [CHAR_SLASH] = '/', + [CHAR_A] = 'A', + [CHAR_B] = 'B', + [CHAR_C] = 'C', + [CHAR_D] = 'D', + [CHAR_E] = 'E', + [CHAR_F] = 'F', + [CHAR_G] = 'G', + [CHAR_H] = 'H', + [CHAR_I] = 'I', + [CHAR_J] = 'J', + [CHAR_K] = 'K', + [CHAR_L] = 'L', + [CHAR_M] = 'M', + [CHAR_N] = 'N', + [CHAR_O] = 'O', + [CHAR_P] = 'P', + [CHAR_Q] = 'Q', + [CHAR_R] = 'R', + [CHAR_S] = 'S', + [CHAR_T] = 'T', + [CHAR_U] = 'U', + [CHAR_V] = 'V', + [CHAR_W] = 'W', + [CHAR_X] = 'X', + [CHAR_Y] = 'Y', + [CHAR_Z] = 'Z', + [CHAR_a] = 'a', + [CHAR_b] = 'b', + [CHAR_c] = 'c', + [CHAR_d] = 'd', + [CHAR_e] = 'e', + [CHAR_f] = 'f', + [CHAR_g] = 'g', + [CHAR_h] = 'h', + [CHAR_i] = 'i', + [CHAR_j] = 'j', + [CHAR_k] = 'k', + [CHAR_l] = 'l', + [CHAR_m] = 'm', + [CHAR_n] = 'n', + [CHAR_o] = 'o', + [CHAR_p] = 'p', + [CHAR_q] = 'q', + [CHAR_r] = 'r', + [CHAR_s] = 's', + [CHAR_t] = 't', + [CHAR_u] = 'u', + [CHAR_v] = 'v', + [CHAR_w] = 'w', + [CHAR_x] = 'x', + [CHAR_y] = 'y', + [CHAR_z] = 'z', + 0x20, 0x20, 0x2b, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + [CHAR_DYNAMIC_PLACEHOLDER] = ' ', + [CHAR_KEYPAD_ICON] = ' ', + [CHAR_EXTRA_EMOJI] = ' ', + [CHAR_PROMPT_SCROLL] = ' ', + [CHAR_PROMPT_CLEAR] = ' ', + [EXT_CTRL_CODE_BEGIN] = ' ', + [PLACEHOLDER_BEGIN] = ' ', + [CHAR_NEWLINE] = ' ', + [EOS] = 0 }; static const struct OamData sWirelessStatusIndicatorOamData = - { - .y = 0, - .affineMode = ST_OAM_AFFINE_OFF, - .objMode = ST_OAM_OBJ_NORMAL, - .bpp = ST_OAM_4BPP, - .shape = SPRITE_SHAPE(16x16), - .x = 0, - .size = SPRITE_SIZE(16x16), - .tileNum = 0, - .priority = 0, - .paletteNum = 0, - }; +{ + .y = 0, + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .bpp = ST_OAM_4BPP, + .shape = SPRITE_SHAPE(16x16), + .x = 0, + .size = SPRITE_SIZE(16x16), + .tileNum = 0, + .priority = 0, + .paletteNum = 0, +}; static const union AnimCmd sWirelessStatusIndicatorAnim0[] = { // 3 bars @@ -154,23 +280,25 @@ static const struct SpritePalette sWirelessStatusIndicatorSpritePalette = { }; static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { - 0xD431, - 0xD432, - &sWirelessStatusIndicatorOamData, - sWirelessStatusIndicatorAnims, - NULL, - gDummySpriteAffineAnimTable, - SpriteCallbackDummy + .tileTag = 0xD431, + .paletteTag = 0xD432, + .oam = &sWirelessStatusIndicatorOamData, + .anims = sWirelessStatusIndicatorAnims, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy }; -void RFU_queue_20_70_reset(struct UnkRfuStruct_2_Sub_124 *queue) +// A bunch of FIFO queues + +void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) { s32 i; s32 j; - for (i = 0; i < 20; i++) + for (i = 0; i < RECV_QUEUE_NUM_SLOTS; i++) { - for (j = 0; j < 70; j++) + for (j = 0; j < RECV_QUEUE_SLOT_LENGTH; j++) { queue->slots[i][j] = 0; } @@ -178,124 +306,124 @@ void RFU_queue_20_70_reset(struct UnkRfuStruct_2_Sub_124 *queue) queue->send_slot = 0; queue->recv_slot = 0; queue->count = 0; - queue->full = 0; + queue->full = FALSE; } -void RFU_queue_40_14_reset(struct RfuSendQueue *ptr) +void RfuSendQueue_Reset(struct RfuSendQueue *queue) { s32 i; s32 j; - for (i = 0; i < 40; i++) + for (i = 0; i < SEND_QUEUE_NUM_SLOTS; i++) { - for (j = 0; j < 14; j++) + for (j = 0; j < SEND_QUEUE_SLOT_LENGTH; j++) { - ptr->slots[i][j] = 0; + queue->slots[i][j] = 0; } } - ptr->send_slot = 0; - ptr->recv_slot = 0; - ptr->count = 0; - ptr->full = 0; + queue->send_slot = 0; + queue->recv_slot = 0; + queue->count = 0; + queue->full = FALSE; } -static void RFU_queue_2_256_reset(struct UnkRfuStruct_Sub_Unused *ptr) +static void RfuUnusedQueue_Reset(struct RfuUnusedQueue *queue) { s32 i; s32 j; - for (i = 0; i < 2; i++) + for (i = 0; i < UNUSED_QUEUE_NUM_SLOTS; i++) { - for (j = 0; j < 256; j++) + for (j = 0; j < UNUSED_QUEUE_SLOT_LENGTH; j++) { - ptr->slots[i][j] = 0; + queue->slots[i][j] = 0; } } - ptr->send_slot = 0; - ptr->recv_slot = 0; - ptr->count = 0; - ptr->full = 0; + queue->send_slot = 0; + queue->recv_slot = 0; + queue->count = 0; + queue->full = FALSE; } -void RFU_queue_20_70_recv(struct UnkRfuStruct_2_Sub_124 *queue, u8 *data) +void RfuRecvQueue_Enqueue(struct RfuRecvQueue *queue, u8 *src) { s32 i; u16 imeBak; u8 count; - if (queue->count < 20) + if (queue->count < RECV_QUEUE_NUM_SLOTS) { imeBak = REG_IME; REG_IME = 0; count = 0; - for (i = 0; i < 70; i += 14) + for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i += RECV_QUEUE_SLOT_LENGTH / MAX_RFU_PLAYERS) { - if (data[i] == 0 && data[i + 1] == 0) + if (src[i] == 0 && src[i + 1] == 0) { count++; } } - if (count != 5) + if (count != MAX_RFU_PLAYERS) { - for (i = 0; i < 70; i++) + for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++) { - queue->slots[queue->recv_slot][i] = data[i]; + queue->slots[queue->recv_slot][i] = src[i]; } queue->recv_slot++; - queue->recv_slot %= 20; + queue->recv_slot %= RECV_QUEUE_NUM_SLOTS; queue->count++; - for (i = 0; i < 70; i++) + for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++) { - data[i] = 0; + src[i] = 0; } } REG_IME = imeBak; } else { - queue->full = 1; + queue->full = TRUE; } } -void RFU_queue_40_14_recv(struct RfuSendQueue *queue, u8 *data) +void RfuSendQueue_Enqueue(struct RfuSendQueue *queue, u8 *src) { s32 i; u16 imeBak; - if (queue->count < 40) + if (queue->count < SEND_QUEUE_NUM_SLOTS) { imeBak = REG_IME; REG_IME = 0; - for (i = 0; i < 14; i++) + for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++) { - if (data[i] != 0) + if (src[i] != 0) { break; } } - if (i != 14) + if (i != SEND_QUEUE_SLOT_LENGTH) { - for (i = 0; i < 14; i++) + for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++) { - queue->slots[queue->recv_slot][i] = data[i]; + queue->slots[queue->recv_slot][i] = src[i]; } queue->recv_slot++; - queue->recv_slot %= 40; + queue->recv_slot %= SEND_QUEUE_NUM_SLOTS; queue->count++; - for (i = 0; i < 14; i++) + for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++) { - data[i] = 0; + src[i] = 0; } } REG_IME = imeBak; } else { - queue->full = 1; + queue->full = TRUE; } } -bool8 RFU_queue_20_70_send(struct UnkRfuStruct_2_Sub_124 *queue, u8 *dest) +bool8 RfuRecvQueue_Dequeue(struct RfuRecvQueue *queue, u8 *dest) { u16 imeBak; s32 i; @@ -304,63 +432,63 @@ bool8 RFU_queue_20_70_send(struct UnkRfuStruct_2_Sub_124 *queue, u8 *dest) REG_IME = 0; if (queue->recv_slot == queue->send_slot || queue->full) { - for (i = 0; i < 70; i++) + for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++) { dest[i] = 0; } REG_IME = imeBak; return FALSE; } - for (i = 0; i < 70; i++) + for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++) { dest[i] = queue->slots[queue->send_slot][i]; } queue->send_slot++; - queue->send_slot %= 20; + queue->send_slot %= RECV_QUEUE_NUM_SLOTS; queue->count--; REG_IME = imeBak; return TRUE; } -bool8 RFU_queue_40_14_send(struct RfuSendQueue *queue, u8 *dest) +bool8 RfuSendQueue_Dequeue(struct RfuSendQueue *queue, u8 *dest) { s32 i; u16 imeBak; - if (queue->recv_slot == queue->send_slot || queue->full != 0) + if (queue->recv_slot == queue->send_slot || queue->full) { return FALSE; } imeBak = REG_IME; REG_IME = 0; - for (i = 0; i < 14; i++) + for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++) { dest[i] = queue->slots[queue->send_slot][i]; } queue->send_slot++; - queue->send_slot %= 40; + queue->send_slot %= SEND_QUEUE_NUM_SLOTS; queue->count--; REG_IME = imeBak; return TRUE; } -void RFU_queue_2_14_recv(struct UnkRfuStruct_2_Sub_c1c *queue, const u8 *data) +void RfuBackupQueue_Enqueue(struct RfuBackupQueue *queue, const u8 *dest) { s32 i; - if (data[1] == 0) + if (dest[1] == 0) { - RFU_queue_2_14_send(queue, NULL); + RfuBackupQueue_Dequeue(queue, NULL); } else { - for (i = 0; i < 14; i++) + for (i = 0; i < BACKUP_QUEUE_SLOT_LENGTH; i++) { - queue->slots[queue->recv_slot][i] = data[i]; + queue->slots[queue->recv_slot][i] = dest[i]; } queue->recv_slot++; - queue->recv_slot %= 2; - if (queue->count < 2) + queue->recv_slot %= BACKUP_QUEUE_NUM_SLOTS; + if (queue->count < BACKUP_QUEUE_NUM_SLOTS) { queue->count++; } @@ -371,7 +499,7 @@ void RFU_queue_2_14_recv(struct UnkRfuStruct_2_Sub_c1c *queue, const u8 *data) } } -bool8 RFU_queue_2_14_send(struct UnkRfuStruct_2_Sub_c1c *queue, u8 *dest) +bool8 RfuBackupQueue_Dequeue(struct RfuBackupQueue *queue, u8 *dest) { s32 i; @@ -381,38 +509,38 @@ bool8 RFU_queue_2_14_send(struct UnkRfuStruct_2_Sub_c1c *queue, u8 *dest) } if (dest != NULL) { - for (i = 0; i < 14; i++) + for (i = 0; i < BACKUP_QUEUE_SLOT_LENGTH; i++) { dest[i] = queue->slots[queue->send_slot][i]; } } queue->send_slot++; - queue->send_slot %= 2; + queue->send_slot %= BACKUP_QUEUE_NUM_SLOTS; queue->count--; return TRUE; } -static void RFU_queue_2_256_recv(struct UnkRfuStruct_Sub_Unused *queue, u8 *data) +static void RfuUnusedQueue_Dequeue(struct RfuUnusedQueue *queue, u8 *dest) { s32 i; - if (queue->count < 2) + if (queue->count < UNUSED_QUEUE_NUM_SLOTS) { - for (i = 0; i < 256; i++) + for (i = 0; i < UNUSED_QUEUE_SLOT_LENGTH; i++) { - queue->slots[queue->recv_slot][i] = data[i]; + queue->slots[queue->recv_slot][i] = dest[i]; } queue->recv_slot++; - queue->recv_slot %= 2; + queue->recv_slot %= UNUSED_QUEUE_NUM_SLOTS; queue->count++; } else { - queue->full = 1; + queue->full = TRUE; } } -static bool8 RFU_queue_2_256_send(struct UnkRfuStruct_Sub_Unused *queue, u8 *send) +static bool8 RfuUnusedQueue_Enqueue(struct RfuUnusedQueue *queue, u8 *dest) { s32 i; @@ -420,16 +548,17 @@ static bool8 RFU_queue_2_256_send(struct UnkRfuStruct_Sub_Unused *queue, u8 *sen { return FALSE; } - for (i = 0; i < 256; i++) + for (i = 0; i < UNUSED_QUEUE_SLOT_LENGTH; i++) { - send[i] = queue->slots[queue->send_slot][i]; + dest[i] = queue->slots[queue->send_slot][i]; } queue->send_slot++; - queue->send_slot %= 2; + queue->send_slot %= UNUSED_QUEUE_NUM_SLOTS; queue->count--; return TRUE; } +UNUSED static void sub_80FC9B8(u8 *q1, u8 mode) { s32 i; @@ -476,26 +605,26 @@ static void sub_80FC9B8(u8 *q1, u8 mode) } } -static void PkmnStrToASCII(u8 *q1, const u8 *q2) +static void PkmnStrToASCII(u8 *dest, const u8 *src) { s32 i; - for (i = 0; q2[i] != EOS; i++) + for (i = 0; src[i] != EOS; i++) { - q1[i] = sWireless_RSEtoASCIITable[q2[i]]; + dest[i] = sWireless_RSEtoASCIITable[src[i]]; } - q1[i] = 0; + dest[i] = 0; } -static void ASCIIToPkmnStr(u8 *q1, const u8 *q2) +static void ASCIIToPkmnStr(u8 *dest, const u8 *src) { s32 i; - for (i = 0; q2[i] != 0; i++) + for (i = 0; src[i] != 0; i++) { - q1[i] = sWireless_ASCIItoRSETable[q2[i]]; + dest[i] = sWireless_ASCIItoRSETable[src[i]]; } - q1[i] = EOS; + dest[i] = EOS; } static u8 GetConnectedChildStrength(u8 maxFlags) @@ -552,7 +681,7 @@ void InitHostRFUtgtGname(struct GFtgtGname *data, u8 activity, bool32 started, s data->unk_00.version = GAME_VERSION; data->unk_00.hasNews = FALSE; data->unk_00.hasCard = FALSE; - data->unk_00.unk_00_6 = 0; + data->unk_00.unknown = FALSE; data->unk_00.isChampion = FlagGet(FLAG_SYS_CAN_LINK_WITH_RS); data->unk_00.hasNationalDex = IsNationalPokedexEnabled(); data->unk_00.gameClear = FlagGet(FLAG_SYS_GAME_CLEAR); @@ -572,7 +701,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *gname, u8 *uname, u8 idx) if (lman.parent_child == MODE_PARENT) { retVal = TRUE; - if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1)) + if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[idx].serialNo) && ((gRfuLinkStatus->getNameFlag >> idx) & 1)) { memcpy(gname, &gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); memcpy(uname, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); @@ -586,7 +715,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *gname, u8 *uname, u8 idx) else { retVal = FALSE; - if (RfuSerialNumberIsValid(gRfuLinkStatus->partner[idx].serialNo)) + if (IsRfuSerialNumberValid(gRfuLinkStatus->partner[idx].serialNo)) { memcpy(gname, &gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); memcpy(uname, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); @@ -609,7 +738,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *gname, u8 *uname, u8 idx) bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *gname, u8 *uname, u8 idx) { bool8 retVal = FALSE; - if (gRfuLinkStatus->partner[idx].serialNo == 0x7F7D) + if (gRfuLinkStatus->partner[idx].serialNo == RFU_SERIAL_7F7D) { memcpy(gname, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); memcpy(uname, gRfuLinkStatus->partner[idx].uname, RFU_USER_NAME_LENGTH); @@ -629,37 +758,46 @@ void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *gname, u8 *uname memcpy(uname, gHostRFUtgtUnameBuffer, RFU_USER_NAME_LENGTH); } +#define sNextAnimNum data[0] +#define sSavedAnimNum data[1] +#define sCurrAnimNum data[2] +#define sFrameDelay data[3] +#define sFrameIdx data[4] +#define sTileStart data[6] +#define sValidator data[7] +#define STATUS_INDICATOR_ACTIVE 0x1234 // Used to validate active indicator + void CreateWirelessStatusIndicatorSprite(u8 x, u8 y) { u8 sprId; if (x == 0 && y == 0) { - x = 0xE7; - y = 0x08; + x = 231; + y = 8; } if (gRfuLinkStatus->parentChild == MODE_PARENT) { sprId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0); - gSprites[sprId].data[7] = 0x1234; - gSprites[sprId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); + gSprites[sprId].sValidator = STATUS_INDICATOR_ACTIVE; + gSprites[sprId].sTileStart = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); gSprites[sprId].invisible = TRUE; gWirelessStatusIndicatorSpriteId = sprId; } else { gWirelessStatusIndicatorSpriteId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0); - gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0x1234; - gSprites[gWirelessStatusIndicatorSpriteId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); + gSprites[gWirelessStatusIndicatorSpriteId].sValidator = STATUS_INDICATOR_ACTIVE; + gSprites[gWirelessStatusIndicatorSpriteId].sTileStart = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); gSprites[gWirelessStatusIndicatorSpriteId].invisible = TRUE; } } void DestroyWirelessStatusIndicatorSprite(void) { - if (gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234) + if (gSprites[gWirelessStatusIndicatorSpriteId].sValidator == STATUS_INDICATOR_ACTIVE) { - gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0; + gSprites[gWirelessStatusIndicatorSpriteId].sValidator = 0; DestroySprite(&gSprites[gWirelessStatusIndicatorSpriteId]); gMain.oamBuffer[125] = gDummyOamData; CpuCopy16(&gDummyOamData, (struct OamData *)OAM + 125, sizeof(struct OamData)); @@ -693,17 +831,17 @@ static u8 GetParentSignalStrength(void) static void SetAndRestartWirelessStatusIndicatorAnim(struct Sprite *sprite, s32 signalStrengthAnimNum) { - if (sprite->data[2] != signalStrengthAnimNum) + if (sprite->sCurrAnimNum != signalStrengthAnimNum) { - sprite->data[2] = signalStrengthAnimNum; - sprite->data[3] = 0; - sprite->data[4] = 0; + sprite->sCurrAnimNum = signalStrengthAnimNum; + sprite->sFrameDelay = 0; + sprite->sFrameIdx = 0; } } void UpdateWirelessStatusIndicatorSprite(void) { - if (gWirelessStatusIndicatorSpriteId != 0xFF && gSprites[gWirelessStatusIndicatorSpriteId].data[7] == 0x1234) + if (gWirelessStatusIndicatorSpriteId != 0xFF && gSprites[gWirelessStatusIndicatorSpriteId].sValidator == STATUS_INDICATOR_ACTIVE) { struct Sprite *sprite = &gSprites[gWirelessStatusIndicatorSpriteId]; u8 signalStrength = RFU_LINK_ICON_LEVEL4_MAX; @@ -722,57 +860,65 @@ void UpdateWirelessStatusIndicatorSprite(void) { signalStrength = GetParentSignalStrength(); } - if (sub_80FC1B0() == TRUE) + if (IsRfuRecoveringFromLinkLoss() == TRUE) { - sprite->data[0] = 4; + sprite->sNextAnimNum = 4; } else if (signalStrength <= RFU_LINK_ICON_LEVEL1_MAX) { - sprite->data[0] = 3; + sprite->sNextAnimNum = 3; } else if (signalStrength >= RFU_LINK_ICON_LEVEL2_MIN && signalStrength <= RFU_LINK_ICON_LEVEL2_MAX) { - sprite->data[0] = 2; + sprite->sNextAnimNum = 2; } else if (signalStrength >= RFU_LINK_ICON_LEVEL3_MIN && signalStrength <= RFU_LINK_ICON_LEVEL3_MAX) { - sprite->data[0] = 1; + sprite->sNextAnimNum = 1; } else if (signalStrength >= RFU_LINK_ICON_LEVEL4_MIN) { - sprite->data[0] = 0; + sprite->sNextAnimNum = 0; } - if (sprite->data[0] != sprite->data[1]) + if (sprite->sNextAnimNum != sprite->sSavedAnimNum) { - SetAndRestartWirelessStatusIndicatorAnim(sprite, sprite->data[0]); - sprite->data[1] = sprite->data[0]; + SetAndRestartWirelessStatusIndicatorAnim(sprite, sprite->sNextAnimNum); + sprite->sSavedAnimNum = sprite->sNextAnimNum; } - if (sprite->anims[sprite->data[2]][sprite->data[4]].frame.duration < sprite->data[3]) + if (sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].frame.duration < sprite->sFrameDelay) { - sprite->data[4]++; - sprite->data[3] = 0; - if (sprite->anims[sprite->data[2]][sprite->data[4]].type == -2) + sprite->sFrameIdx++; + sprite->sFrameDelay = 0; + if (sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].type == -2) // ANIMCMD_JUMP { - sprite->data[4] = 0; + sprite->sFrameIdx = 0; } } else { - sprite->data[3]++; + sprite->sFrameDelay++; } gMain.oamBuffer[125] = sWirelessStatusIndicatorOamData; gMain.oamBuffer[125].x = sprite->pos1.x + sprite->centerToCornerVecX; gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY; gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum; - gMain.oamBuffer[125].tileNum = sprite->data[6] + sprite->anims[sprite->data[2]][sprite->data[4]].frame.imageValue; + gMain.oamBuffer[125].tileNum = sprite->sTileStart + sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].frame.imageValue; CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData)); - if (RfuGetErrorStatus() == 1) + if (RfuGetStatus() == RFU_STATUS_FATAL_ERROR) { DestroyWirelessStatusIndicatorSprite(); } } } +#undef sNextAnimNum +#undef sSavedAnimNum +#undef sCurrAnimNum +#undef sFrameDelay +#undef sFrameIdx +#undef sTileStart +#undef sValidator + static void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name) { int i; diff --git a/src/mystery_gift_menu.c b/src/mystery_gift_menu.c index 2c455b57a..8290930d7 100644 --- a/src/mystery_gift_menu.c +++ b/src/mystery_gift_menu.c @@ -1270,7 +1270,7 @@ void task00_mystery_gift(u8 taskId) switch (mevent_client_do_exec(&data->curPromptWindowId)) { case 6: // done - Rfu_BeginBuildAndSendCommand5F(); + Rfu_SetCloseLinkCallback(); data->prevPromptWindowId = data->curPromptWindowId; data->state = 13; break; @@ -1633,7 +1633,7 @@ void task00_mystery_gift(u8 taskId) } break; case 33: - Rfu_BeginBuildAndSendCommand5F(); + Rfu_SetCloseLinkCallback(); StringCopy(gStringVar1, gLinkPlayers[1].name); data->state = 34; break; diff --git a/src/pokemon_jump_2.c b/src/pokemon_jump_2.c index 2fe066da1..a771b8fcc 100644 --- a/src/pokemon_jump_2.c +++ b/src/pokemon_jump_2.c @@ -1882,7 +1882,7 @@ static int sub_81497A8(void) static bool32 sub_8149804(void) { - return !Rfu.unk_124.count && !Rfu.sendQueue.count; + return !Rfu.recvQueue.count && !Rfu.sendQueue.count; } static int sub_8149834(u8 *arg0) diff --git a/src/union_room.c b/src/union_room.c index 876e11e19..575fcd60e 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -861,7 +861,9 @@ static void Task_TryBecomeLinkLeader(u8 taskId) } break; case 11: - switch (UnionRoomHandleYesNo(&data->textState, TrainerIdAndNameStillInPartnersList(ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), data->field_0->arr[data->playerCount].gname_uname.uname))) + switch (UnionRoomHandleYesNo(&data->textState, CheckTrainerHasLeftByIdAndName( + ReadAsU16(data->field_0->arr[data->playerCount].gname_uname.gname.unk_00.playerTrainerId), + data->field_0->arr[data->playerCount].gname_uname.uname))) { case 0: LoadWirelessStatusIndicatorSpriteGfx(); @@ -928,7 +930,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) else if (val == 2) { // Disconnect - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); data->state = 4; } break; @@ -1027,7 +1029,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) gSpecialVar_Result = 8; break; case 26: - if (RfuIsErrorStatus1or2()) + if (RfuHasErrored()) { data->state = 29; } @@ -1152,7 +1154,7 @@ static bool8 Leader_SetStateIfMemberListChanged(struct UnkStruct_Leader * data, data->state = state1; break; case UNION_ROOM_SPAWN_OUT: - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); RedrawListMenu(data->listTaskId); data->state = state2; return TRUE; @@ -1387,7 +1389,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) if (gReceivedRemoteLinkPlayers) { sPlayerCurrActivity = data->field_0->arr[data->leaderId].gname_uname.gname.activity; - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); switch (sPlayerCurrActivity) { case ACTIVITY_BATTLE: @@ -1407,7 +1409,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) } } - switch (RfuGetErrorStatus()) + switch (RfuGetStatus()) { case 1: data->state = 12; @@ -1421,7 +1423,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) GetGroupLeaderSentAnOKMessage(gStringVar4, sPlayerCurrActivity); if (PrintOnTextbox(&data->textState, gStringVar4)) { - RfuSetErrorStatus(7, 0); + RfuSetStatus(RFU_STATUS_WAIT_ACK_JOIN_GROUP, 0); StringCopy(gStringVar1, sUnionRoomActivityStringPtrs[sPlayerCurrActivity]); StringExpandPlaceholders(gStringVar4, gUnknown_8457700); } @@ -1432,7 +1434,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) { if (PrintOnTextbox(&data->textState, gStringVar4)) { - RfuSetErrorStatus(12, 0); + RfuSetStatus(RFU_STATUS_ACK_JOIN_GROUP, 0); data->delayBeforePrint = 0; } } @@ -1443,7 +1445,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; } - if (!RfuGetErrorStatus() && JOY_NEW(B_BUTTON)) + if (!RfuGetStatus() && JOY_NEW(B_BUTTON)) data->state = 7; break; case 7: @@ -1451,10 +1453,10 @@ static void Task_TryJoinLinkGroup(u8 taskId) data->state = 8; break; case 8: - switch (UnionRoomHandleYesNo(&data->textState, RfuGetErrorStatus())) + switch (UnionRoomHandleYesNo(&data->textState, RfuGetStatus())) { case 0: - LinkRfuNIsend8(); + SendLeaveGroupNotice(); data->state = 9; RedrawListMenu(data->listTaskId); break; @@ -1470,7 +1472,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) } break; case 9: - if (RfuGetErrorStatus()) + if (RfuGetStatus()) data->state = 6; break; case 10: @@ -1494,7 +1496,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; case 13: DestroyWirelessStatusIndicatorSprite(); - if (PrintOnTextbox(&data->textState, gUnknown_8457754[RfuGetErrorStatus()])) + if (PrintOnTextbox(&data->textState, gUnknown_8457754[RfuGetStatus()])) { gSpecialVar_Result = 6; data->state = 23; @@ -1507,7 +1509,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; case 15: DestroyWirelessStatusIndicatorSprite(); - if (PrintOnTextbox(&data->textState, gUnknown_8457754[RfuGetErrorStatus()])) + if (PrintOnTextbox(&data->textState, gUnknown_8457754[RfuGetStatus()])) { gSpecialVar_Result = 8; data->state = 23; @@ -2180,7 +2182,7 @@ static void Task_MEvent_Leader(u8 taskId) } else if (val == 2) { - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); data->state = 2; } break; @@ -2228,7 +2230,7 @@ static void Task_MEvent_Leader(u8 taskId) } break; case 15: - if (RfuGetErrorStatus() == 1 || RfuGetErrorStatus() == 2) + if (RfuGetStatus() == 1 || RfuGetStatus() == 2) { data->state = 13; } @@ -2370,7 +2372,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) data->state = 10; } - switch (RfuGetErrorStatus()) + switch (RfuGetStatus()) { case 1: case 2: @@ -2379,7 +2381,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) break; case 5: AddTextPrinterToWindow1(gUnknown_84576AC); - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); break; } break; @@ -2396,7 +2398,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) data->state++; break; case 9: - if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gUnknown_8457838[RfuGetErrorStatus()])) + if (MG_PrintTextOnWindow1AndWaitButton(&data->textState, gUnknown_8457838[RfuGetStatus()])) { DestroyWirelessStatusIndicatorSprite(); DestroyTask(taskId); @@ -2535,7 +2537,7 @@ static void Task_CardOrNewsOverWireless(u8 taskId) data->state = 12; } - switch (RfuGetErrorStatus()) + switch (RfuGetStatus()) { case 1: case 2: @@ -2544,7 +2546,7 @@ static void Task_CardOrNewsOverWireless(u8 taskId) break; case 5: AddTextPrinterToWindow1(gUnknown_845777C); - RfuSetErrorStatus(0, 0); + RfuSetStatus(RFU_STATUS_OK, 0); break; } break; @@ -2837,7 +2839,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case 25: UR_RunTextPrinters_CheckPrinter0Active(); - switch (RfuGetErrorStatus()) + switch (RfuGetStatus()) { case 4: HandleCancelTrade(TRUE); @@ -3032,7 +3034,7 @@ static void Task_RunUnionRoom(u8 taskId) } break; case 21: - switch (RfuGetErrorStatus()) + switch (RfuGetStatus()) { case 4: HandleCancelTrade(TRUE); @@ -3054,7 +3056,7 @@ static void Task_RunUnionRoom(u8 taskId) taskData[3]++; break; case 22: - if (RfuIsErrorStatus1or2()) + if (RfuHasErrored()) { playerGender = GetUnionRoomPlayerGender(taskData[1], data->field_0); UpdateGameDataWithActivitySpriteGendersFlag(ACTIVITY_PLYRTALK | IN_UNION_ROOM, 0, TRUE); @@ -3073,7 +3075,7 @@ static void Task_RunUnionRoom(u8 taskId) data->recvActivityRequest[0] = 0; break; case 12: - if (RfuIsErrorStatus1or2()) + if (RfuHasErrored()) { HandleCancelTrade(FALSE); data->state = 2; diff --git a/src/union_room_chat.c b/src/union_room_chat.c index 85df5cd39..524ce7e89 100644 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -324,7 +324,7 @@ static void ChatEntryRoutine_Join(void) sWork->routineState++; // fall through case 1: - if (IsLinkTaskFinished() && !GetRfuUnkCE8()) + if (IsLinkTaskFinished() && !RfuHasFoundNewLeader()) { if (SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) sWork->routineState++; @@ -527,14 +527,14 @@ static void ChatEntryRoutine_AskQuitChatting(void) sWork->routineState = 3; break; case 0: - sub_80FA4A8(); + Rfu_UnionRoomChat_StopLinkManager(); PrepareSendBuffer_Disband(sWork->sendMessageBuffer); sWork->routineState = 4; break; } break; case 4: - if (IsLinkTaskFinished() && !GetRfuUnkCE8() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) + if (IsLinkTaskFinished() && !RfuHasFoundNewLeader() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) { if (sWork->multiplayerId == 0) sWork->routineState = 6; @@ -577,15 +577,15 @@ static void ChatEntryRoutine_ExitChat(void) } break; case 3: - if (IsLinkTaskFinished() && !GetRfuUnkCE8() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) + if (IsLinkTaskFinished() && !RfuHasFoundNewLeader() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) sWork->routineState++; break; case 4: - if ((GetBlockReceivedStatus() & 1) && !GetRfuUnkCE8()) + if ((GetBlockReceivedStatus() & 1) && !RfuHasFoundNewLeader()) sWork->routineState++; break; case 5: - if (IsLinkTaskFinished() && !GetRfuUnkCE8()) + if (IsLinkTaskFinished() && !RfuHasFoundNewLeader()) { SetCloseLinkCallback(); sWork->exitDelayTimer = 0; @@ -620,7 +620,7 @@ static void ChatEntryRoutine_Drop(void) } break; case 1: - if (!RunDisplaySubtask(0) && IsLinkTaskFinished() && !GetRfuUnkCE8()) + if (!RunDisplaySubtask(0) && IsLinkTaskFinished() && !RfuHasFoundNewLeader()) { SetCloseLinkCallback(); sWork->exitDelayTimer = 0; @@ -666,7 +666,7 @@ static void ChatEntryRoutine_Disbanded(void) } break; case 2: - if (RunDisplaySubtask(0) != TRUE && IsLinkTaskFinished() && !GetRfuUnkCE8()) + if (RunDisplaySubtask(0) != TRUE && IsLinkTaskFinished() && !RfuHasFoundNewLeader()) { SetCloseLinkCallback(); sWork->exitDelayTimer = 0; @@ -704,7 +704,7 @@ static void ChatEntryRoutine_SendMessage(void) sWork->routineState++; // fall through case 1: - if (IsLinkTaskFinished() == TRUE && !GetRfuUnkCE8() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) + if (IsLinkTaskFinished() == TRUE && !RfuHasFoundNewLeader() && SendBlock(0, sWork->sendMessageBuffer, sizeof(sWork->sendMessageBuffer))) sWork->routineState++; break; case 2: @@ -1355,7 +1355,7 @@ static void Task_ReceiveChatMessage(u8 taskId) } tBlockReceivedStatus = GetBlockReceivedStatus(); - if (!tBlockReceivedStatus && GetRfuUnkCE8()) + if (!tBlockReceivedStatus && RfuHasFoundNewLeader()) return; tI = 0; @@ -1409,7 +1409,7 @@ static void Task_ReceiveChatMessage(u8 taskId) // You're the leader, and the person who left is not you if (GetLinkPlayerCount() == 2) { - sub_80FA4A8(); + Rfu_UnionRoomChat_StopLinkManager(); sWork->exitType = CHATEXIT_LEADER_LAST; DestroyTask(taskId); return; @@ -1433,7 +1433,7 @@ static void Task_ReceiveChatMessage(u8 taskId) DestroyTask(taskId); break; case 2: - if (!GetRfuUnkCE8()) + if (!RfuHasFoundNewLeader()) { if (sWork->multiplayerId == 0) sub_80FB030(sWork->linkPlayerCount); |