From e01ae55c13f9717f6b0f781846d9ceaeeb2a250d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 11 Jul 2021 20:42:05 -0400 Subject: Start more link_rfu_2 documentation --- src/link.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'src/link.c') diff --git a/src/link.c b/src/link.c index 8a04b53e5..c32ee07d2 100644 --- a/src/link.c +++ b/src/link.c @@ -485,21 +485,17 @@ u16 LinkMain2(const u16 *heldKeys) u8 i; if (!sLinkOpen) - { return 0; - } + for (i = 0; i < CMD_LENGTH; i++) - { gSendCmd[i] = 0; - } + gLinkHeldKeys = *heldKeys; if (gLinkStatus & LINK_STAT_CONN_ESTABLISHED) { ProcessRecvCmds(SIO_MULTI_CNT->id); if (gLinkCallback != NULL) - { gLinkCallback(); - } CheckErrorStatus(); } return gLinkStatus; @@ -1796,8 +1792,8 @@ bool8 HandleLinkConnection(void) } else { - r4 = sub_8010EC0(); - r5 = sub_8010F1C(); + r4 = RfuMain1(); + r5 = RfuMain2(); if (IsSendingKeysOverCable() == TRUE) { if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5) @@ -1916,9 +1912,7 @@ u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENG break; case 1: if (gLink.isMaster == LINK_MASTER && gLink.playerCount > 1) - { gLink.handshakeAsMaster = TRUE; - } break; case 2: gLink.state = LINK_STATE_START0; @@ -1974,20 +1968,14 @@ u32 LinkMain1(u8 *shouldAdvanceLinkState, u16 *sendCmd, u16 (*recvCmds)[CMD_LENG } if (gLink.lag == LAG_MASTER) - { retVal |= LINK_STAT_ERROR_LAG_MASTER; - } if (gLink.localId >= MAX_LINK_PLAYERS) - { retVal |= LINK_STAT_ERROR_INVALID_ID; - } retVal2 = retVal; if (gLink.lag == LAG_SLAVE) - { retVal2 |= LINK_STAT_ERROR_LAG_SLAVE; - } return retVal2; } -- cgit v1.2.3 From dfdcfc1568ad8d3c4efbe36f06c1b883b677abd2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 15 Aug 2021 16:11:30 -0400 Subject: Document remaining functions in cable_club --- src/link.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/link.c') diff --git a/src/link.c b/src/link.c index c32ee07d2..39f6568de 100644 --- a/src/link.c +++ b/src/link.c @@ -166,11 +166,11 @@ static const u16 sLinkTestDigitsGfx[] = INCBIN_U16("graphics/interface/link_test static const u8 sUnusedTransparentWhite[] = _("{HIGHLIGHT TRANSPARENT}{COLOR WHITE}"); static const u16 sCommErrorBg_Gfx[] = INCBIN_U16("graphics/interface/comm_error_bg.4bpp"); static const struct BlockRequest sBlockRequests[] = { - {gBlockSendBuffer, 200}, - {gBlockSendBuffer, 200}, - {gBlockSendBuffer, 100}, - {gBlockSendBuffer, 220}, - {gBlockSendBuffer, 40} + [BLOCK_REQ_SIZE_NONE] = {gBlockSendBuffer, 200}, + [BLOCK_REQ_SIZE_200] = {gBlockSendBuffer, 200}, + [BLOCK_REQ_SIZE_100] = {gBlockSendBuffer, 100}, + [BLOCK_REQ_SIZE_220] = {gBlockSendBuffer, 220}, + [BLOCK_REQ_SIZE_40] = {gBlockSendBuffer, 40} }; static const u8 sBGControlRegs[] = { REG_OFFSET_BG0CNT, @@ -1025,7 +1025,7 @@ u8 GetMultiplayerId(void) return SIO_MULTI_CNT->id; } -u8 bitmask_all_link_players_but_self(void) +u8 BitmaskAllOtherLinkPlayers(void) { u8 mpId; @@ -1727,12 +1727,12 @@ static void CB2_PrintErrorMessage(void) bool8 GetSioMultiSI(void) { - return (REG_SIOCNT & 0x04) != 0; + return (REG_SIOCNT & SIO_MULTI_SI) != 0; } static bool8 IsSioMultiMaster(void) { - return (REG_SIOCNT & 0x8) && !(REG_SIOCNT & 0x04); + return (REG_SIOCNT & SIO_MULTI_SD) && (REG_SIOCNT & SIO_MULTI_SI) == 0; } bool8 IsLinkConnectionEstablished(void) -- cgit v1.2.3 From 4efa6c882a68d69e32f59580faa438a6b1fd0b68 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 15 Aug 2021 18:26:09 -0400 Subject: Continue misc link documentation, rename reset_save_heap --- src/link.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/link.c') diff --git a/src/link.c b/src/link.c index 39f6568de..6e9d01559 100644 --- a/src/link.c +++ b/src/link.c @@ -1,7 +1,7 @@ #include "global.h" #include "m4a.h" #include "malloc.h" -#include "reset_save_heap.h" +#include "reload_save.h" #include "save.h" #include "bg.h" #include "window.h" @@ -1705,7 +1705,7 @@ static void CB2_PrintErrorMessage(void) PlaySE(SE_PIN); gWirelessCommType = 0; sLinkErrorBuffer.disconnected = FALSE; - sub_81700F8(); + ReloadSave(); } } else if (gWirelessCommType == 2) -- cgit v1.2.3 From 846942ce48d650efd3d837493157ce462e568d78 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 7 Oct 2021 14:55:15 -0400 Subject: Finish remaining symbols in link_rfu_2 --- src/link.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/link.c') diff --git a/src/link.c b/src/link.c index 6e9d01559..1f06eef66 100644 --- a/src/link.c +++ b/src/link.c @@ -108,7 +108,7 @@ static EWRAM_DATA u16 sTimeOutCounter = 0; EWRAM_DATA struct LinkPlayer gLocalLinkPlayer = {}; EWRAM_DATA struct LinkPlayer gLinkPlayers[MAX_RFU_PLAYERS] = {}; static EWRAM_DATA struct LinkPlayer sSavedLinkPlayers[MAX_RFU_PLAYERS] = {}; -EWRAM_DATA struct { +static EWRAM_DATA struct { u32 status; u8 lastRecvQueueCount; u8 lastSendQueueCount; @@ -140,7 +140,7 @@ static void LinkCB_WaitCloseLinkWithJP(void); static void LinkCB_Standby(void); static void LinkCB_StandbyForAll(void); -static void CheckErrorStatus(void); +static void TrySetLinkErrorBuffer(void); static void CB2_PrintErrorMessage(void); static bool8 IsSioMultiMaster(void); static void SetWirelessCommType0_Internal(void); @@ -394,9 +394,7 @@ void CloseLink(void) { gReceivedRemoteLinkPlayers = FALSE; if (gWirelessCommType) - { LinkRfu_Shutdown(); - } sLinkOpen = FALSE; DisableSerial(); } @@ -496,7 +494,7 @@ u16 LinkMain2(const u16 *heldKeys) ProcessRecvCmds(SIO_MULTI_CNT->id); if (gLinkCallback != NULL) gLinkCallback(); - CheckErrorStatus(); + TrySetLinkErrorBuffer(); } return gLinkStatus; } @@ -1559,10 +1557,13 @@ static void LinkCB_StandbyForAll(void) } } -static void CheckErrorStatus(void) +static void TrySetLinkErrorBuffer(void) { + // Check if a link error has occurred if (sLinkOpen && EXTRACT_LINK_ERRORS(gLinkStatus)) { + // Link error has occurred, handle message details if + // necessary, then stop the link. if (!gSuppressLinkErrorMessage) { sLinkErrorBuffer.status = gLinkStatus; @@ -1575,7 +1576,7 @@ static void CheckErrorStatus(void) } } -void BufferLinkErrorInfo(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, bool8 disconnected) +void SetLinkErrorBuffer(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, bool8 disconnected) { sLinkErrorBuffer.status = status; sLinkErrorBuffer.lastSendQueueCount = lastSendQueueCount; @@ -1778,10 +1779,10 @@ void LinkPlayerFromBlock(u32 who) SetMainCallback2(CB2_LinkError); } +// When this function returns TRUE the callbacks are skipped bool8 HandleLinkConnection(void) { - bool32 r4; - bool32 r5; + bool32 main1Failed, main2Failed; if (gWirelessCommType == 0) { @@ -1792,11 +1793,13 @@ bool8 HandleLinkConnection(void) } else { - r4 = RfuMain1(); - r5 = RfuMain2(); + main1Failed = RfuMain1(); // Always returns FALSE + main2Failed = RfuMain2(); if (IsSendingKeysOverCable() == TRUE) { - if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5) + // This will never be reached. + // IsSendingKeysOverCable is always FALSE for wireless communication + if (main1Failed == TRUE || IsRfuRecvQueueEmpty() || main2Failed) return TRUE; } } -- cgit v1.2.3