Start more link_rfu_2 documentation

This commit is contained in:
GriffinR 2021-07-11 20:42:05 -04:00
parent 01f2381e01
commit e01ae55c13
5 changed files with 144 additions and 124 deletions

View File

@ -41,8 +41,8 @@
#define RFU_STATUS_WAIT_ACK_JOIN_GROUP 7 #define RFU_STATUS_WAIT_ACK_JOIN_GROUP 7
#define RFU_STATUS_LEAVE_GROUP_NOTICE 8 #define RFU_STATUS_LEAVE_GROUP_NOTICE 8
#define RFU_STATUS_LEAVE_GROUP 9 #define RFU_STATUS_LEAVE_GROUP 9
#define RFU_STATUS_10 10 #define RFU_STATUS_CHILD_LEAVE_READY 10
#define RFU_STATUS_11 11 #define RFU_STATUS_CHILD_LEAVE 11
#define RFU_STATUS_ACK_JOIN_GROUP 12 #define RFU_STATUS_ACK_JOIN_GROUP 12
// RfuTgtData.gname is read as these structs. // RfuTgtData.gname is read as these structs.
@ -213,8 +213,8 @@ void Rfu_SetLinkStandbyCallback(void);
void ResetLinkRfuGFLayer(void); void ResetLinkRfuGFLayer(void);
void UpdateWirelessStatusIndicatorSprite(void); void UpdateWirelessStatusIndicatorSprite(void);
void InitRFU(void); void InitRFU(void);
bool32 sub_8010EC0(void); bool32 RfuMain1(void);
bool32 sub_8010F1C(void); bool32 RfuMain2(void);
bool32 RfuHasErrored(void); bool32 RfuHasErrored(void);
bool32 IsRfuRecvQueueEmpty(void); bool32 IsRfuRecvQueueEmpty(void);
u32 GetRfuRecvQueueLength(void); u32 GetRfuRecvQueueLength(void);
@ -229,9 +229,9 @@ u8 sub_801048C(bool32 a0);
void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2); void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2);
void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, bool32 started); void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, bool32 started);
void InitializeRfuLinkManager_LinkLeader(u32 a0); void InitializeRfuLinkManager_LinkLeader(u32 a0);
bool32 sub_8012240(void); bool32 IsRfuCommunicatingWithAllChildren(void);
void LinkRfu_StopManagerAndFinalizeSlots(void); void LinkRfu_StopManagerAndFinalizeSlots(void);
bool32 sub_80105EC(void); bool32 RfuTryDisconnectLeavingChildren(void);
bool32 HasTrainerLeftPartnersList(u16 trainerId, const u8 *name); bool32 HasTrainerLeftPartnersList(u16 trainerId, const u8 *name);
void SendRfuStatusToPartner(u8 status, u16 trainerId, const u8 *name); void SendRfuStatusToPartner(u8 status, u16 trainerId, const u8 *name);
u32 WaitSendRfuStatusToPartner(u16 trainerId, const u8 *name); u32 WaitSendRfuStatusToPartner(u16 trainerId, const u8 *name);

View File

@ -986,7 +986,7 @@ static const struct ListMenuItem sEmptyListMenuItems[] = {
static const struct ListMenuTemplate sUnknownListMenuTemplate = { static const struct ListMenuTemplate sUnknownListMenuTemplate = {
.items = sEmptyListMenuItems, .items = sEmptyListMenuItems,
.moveCursorFunc = ListMenuDefaultCursorMoveFunc, .moveCursorFunc = ListMenuDefaultCursorMoveFunc,
.itemPrintFunc = nullsub_14, .itemPrintFunc = ItemPrintFunc_EmptyList,
.totalItems = ARRAY_COUNT(sEmptyListMenuItems), .totalItems = ARRAY_COUNT(sEmptyListMenuItems),
.maxShowed = 4, .maxShowed = 4,
.windowId = 0, .windowId = 0,

View File

@ -485,21 +485,17 @@ u16 LinkMain2(const u16 *heldKeys)
u8 i; u8 i;
if (!sLinkOpen) if (!sLinkOpen)
{
return 0; return 0;
}
for (i = 0; i < CMD_LENGTH; i++) for (i = 0; i < CMD_LENGTH; i++)
{
gSendCmd[i] = 0; gSendCmd[i] = 0;
}
gLinkHeldKeys = *heldKeys; gLinkHeldKeys = *heldKeys;
if (gLinkStatus & LINK_STAT_CONN_ESTABLISHED) if (gLinkStatus & LINK_STAT_CONN_ESTABLISHED)
{ {
ProcessRecvCmds(SIO_MULTI_CNT->id); ProcessRecvCmds(SIO_MULTI_CNT->id);
if (gLinkCallback != NULL) if (gLinkCallback != NULL)
{
gLinkCallback(); gLinkCallback();
}
CheckErrorStatus(); CheckErrorStatus();
} }
return gLinkStatus; return gLinkStatus;
@ -1796,8 +1792,8 @@ bool8 HandleLinkConnection(void)
} }
else else
{ {
r4 = sub_8010EC0(); r4 = RfuMain1();
r5 = sub_8010F1C(); r5 = RfuMain2();
if (IsSendingKeysOverCable() == TRUE) if (IsSendingKeysOverCable() == TRUE)
{ {
if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5) if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5)
@ -1916,9 +1912,7 @@ u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENG
break; break;
case 1: case 1:
if (gLink.isMaster == LINK_MASTER && gLink.playerCount > 1) if (gLink.isMaster == LINK_MASTER && gLink.playerCount > 1)
{
gLink.handshakeAsMaster = TRUE; gLink.handshakeAsMaster = TRUE;
}
break; break;
case 2: case 2:
gLink.state = LINK_STATE_START0; gLink.state = LINK_STATE_START0;
@ -1974,20 +1968,14 @@ u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENG
} }
if (gLink.lag == LAG_MASTER) if (gLink.lag == LAG_MASTER)
{
retVal |= LINK_STAT_ERROR_LAG_MASTER; retVal |= LINK_STAT_ERROR_LAG_MASTER;
}
if (gLink.localId >= MAX_LINK_PLAYERS) if (gLink.localId >= MAX_LINK_PLAYERS)
{
retVal |= LINK_STAT_ERROR_INVALID_ID; retVal |= LINK_STAT_ERROR_INVALID_ID;
}
retVal2 = retVal; retVal2 = retVal;
if (gLink.lag == LAG_SLAVE) if (gLink.lag == LAG_SLAVE)
{
retVal2 |= LINK_STAT_ERROR_LAG_SLAVE; retVal2 |= LINK_STAT_ERROR_LAG_SLAVE;
}
return retVal2; return retVal2;
} }

View File

@ -18,6 +18,35 @@
#include "save.h" #include "save.h"
#include "mystery_gift.h" #include "mystery_gift.h"
enum {
RFUSTATE_INIT,
RFUSTATE_INIT_END,
RFUSTATE_PARENT_CONNECT,
RFUSTATE_PARENT_CONNECT_END,
RFUSTATE_STOP_MANAGER,
RFUSTATE_STOP_MANAGER_END,
RFUSTATE_CHILD_CONNECT,
RFUSTATE_CHILD_CONNECT_END,
RFUSTATE_8, // Unused
RFUSTATE_RECONNECTED,
RFUSTATE_10,
RFUSTATE_CHILD_TRY_JOIN,
RFUSTATE_CHILD_JOINED,
RFUSTATE_13,
RFUSTATE_14,
RFUSTATE_15,
RFUSTATE_UR_FINALIZE,
};
// These states are re-used for different purposes
#define RFUSTATE_17 17
#define RFUSTATE_18 18
#define RFUSTATE_PARENT_FINALIZE_START 17
#define RFUSTATE_PARENT_FINALIZE 18
#define RFUSTATE_UR_CONNECT 17
#define RFUSTATE_UR_CONNECT_END 18
#define RFUSTATE_20 20
struct SioInfo struct SioInfo
{ {
char magic[15]; // PokemonSioInfo char magic[15]; // PokemonSioInfo
@ -193,9 +222,9 @@ static const TaskFunc sUnknown_082ED7E0[] = {
static const char sASCII_PokemonSioInfo[] = "PokemonSioInfo"; static const char sASCII_PokemonSioInfo[] = "PokemonSioInfo";
static const char sASCII_LinkLossDisconnect[] = "LINK LOSS DISCONNECT!"; static const char sASCII_LinkLossDisconnect[] = "LINK LOSS DISCONNECT!";
static const char sASCII_LinkLossRecoveryNow[] = "LINK LOSS RECOVERY NOW"; static const char sASCII_LinkLossRecoveryNow[] = "LINK LOSS RECOVERY NOW";
ALIGNED(4) static const char sASCII_30Commas[31] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}; ALIGNED(4) static const char sASCII_30Spaces[31] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
static const char sASCII_15Commas[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}; static const char sASCII_15Spaces[16] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
static const char sASCII_8Commas[9] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'}; static const char sASCII_8Spaces[9] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'};
ALIGNED(4) static const char sASCII_Space[2] = {' ','\0'}; ALIGNED(4) static const char sASCII_Space[2] = {' ','\0'};
static const char sASCII_Asterisk[2] = {'*','\0'}; static const char sASCII_Asterisk[2] = {'*','\0'};
static const char sASCII_NowSlot[8] = "NOWSLOT"; static const char sASCII_NowSlot[8] = "NOWSLOT";
@ -277,32 +306,32 @@ static void Task_LinkLeaderSearchForChildren(u8 taskId)
UpdateChildStatuses(); UpdateChildStatuses();
switch (Rfu.state) switch (Rfu.state)
{ {
case 0: case RFUSTATE_INIT:
rfu_LMAN_initializeRFU(&sRfuReqConfig); rfu_LMAN_initializeRFU(&sRfuReqConfig);
Rfu.state = 1; Rfu.state = RFUSTATE_INIT_END;
gTasks[taskId].data[1] = 1; gTasks[taskId].data[1] = 1;
break; break;
case 1: case RFUSTATE_INIT_END:
break; break;
case 2: case RFUSTATE_PARENT_CONNECT:
rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos);
Rfu.state = 3; Rfu.state = RFUSTATE_PARENT_CONNECT_END;
gTasks[taskId].data[1] = 6; gTasks[taskId].data[1] = 6;
break; break;
case 3: case RFUSTATE_PARENT_CONNECT_END:
break; break;
case 4: case RFUSTATE_STOP_MANAGER:
rfu_LMAN_stopManager(FALSE); rfu_LMAN_stopManager(FALSE);
Rfu.state = 5; Rfu.state = RFUSTATE_STOP_MANAGER_END;
break; break;
case 5: case RFUSTATE_STOP_MANAGER_END:
break; break;
case 18: case RFUSTATE_PARENT_FINALIZE:
Rfu.unk_cdb = FALSE; Rfu.unk_cdb = FALSE;
rfu_LMAN_setMSCCallback(sub_800EDBC); rfu_LMAN_setMSCCallback(sub_800EDBC);
sub_800EAB4(); sub_800EAB4();
sub_800EAFC(); sub_800EAFC();
Rfu.state = 20; Rfu.state = RFUSTATE_20;
gTasks[taskId].data[1] = 8; gTasks[taskId].data[1] = 8;
CreateTask(sub_801084C, 5); CreateTask(sub_801084C, 5);
DestroyTask(taskId); DestroyTask(taskId);
@ -363,28 +392,28 @@ static void Task_JoinGroupSearchForParent(u8 taskId)
{ {
switch (Rfu.state) switch (Rfu.state)
{ {
case 0: case RFUSTATE_INIT:
rfu_LMAN_initializeRFU((INIT_PARAM *)&sRfuReqConfigTemplate); rfu_LMAN_initializeRFU((INIT_PARAM *)&sRfuReqConfigTemplate);
Rfu.state = 1; Rfu.state = RFUSTATE_INIT_END;
gTasks[taskId].data[1] = 1; gTasks[taskId].data[1] = 1;
break; break;
case 1: case RFUSTATE_INIT_END:
break; break;
case 6: case RFUSTATE_CHILD_CONNECT:
rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos); rfu_LMAN_establishConnection(Rfu.parentChild, 0, 240, (u16 *)sAcceptedSerialNos);
Rfu.state = 7; Rfu.state = RFUSTATE_CHILD_CONNECT_END;
gTasks[taskId].data[1] = 7; gTasks[taskId].data[1] = 7;
break; break;
case 7: case RFUSTATE_CHILD_CONNECT_END:
break; break;
case 9: case RFUSTATE_RECONNECTED:
gTasks[taskId].data[1] = 10; gTasks[taskId].data[1] = 10;
break; break;
case 11: case RFUSTATE_CHILD_TRY_JOIN:
switch (sub_80107A0()) switch (sub_80107A0())
{ {
case RFU_STATUS_JOIN_GROUP_OK: case RFU_STATUS_JOIN_GROUP_OK:
Rfu.state = 12; Rfu.state = RFUSTATE_CHILD_JOINED;
break; break;
case RFU_STATUS_JOIN_GROUP_NO: case RFU_STATUS_JOIN_GROUP_NO:
case RFU_STATUS_LEAVE_GROUP: case RFU_STATUS_LEAVE_GROUP:
@ -394,7 +423,7 @@ static void Task_JoinGroupSearchForParent(u8 taskId)
break; break;
} }
break; break;
case 12: case RFUSTATE_CHILD_JOINED:
{ {
u8 bmChildSlot = 1 << Rfu.childSlot; u8 bmChildSlot = 1 << Rfu.childSlot;
rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.childSlot); rfu_clearSlot(TYPE_NI_SEND | TYPE_NI_RECV, Rfu.childSlot);
@ -448,48 +477,44 @@ static void Task_LinkRfu_UnionRoomListen(u8 taskId)
} }
switch (Rfu.state) switch (Rfu.state)
{ {
case 0: case RFUSTATE_INIT:
rfu_LMAN_initializeRFU(&sRfuReqConfig); rfu_LMAN_initializeRFU(&sRfuReqConfig);
Rfu.state = 1; Rfu.state = RFUSTATE_INIT_END;
gTasks[taskId].data[1] = 1; gTasks[taskId].data[1] = 1;
break; break;
case 1: case RFUSTATE_INIT_END:
break; break;
case 17: case RFUSTATE_UR_CONNECT:
rfu_LMAN_establishConnection(2, 0, 240, (u16 *)sAcceptedSerialNos); rfu_LMAN_establishConnection(2, 0, 240, (u16 *)sAcceptedSerialNos);
rfu_LMAN_setMSCCallback(sub_800ED34); rfu_LMAN_setMSCCallback(sub_800ED34);
Rfu.state = 18; Rfu.state = RFUSTATE_UR_CONNECT_END;
break; break;
case 18: case RFUSTATE_UR_CONNECT_END:
break; break;
case 13: case RFUSTATE_13:
if (rfu_UNI_setSendData(1 << Rfu.childSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)) == 0) if (rfu_UNI_setSendData(1 << Rfu.childSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)) == 0)
{ {
Rfu.parentChild = MODE_CHILD; Rfu.parentChild = MODE_CHILD;
DestroyTask(taskId); DestroyTask(taskId);
if (gTasks[taskId].data[7]) if (gTasks[taskId].data[7])
{
CreateTask(sub_8010D0C, 1); CreateTask(sub_8010D0C, 1);
}
else else
{
CreateTask(sub_801084C, 5); CreateTask(sub_801084C, 5);
} }
}
break; break;
case 14: case RFUSTATE_14:
rfu_LMAN_stopManager(0); rfu_LMAN_stopManager(0);
Rfu.state = 15; Rfu.state = RFUSTATE_15;
break; break;
case 15: case RFUSTATE_15:
break; break;
case 16: case RFUSTATE_UR_FINALIZE:
Rfu.unk_cdb = FALSE; Rfu.unk_cdb = FALSE;
rfu_LMAN_setMSCCallback(sub_800EDBC); rfu_LMAN_setMSCCallback(sub_800EDBC);
UpdateGameData_GroupLockedIn(TRUE); UpdateGameData_GroupLockedIn(TRUE);
sub_800EAB4(); sub_800EAB4();
sub_800EAFC(); sub_800EAFC();
Rfu.state = 20; Rfu.state = RFUSTATE_20;
gTasks[taskId].data[1] = 8; gTasks[taskId].data[1] = 8;
Rfu.parentChild = MODE_PARENT; Rfu.parentChild = MODE_PARENT;
CreateTask(sub_801084C, 5); CreateTask(sub_801084C, 5);
@ -557,7 +582,7 @@ void LinkRfu_Shutdown(void)
ResetLinkRfuGFLayer(); ResetLinkRfuGFLayer();
} }
} }
else if (Rfu.parentChild == 2) else if (Rfu.parentChild == MODE_P_C_SWITCH)
{ {
if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) if (FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE)
{ {
@ -581,7 +606,7 @@ static void CreateTask_LinkLeaderSearchForChildren(void)
static bool8 sub_800EE94(void) static bool8 sub_800EE94(void)
{ {
if (Rfu.state == 7 && Rfu.parentId) if (Rfu.state == RFUSTATE_CHILD_CONNECT_END && Rfu.parentId)
{ {
return TRUE; return TRUE;
} }
@ -590,9 +615,9 @@ static bool8 sub_800EE94(void)
static bool32 IsParentSuccessfullyReconnected(void) static bool32 IsParentSuccessfullyReconnected(void)
{ {
if (Rfu.state == 7 && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240)) if (Rfu.state == RFUSTATE_CHILD_CONNECT_END && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[Rfu.unk_c3d].id, 240))
{ {
Rfu.state = 9; Rfu.state = RFUSTATE_RECONNECTED;
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -614,15 +639,15 @@ bool8 LmanAcceptSlotFlagIsNotZero(void)
void LinkRfu_StopManagerAndFinalizeSlots(void) void LinkRfu_StopManagerAndFinalizeSlots(void)
{ {
Rfu.state = 4; Rfu.state = RFUSTATE_STOP_MANAGER;
Rfu.acceptSlot_flag = lman.acceptSlot_flag; Rfu.acceptSlot_flag = lman.acceptSlot_flag;
} }
bool32 WaitRfuState(bool32 force) bool32 WaitRfuState(bool32 force)
{ {
if (Rfu.state == 17 || force) if (Rfu.state == RFUSTATE_PARENT_FINALIZE_START || force)
{ {
Rfu.state = 18; Rfu.state = RFUSTATE_PARENT_FINALIZE;
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -630,7 +655,7 @@ bool32 WaitRfuState(bool32 force)
void sub_800EF7C(void) void sub_800EF7C(void)
{ {
Rfu.state = 14; Rfu.state = RFUSTATE_14;
} }
static void sub_800EF88(u8 a0) static void sub_800EF88(u8 a0)
@ -720,7 +745,7 @@ bool32 IsRfuRecvQueueEmpty(void)
static bool32 sub_800F0F8(void) static bool32 sub_800F0F8(void)
{ {
if (Rfu.state < 20) if (Rfu.state < RFUSTATE_20)
{ {
rfu_REQ_recvData(); rfu_REQ_recvData();
rfu_waitREQComplete(); rfu_waitREQComplete();
@ -772,16 +797,14 @@ static bool32 sub_800F1E0(void)
u16 j; u16 j;
u8 retval; u8 retval;
if (Rfu.state >= 20 && Rfu.unk_0e == TRUE) if (Rfu.state >= RFUSTATE_20 && Rfu.unk_0e == TRUE)
{ {
rfu_waitREQComplete(); rfu_waitREQComplete();
while (Rfu.unk_cdb == FALSE) while (Rfu.unk_cdb == FALSE)
{ {
if (Rfu.errorState != 0) if (Rfu.errorState != 0)
{
return FALSE; return FALSE;
} }
}
rfu_REQ_recvData(); rfu_REQ_recvData();
rfu_waitREQComplete(); rfu_waitREQComplete();
if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2) if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2)
@ -885,10 +908,8 @@ static bool32 RfuProcessEnqueuedRecvBlock(void)
for (i = 0; i < MAX_RFU_PLAYERS; i++) for (i = 0; i < MAX_RFU_PLAYERS; i++)
{ {
for (j = 0; j < CMD_LENGTH - 1; j++) 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] = (sp00[i * 14 + (j << 1) + 1] << 8) | sp00[i * 14 + (j << 1) + 0];
} }
}
RfuHandleReceiveCommand(0); RfuHandleReceiveCommand(0);
if (lman.childClockSlave_flag == 0 && Rfu.unk_ce4) if (lman.childClockSlave_flag == 0 && Rfu.unk_ce4)
{ {
@ -1563,7 +1584,7 @@ static bool8 CheckForLeavingGroupMembers(void)
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE)
{ {
Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP;
Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; Rfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE_READY;
rfu_clearSlot(TYPE_NI_RECV, i); rfu_clearSlot(TYPE_NI_RECV, i);
rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1);
memberLeft = TRUE; memberLeft = TRUE;
@ -1580,27 +1601,33 @@ static bool8 CheckForLeavingGroupMembers(void)
return memberLeft; return memberLeft;
} }
bool32 sub_80105EC(void) bool32 RfuTryDisconnectLeavingChildren(void)
{ {
u8 flags = 0; u8 childrenLeaving = 0;
s32 i; s32 i;
// Check all children, get those waiting to be disconnected
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_11) if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE)
{ {
flags |= (1 << i); childrenLeaving |= (1 << i);
Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK; Rfu.partnerRecvStatuses[i] = RFU_STATUS_OK;
} }
} }
if (flags)
// Disconnect any leaving children
if (childrenLeaving)
{ {
rfu_REQ_disconnect(flags); rfu_REQ_disconnect(childrenLeaving);
rfu_waitREQComplete(); rfu_waitREQComplete();
} }
// Return true if any children have left or are still waiting to leave
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10 if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY
|| Rfu.partnerRecvStatuses[i] == RFU_STATUS_11) || Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE)
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -1651,8 +1678,8 @@ static void UpdateChildStatuses(void)
if (gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_SUCCESS if (gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_SUCCESS
|| gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_FAILED) || gRfuSlotStatusNI[i]->send.state == SLOT_STATE_SEND_FAILED)
{ {
if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_10) if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_CHILD_LEAVE_READY)
Rfu.partnerRecvStatuses[i] = RFU_STATUS_11; Rfu.partnerRecvStatuses[i] = RFU_STATUS_CHILD_LEAVE;
rfu_clearSlot(TYPE_NI_SEND, i); rfu_clearSlot(TYPE_NI_SEND, i);
} }
} }
@ -1939,7 +1966,8 @@ static void rfu_REQ_recvData_then_sendData(void)
} }
} }
bool32 sub_8010EC0(void) // Rfu equivalent of LinkMain1
bool32 RfuMain1(void)
{ {
bool32 retval = FALSE; bool32 retval = FALSE;
Rfu.parentId = 0; Rfu.parentId = 0;
@ -1954,7 +1982,7 @@ bool32 sub_8010EC0(void)
case MODE_CHILD: case MODE_CHILD:
retval = RfuProcessEnqueuedRecvBlock(); retval = RfuProcessEnqueuedRecvBlock();
break; break;
case 2: case MODE_P_C_SWITCH:
rfu_REQ_recvData_then_sendData(); rfu_REQ_recvData_then_sendData();
break; break;
} }
@ -1962,7 +1990,8 @@ bool32 sub_8010EC0(void)
return retval; return retval;
} }
bool32 sub_8010F1C(void) // Rfu equivalent of LinkMain2
bool32 RfuMain2(void)
{ {
bool32 retval = FALSE; bool32 retval = FALSE;
if (!Rfu.isShuttingDown) if (!Rfu.isShuttingDown)
@ -2101,7 +2130,7 @@ static void sub_801120C(u8 msg, u8 paramCount)
switch (msg) switch (msg)
{ {
case LMAN_MSG_INITIALIZE_COMPLETED: case LMAN_MSG_INITIALIZE_COMPLETED:
Rfu.state = 2; Rfu.state = RFUSTATE_PARENT_CONNECT;
break; break;
case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED:
break; break;
@ -2140,7 +2169,7 @@ static void sub_801120C(u8 msg, u8 paramCount)
rfu_REQ_disconnect(Rfu.acceptSlot_flag ^ lman.acceptSlot_flag); rfu_REQ_disconnect(Rfu.acceptSlot_flag ^ lman.acceptSlot_flag);
rfu_waitREQComplete(); rfu_waitREQComplete();
} }
Rfu.state = 17; Rfu.state = RFUSTATE_PARENT_FINALIZE_START;
break; break;
case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY: case LMAN_MSG_LINK_LOSS_DETECTED_AND_START_RECOVERY:
Rfu.linkLossRecoveryState = 1; Rfu.linkLossRecoveryState = 1;
@ -2161,8 +2190,7 @@ static void sub_801120C(u8 msg, u8 paramCount)
} }
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
break; break;
case 0x34: case 0x34: // ? Not a valid LMAN_MSG value
break;
case LMAN_MSG_RFU_POWER_DOWN: case LMAN_MSG_RFU_POWER_DOWN:
case LMAN_MSG_MANAGER_STOPPED: case LMAN_MSG_MANAGER_STOPPED:
case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET: case LMAN_MSG_MANAGER_FORCED_STOPPED_AND_RFU_RESET:
@ -2188,7 +2216,7 @@ void sub_8011404(u8 msg, u8 unused1)
switch (msg) switch (msg)
{ {
case LMAN_MSG_INITIALIZE_COMPLETED: case LMAN_MSG_INITIALIZE_COMPLETED:
Rfu.state = 6; Rfu.state = RFUSTATE_CHILD_CONNECT;
break; break;
case LMAN_MSG_PARENT_FOUND: case LMAN_MSG_PARENT_FOUND:
Rfu.parentId = lman.param[0]; Rfu.parentId = lman.param[0];
@ -2202,7 +2230,7 @@ void sub_8011404(u8 msg, u8 unused1)
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
break; break;
case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: case LMAN_MSG_CHILD_NAME_SEND_COMPLETED:
Rfu.state = 11; Rfu.state = RFUSTATE_CHILD_TRY_JOIN;
Rfu.unk_c85 = 0; Rfu.unk_c85 = 0;
Rfu.recvStatus = RFU_STATUS_OK; Rfu.recvStatus = RFU_STATUS_OK;
rfu_setRecvBuffer(TYPE_NI, Rfu.childSlot, &Rfu.recvStatus, 1); rfu_setRecvBuffer(TYPE_NI, Rfu.childSlot, &Rfu.recvStatus, 1);
@ -2293,7 +2321,7 @@ static void sub_8011674(u8 msg, u8 paramCount)
switch (msg) switch (msg)
{ {
case LMAN_MSG_INITIALIZE_COMPLETED: case LMAN_MSG_INITIALIZE_COMPLETED:
Rfu.state = 17; Rfu.state = RFUSTATE_17;
break; break;
case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED: case LMAN_MSG_NEW_CHILD_CONNECT_DETECTED:
RfuSetStatus(RFU_STATUS_NEW_CHILD_DETECTED, 0); RfuSetStatus(RFU_STATUS_NEW_CHILD_DETECTED, 0);
@ -2340,8 +2368,8 @@ static void sub_8011674(u8 msg, u8 paramCount)
rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1); rfu_REQ_disconnect(lman.acceptSlot_flag ^ r1);
rfu_waitREQComplete(); rfu_waitREQComplete();
} }
if (Rfu.state == 15) if (Rfu.state == RFUSTATE_15)
Rfu.state = 16; Rfu.state = RFUSTATE_UR_FINALIZE;
break; break;
break; break;
case LMAN_MSG_PARENT_FOUND: case LMAN_MSG_PARENT_FOUND:
@ -2353,7 +2381,7 @@ static void sub_8011674(u8 msg, u8 paramCount)
Rfu.childSlot = lman.param[0]; Rfu.childSlot = lman.param[0];
break; break;
case LMAN_MSG_CONNECT_PARENT_FAILED: case LMAN_MSG_CONNECT_PARENT_FAILED:
Rfu.state = 18; Rfu.state = RFUSTATE_18;
if (Rfu.unk_ccf < 2) if (Rfu.unk_ccf < 2)
{ {
Rfu.unk_ccf++; Rfu.unk_ccf++;
@ -2365,7 +2393,7 @@ static void sub_8011674(u8 msg, u8 paramCount)
} }
break; break;
case LMAN_MSG_CHILD_NAME_SEND_COMPLETED: case LMAN_MSG_CHILD_NAME_SEND_COMPLETED:
Rfu.state = 13; Rfu.state = RFUSTATE_13;
RfuSetStatus(RFU_STATUS_CHILD_SEND_COMPLETE, 0); RfuSetStatus(RFU_STATUS_CHILD_SEND_COMPLETE, 0);
rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70); rfu_setRecvBuffer(TYPE_UNI, Rfu.childSlot, Rfu.unk_c3f, 70);
break; break;
@ -2403,8 +2431,10 @@ static void sub_8011674(u8 msg, u8 paramCount)
rfu_LMAN_stopManager(0); rfu_LMAN_stopManager(0);
} }
if (gRfuLinkStatus->parentChild == MODE_NEUTRAL && lman.pcswitch_flag == 0 && FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE) if (gRfuLinkStatus->parentChild == MODE_NEUTRAL
Rfu.state = 17; && lman.pcswitch_flag == 0
&& FuncIsActiveTask(Task_LinkRfu_UnionRoomListen) == TRUE)
Rfu.state = RFUSTATE_17;
RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg); RfuSetStatus(RFU_STATUS_CONNECTION_ERROR, msg);
break; break;
@ -2557,7 +2587,7 @@ void InitializeRfuLinkManager_JoinGroup(void)
void InitializeRfuLinkManager_EnterUnionRoom(void) void InitializeRfuLinkManager_EnterUnionRoom(void)
{ {
Rfu.parentChild = 2; Rfu.parentChild = MODE_P_C_SWITCH;
CopyPlayerNameToUnameBuffer(); CopyPlayerNameToUnameBuffer();
rfu_LMAN_initializeManager(sub_8011674, NULL); rfu_LMAN_initializeManager(sub_8011674, NULL);
sRfuReqConfig = sRfuReqConfigTemplate; sRfuReqConfig = sRfuReqConfigTemplate;
@ -2765,7 +2795,7 @@ static void sub_801209C(u8 taskId)
{ {
if (gRfuLinkStatus->partner[id].slot != 0xFF && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[id].id, 0x5A)) if (gRfuLinkStatus->partner[id].slot != 0xFF && !rfu_LMAN_CHILD_connectParent(gRfuLinkStatus->partner[id].id, 0x5A))
{ {
Rfu.state = 0xA; Rfu.state = RFUSTATE_10;
DestroyTask(taskId); DestroyTask(taskId);
} }
} }
@ -2810,12 +2840,15 @@ bool8 IsRfuRecoveringFromLinkLoss(void)
return FALSE; return FALSE;
} }
bool32 sub_8012240(void) bool32 IsRfuCommunicatingWithAllChildren(void)
{ {
s32 i; s32 i;
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
// RFU_STATUS_OK is the default status.
// If any connected child is receiving a status other
// than OK, then the parent is communicating with them
if ((lman.acceptSlot_flag >> i) & 1 && Rfu.partnerSendStatuses[i] == RFU_STATUS_OK) if ((lman.acceptSlot_flag >> i) & 1 && Rfu.partnerSendStatuses[i] == RFU_STATUS_OK)
return FALSE; return FALSE;
} }
@ -2828,7 +2861,7 @@ static void Debug_PrintEmpty(void)
s32 i; s32 i;
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
Debug_PrintString(sASCII_30Commas, 0, i); Debug_PrintString(sASCII_30Spaces, 0, i);
} }
static void Debug_PrintStatus(void) static void Debug_PrintStatus(void)
@ -2863,8 +2896,8 @@ static void Debug_PrintStatus(void)
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
Debug_PrintNum(0, 1, i + 3, 4); Debug_PrintNum(0, 1, i + 3, 4);
Debug_PrintString(sASCII_15Commas, 6, i + 3); Debug_PrintString(sASCII_15Spaces, 6, i + 3);
Debug_PrintString(sASCII_8Commas, 0x16, i + 3); Debug_PrintString(sASCII_8Spaces, 0x16, i + 3);
} }
Debug_PrintNum(gRfuLinkStatus->partner[Rfu.childSlot].serialNo, 1, 3, 4); Debug_PrintNum(gRfuLinkStatus->partner[Rfu.childSlot].serialNo, 1, 3, 4);
Debug_PrintString((void*)gRfuLinkStatus->partner[Rfu.childSlot].gname, 6, 3); Debug_PrintString((void*)gRfuLinkStatus->partner[Rfu.childSlot].gname, 6, 3);
@ -2884,8 +2917,8 @@ static void Debug_PrintStatus(void)
for (; i < RFU_CHILD_MAX; i++) for (; i < RFU_CHILD_MAX; i++)
{ {
Debug_PrintNum(0, 1, i + 3, 4); Debug_PrintNum(0, 1, i + 3, 4);
Debug_PrintString(sASCII_15Commas, 6, i + 3); Debug_PrintString(sASCII_15Spaces, 6, i + 3);
Debug_PrintString(sASCII_8Commas, 0x16, i + 3); Debug_PrintString(sASCII_8Spaces, 0x16, i + 3);
} }
} }
} }

View File

@ -129,7 +129,7 @@ enum {
LL_STATE_PRINT_AWAITING_PLAYERS, LL_STATE_PRINT_AWAITING_PLAYERS,
LL_STATE_AWAIT_PLAYERS, LL_STATE_AWAIT_PLAYERS,
LL_STATE_ACCEPT_NEW_MEMBER_PROMPT, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT,
LL_STATE_9 = 9, LL_STATE_WAIT_DISCONNECT_CHILD = 9,
LL_STATE_MEMBER_LEFT, LL_STATE_MEMBER_LEFT,
LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT_HANDLE_INPUT,
LL_STATE_UPDATE_AFTER_JOIN_REQUEST, LL_STATE_UPDATE_AFTER_JOIN_REQUEST,
@ -184,12 +184,10 @@ EWRAM_DATA u16 gUnionRoomOfferedSpecies = 0;
EWRAM_DATA u8 gUnionRoomRequestedMonType = 0; EWRAM_DATA u8 gUnionRoomRequestedMonType = 0;
static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {}; static EWRAM_DATA struct UnionRoomTrade sUnionRoomTrade = {};
// IWRAM vars
static struct WirelessLink_Leader *sLeader; static struct WirelessLink_Leader *sLeader;
static struct WirelessLink_Group *sGroup; static struct WirelessLink_Group *sGroup;
static struct WirelessLink_URoom *sURoom; static struct WirelessLink_URoom *sURoom;
// this file's functions
static void UR_AddTextPrinterParameterized(u8, u8, const u8 *, u8, u8, u8); static void UR_AddTextPrinterParameterized(u8, u8, const u8 *, u8, u8, u8);
static u16 ReadAsU16(const u8 *); static u16 ReadAsU16(const u8 *);
static void Task_TryBecomeLinkLeader(u8); static void Task_TryBecomeLinkLeader(u8);
@ -256,11 +254,10 @@ static bool8 AreGnameUnameDifferent(struct WirelessGnameUnamePair*, const struct
static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y); static void ItemPrintFunc_PossibleGroupMembers(u8 windowId, u32 id, u8 y);
static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, u32 id, u8 y); static void ListMenuItemPrintFunc_UnionRoomGroups(u8 windowId, u32 id, u8 y);
static void TradeBoardListMenuItemPrintFunc(u8 windowId, u32 id, u8 y); static void TradeBoardListMenuItemPrintFunc(u8 windowId, u32 id, u8 y);
static void nullsub_14(u8 windowId, u32 id, u8 y); static void ItemPrintFunc_EmptyList(u8 windowId, u32 id, u8 y);
#include "data/union_room.h" #include "data/union_room.h"
// code
static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 stringId) static void PrintNumPlayersWaitingForMsg(u8 windowId, u8 capacityCode, u8 stringId)
{ {
FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
@ -461,19 +458,21 @@ static void Task_TryBecomeLinkLeader(u8 taskId)
if (GROUP_MIN(sPlayerActivityGroupSize) != 0 if (GROUP_MIN(sPlayerActivityGroupSize) != 0
&& data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1 && data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1
&& GROUP_MAX(sPlayerActivityGroupSize) != 0 && GROUP_MAX(sPlayerActivityGroupSize) != 0
&& sub_8012240() && IsRfuCommunicatingWithAllChildren()
&& JOY_NEW(START_BUTTON)) && JOY_NEW(START_BUTTON))
{ {
data->state = LL_STATE_MEMBERS_OK_PROMPT; data->state = LL_STATE_MEMBERS_OK_PROMPT;
LinkRfu_StopManagerAndFinalizeSlots(); LinkRfu_StopManagerAndFinalizeSlots();
} }
if (data->state == LL_STATE_AWAIT_PLAYERS && sub_80105EC()) if (data->state == LL_STATE_AWAIT_PLAYERS && RfuTryDisconnectLeavingChildren())
{ {
data->state = LL_STATE_9; // At least 1 group member has left or is trying to leave
data->state = LL_STATE_WAIT_DISCONNECT_CHILD;
} }
break; break;
case LL_STATE_9: case LL_STATE_WAIT_DISCONNECT_CHILD:
if (!sub_80105EC()) // Resume after ensuring all members trying to leave have left
if (!RfuTryDisconnectLeavingChildren())
{ {
data->state = LL_STATE_AWAIT_PLAYERS; data->state = LL_STATE_AWAIT_PLAYERS;
data->playerCount = sub_8013398(data->field_0); data->playerCount = sub_8013398(data->field_0);
@ -525,7 +524,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId)
data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST; data->state = LL_STATE_UPDATE_AFTER_JOIN_REQUEST;
break; break;
case -3: case -3:
data->state = LL_STATE_9; data->state = LL_STATE_WAIT_DISCONNECT_CHILD;
break; break;
} }
break; break;
@ -4074,7 +4073,7 @@ static s32 UnionRoomGetPlayerInteractionResponse(struct UnkStruct_Main0 *main0,
} }
} }
void nullsub_14(u8 windowId, u32 itemId, u8 y) void ItemPrintFunc_EmptyList(u8 windowId, u32 itemId, u8 y)
{ {
} }