Some link rfu cleanup / link.c documentation

This commit is contained in:
GriffinR 2020-06-08 00:45:06 -04:00
parent c98342c973
commit 35867f531b
15 changed files with 354 additions and 376 deletions

View File

@ -3,15 +3,15 @@ gLinkDebugSeed
gLocalLinkPlayerBlock gLocalLinkPlayerBlock
gLinkErrorOccurred gLinkErrorOccurred
gLinkDebugFlags gLinkDebugFlags
gFiller_03003074 gLinkFiller1
gRemoteLinkPlayersNotReceived gRemoteLinkPlayersNotReceived
gBlockReceivedStatus gBlockReceivedStatus
gFiller_03003080 gLinkFiller2
gLinkHeldKeys gLinkHeldKeys
gRecvCmds gRecvCmds
gLinkStatus gLinkStatus
gUnknown_030030E4 gLinkDummy1
gUnknown_030030E8 gLinkDummy2
gUnknown_030030EC gUnknown_030030EC
gUnknown_030030F0 gUnknown_030030F0
gUnknown_030030F4 gUnknown_030030F4
@ -26,12 +26,12 @@ gLinkCallback
gShouldAdvanceLinkState gShouldAdvanceLinkState
gLinkTestBlockChecksums gLinkTestBlockChecksums
gBlockRequestType gBlockRequestType
gFiller_03003154 gLinkFiller3
gFiller_03003158 gLinkFiller4
gFiller_0300315c gLinkFiller5
gLastSendQueueCount gLastSendQueueCount
gLink gLink
gLastRecvQueueCount gLastRecvQueueCount
gLinkSavedIme gLinkSavedIme
gFiller_03004138 gLinkFiller6
gFiller_0300413C gLinkFiller7

View File

@ -27,6 +27,9 @@ typedef double f64;
typedef u8 bool8; typedef u8 bool8;
typedef u16 bool16; typedef u16 bool16;
typedef u32 bool32; typedef u32 bool32;
typedef vu8 vbool8;
typedef vu16 vbool16;
typedef vu32 vbool32;
struct BgCnt struct BgCnt
{ {

View File

@ -284,13 +284,13 @@ void sub_800A418(void);
void SetSuppressLinkErrorMessage(bool8 flag); void SetSuppressLinkErrorMessage(bool8 flag);
void sub_800B524(struct LinkPlayer *linkPlayer); void sub_800B524(struct LinkPlayer *linkPlayer);
u8 GetSioMultiSI(void); u8 GetSioMultiSI(void);
void sub_800AAF4(void); void ClearSavedLinkPlayers(void);
void sub_800AF18(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06); void BufferLinkErrorInfo(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06);
void sub_800B348(void); void sub_800B348(void);
void LinkPlayerFromBlock(u32 who); void LinkPlayerFromBlock(u32 who);
bool32 sub_800A07C(void); bool32 Link_AnyPartnersPlayingFRLG_JP(void);
void ResetLinkPlayerCount(void); void ResetLinkPlayerCount(void);
void sub_800AA04(u8 a0); void SaveLinkPlayers(u8 a0);
void SetWirelessCommType0(void); void SetWirelessCommType0(void);
bool32 sub_800B504(void); bool32 sub_800B504(void);
@ -330,18 +330,18 @@ extern u32 gFiller_03003080;
extern struct LinkPlayer gLocalLinkPlayer; extern struct LinkPlayer gLocalLinkPlayer;
bool32 Link_AnyPartnersPlayingRubyOrSapphire(void); bool32 Link_AnyPartnersPlayingRubyOrSapphire(void);
bool32 sub_800A03C(void); bool32 LinkDummy_Return2(void);
void SetLocalLinkPlayerId(u8); void SetLocalLinkPlayerId(u8);
u8 GetSavedPlayerCount(void); u8 GetSavedPlayerCount(void);
void sub_8009FAC(void); void sub_8009FAC(void);
bool8 sub_800A4D8(u8 a0); bool8 sub_800A4D8(u8 a0);
u8 sub_800A9D8(void); u8 GetLinkPlayerCountAsBitFlags(void);
u8 sub_800A0C8(s32, s32); u8 sub_800A0C8(s32, s32);
u8 sub_800A9A8(void); u8 GetSavedLinkPlayerCountAsBitFlags(void);
void sub_800AD10(void); void sub_800AD10(void);
void sub_800AB18(void); void CheckLinkPlayersMatchSaved(void);
void sub_8009F18(void); void StartSendingKeysToLink(void);
bool8 sub_800AA60(void); bool8 DoesLinkPlayerCountMatchSaved(void);
void sub_800ABF4(u16 a0); void sub_800ABF4(u16 a0);
bool32 IsSendingKeysToLink(void); bool32 IsSendingKeysToLink(void);
u32 GetLinkRecvQueueLength(void); u32 GetLinkRecvQueueLength(void);

View File

@ -18,6 +18,17 @@
#define RFU_COMMAND_0xEE00 0xEE00 #define RFU_COMMAND_0xEE00 0xEE00
#define RFU_COMMAND_0xED00 0xED00 #define RFU_COMMAND_0xED00 0xED00
#define RFU_SERIAL_7F7D 0x7F7D
#define RECV_QUEUE_NUM_SLOTS 32
#define RECV_QUEUE_SLOT_LENGTH (14 * MAX_RFU_PLAYERS)
#define SEND_QUEUE_NUM_SLOTS 40
#define SEND_QUEUE_SLOT_LENGTH 14
#define BACKUP_QUEUE_NUM_SLOTS 2
#define BACKUP_QUEUE_SLOT_LENGTH 14
// RfuTgtData.gname is read as these structs. // RfuTgtData.gname is read as these structs.
struct GFtgtGnameSub struct GFtgtGnameSub
{ {
@ -48,35 +59,6 @@ struct __attribute__((packed, aligned(2))) GFtgtGname
u8 padding; u8 padding;
}; // size: RFU_GNAME_SIZE }; // size: RFU_GNAME_SIZE
struct UnkLinkRfuStruct_02022B2C
{
u8 unk_00;
u8 unk_01;
u16 unk_02;
u8 unk_04;
u16 unk_06;
struct GFtgtGname *unk_08;
u8 *unk_0c;
u8 unk_10;
u8 unk_11;
u16 unk_12;
u16 unk_14;
};
struct UnkLinkRfuStruct_02022B44
{
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];
};
struct RfuBlockSend struct RfuBlockSend
{ {
/* 0x00 */ u16 next; /* 0x00 */ u16 next;
@ -91,7 +73,7 @@ struct RfuBlockSend
struct RfuRecvQueue struct RfuRecvQueue
{ {
/* 0x000 */ u8 slots[32][70]; /* 0x000 */ u8 slots[RECV_QUEUE_NUM_SLOTS][RECV_QUEUE_SLOT_LENGTH];
/* 0x8c0 */ vu8 recvSlot; /* 0x8c0 */ vu8 recvSlot;
/* 0x8c1 */ vu8 sendSlot; /* 0x8c1 */ vu8 sendSlot;
/* 0x8c2 */ vu8 count; /* 0x8c2 */ vu8 count;
@ -100,7 +82,7 @@ struct RfuRecvQueue
struct RfuSendQueue struct RfuSendQueue
{ {
/* 0x000 */ u8 slots[40][14]; /* 0x000 */ u8 slots[SEND_QUEUE_NUM_SLOTS][SEND_QUEUE_SLOT_LENGTH];
/* 0x230 */ vu8 recvSlot; /* 0x230 */ vu8 recvSlot;
/* 0x231 */ vu8 sendSlot; /* 0x231 */ vu8 sendSlot;
/* 0x232 */ vu8 count; /* 0x232 */ vu8 count;
@ -109,7 +91,7 @@ struct RfuSendQueue
struct RfuBackupQueue struct RfuBackupQueue
{ {
/* 0x00 */ u8 slots[2][14]; /* 0x00 */ u8 slots[BACKUP_QUEUE_NUM_SLOTS][BACKUP_QUEUE_SLOT_LENGTH];
/* 0x1c */ vu8 recvSlot; /* 0x1c */ vu8 recvSlot;
/* 0x1d */ vu8 sendSlot; /* 0x1d */ vu8 sendSlot;
/* 0x1e */ vu8 count; /* 0x1e */ vu8 count;
@ -123,11 +105,11 @@ struct GFRfuManager
/* 0x00a */ u16 linkmanMsg; /* 0x00a */ u16 linkmanMsg;
/* 0x00c */ u8 parentChild; /* 0x00c */ u8 parentChild;
/* 0x00d */ u8 playerCount; /* 0x00d */ u8 playerCount;
/* 0x00e */ u8 unk_0e; /* 0x00e */ bool8 unk_0e;
/* 0x00f */ u8 unk_0f; /* 0x00f */ u8 unk_0f;
/* 0x010 */ u16 unk_10; /* 0x010 */ u16 unk_10;
/* 0x012 */ u16 unk_12; /* 0x012 */ u16 unk_12;
/* 0x014 */ u8 unk_14[4][14]; /* 0x014 */ u8 unk_14[RFU_CHILD_MAX][14];
/* 0x04c */ u8 unk_4c[14]; /* 0x04c */ u8 unk_4c[14];
/* 0x05a */ u8 unk_5a; /* 0x05a */ u8 unk_5a;
/* 0x05b */ u8 unk_5b; /* 0x05b */ u8 unk_5b;
@ -136,8 +118,8 @@ struct GFRfuManager
/* 0x066 */ u8 idleTaskId; /* 0x066 */ u8 idleTaskId;
/* 0x067 */ u8 searchTaskId; /* 0x067 */ u8 searchTaskId;
/* 0x068 */ u8 filler_68[4]; /* 0x068 */ u8 filler_68[4];
/* 0x06c */ struct RfuBlockSend unk_6c; /* 0x06c */ struct RfuBlockSend sendBlock;
/* 0x080 */ struct RfuBlockSend unk_80[MAX_RFU_PLAYERS]; /* 0x080 */ struct RfuBlockSend recvBlock[MAX_RFU_PLAYERS];
/* 0x0e4 */ u8 unk_e4[5]; /* 0x0e4 */ u8 unk_e4[5];
/* 0x0e9 */ u8 unk_e9[5]; /* 0x0e9 */ u8 unk_e9[5];
/* 0x0ee */ vu8 errorState; /* 0x0ee */ vu8 errorState;
@ -170,8 +152,8 @@ struct GFRfuManager
/* 0xcd5 */ u8 unk_cd5[4]; /* 0xcd5 */ u8 unk_cd5[4];
/* 0xcd9 */ u8 unk_cd9; /* 0xcd9 */ u8 unk_cd9;
/* 0xcda */ u8 unk_cda; /* 0xcda */ u8 unk_cda;
/* 0xcdb */ vu8 unk_cdb; /* 0xcdb */ vbool8 unk_cdb;
/* 0xcdc */ vu8 unk_cdc; /* 0xcdc */ vbool8 unk_cdc;
/* 0xcdd */ u8 unk_cdd; /* 0xcdd */ u8 unk_cdd;
/* 0xcde */ u8 linkPlayerIdx[RFU_CHILD_MAX]; /* 0xcde */ u8 linkPlayerIdx[RFU_CHILD_MAX];
/* 0xce2 */ u8 unk_ce2; /* 0xce2 */ u8 unk_ce2;
@ -195,7 +177,7 @@ extern u8 gWirelessStatusIndicatorSpriteId;
// Exported ROM declarations // Exported ROM declarations
void WipeTrainerNameRecords(void); void WipeTrainerNameRecords(void);
void sub_800E700(void); void InitRFUAPI(void);
void LinkRfu_Shutdown(void); void LinkRfu_Shutdown(void);
void Rfu_SetBlockReceivedFlag(u8 who); void Rfu_SetBlockReceivedFlag(u8 who);
void Rfu_ResetBlockReceivedFlag(u8 who); void Rfu_ResetBlockReceivedFlag(u8 who);
@ -264,7 +246,6 @@ bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx);
s32 sub_800E87C(u8 idx); s32 sub_800E87C(u8 idx);
void CreateTask_RfuIdle(void); void CreateTask_RfuIdle(void);
void DestroyTask_RfuIdle(void); void DestroyTask_RfuIdle(void);
void sub_8010198(void);
void sub_8011AC8(void); void sub_8011AC8(void);
void LinkRfu_FatalError(void); void LinkRfu_FatalError(void);
bool32 sub_8011A9C(void); bool32 sub_8011A9C(void);
@ -273,7 +254,6 @@ void sub_8011A50(void);
void sub_80110B8(u32 a0); void sub_80110B8(u32 a0);
bool32 IsRfuSerialNumberValid(u32 serialNo); bool32 IsRfuSerialNumberValid(u32 serialNo);
bool8 IsRfuRecoveringFromLinkLoss(void); bool8 IsRfuRecoveringFromLinkLoss(void);
void sub_8011BA4(void);
void RfuRecvQueue_Reset(struct RfuRecvQueue *queue); void RfuRecvQueue_Reset(struct RfuRecvQueue *queue);
void RfuSendQueue_Reset(struct RfuSendQueue *queue); void RfuSendQueue_Reset(struct RfuSendQueue *queue);
void RfuRecvQueue_Enqueue(struct RfuRecvQueue *queue, u8 *data); void RfuRecvQueue_Enqueue(struct RfuRecvQueue *queue, u8 *data);
@ -282,13 +262,9 @@ bool8 RfuRecvQueue_Dequeue(struct RfuRecvQueue *queue, u8 *dest);
bool8 RfuSendQueue_Dequeue(struct RfuSendQueue *queue, u8 *dest); bool8 RfuSendQueue_Dequeue(struct RfuSendQueue *queue, u8 *dest);
void RfuBackupQueue_Enqueue(struct RfuBackupQueue *queue, const u8 *q2); void RfuBackupQueue_Enqueue(struct RfuBackupQueue *queue, const u8 *q2);
bool8 RfuBackupQueue_Dequeue(struct RfuBackupQueue *queue, u8 *q2); bool8 RfuBackupQueue_Dequeue(struct RfuBackupQueue *queue, u8 *q2);
void sub_800DBF8(u8 *q1, u8 mode); void InitHostRFUtgtGname(struct GFtgtGname *data, u8 activity, bool32 started, s32 child_sprite_genders);
u8 sub_800DD1C(u8 maxFlags);
void InitHostRFUtgtGname(struct GFtgtGname *data, u8 r9, bool32 r2, s32 r3);
void CreateWirelessStatusIndicatorSprite(u8 x, u8 y); void CreateWirelessStatusIndicatorSprite(u8 x, u8 y);
void DestroyWirelessStatusIndicatorSprite(void); void DestroyWirelessStatusIndicatorSprite(void);
void LoadWirelessStatusIndicatorSpriteGfx(void); void LoadWirelessStatusIndicatorSpriteGfx(void);
u8 sub_800E124(void);
void sub_800E15C(struct Sprite *sprite, s32 signalStrengthAnimNum);
#endif //GUARD_LINK_RFU_H #endif //GUARD_LINK_RFU_H

View File

@ -1246,7 +1246,7 @@ static void sub_8080018(void)
if (++sBerryBlenderData->framesToWait > 20) if (++sBerryBlenderData->framesToWait > 20)
{ {
ClearDialogWindowAndFrameToTransparent(4, TRUE); ClearDialogWindowAndFrameToTransparent(4, TRUE);
if (GetBlockReceivedStatus() == sub_800A9D8()) if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
{ {
for (i = 0; i < GetLinkPlayerCount(); i++) for (i = 0; i < GetLinkPlayerCount(); i++)
{ {
@ -1664,7 +1664,7 @@ static void sub_80808D4(void)
static void sub_8080DF8(void) static void sub_8080DF8(void)
{ {
s32 i; s32 i;
for (i = 0; i < 4; i++) for (i = 0; i < CMD_LENGTH / 2; i++)
{ {
gSendCmd[0] = 0; gSendCmd[0] = 0;
gSendCmd[2] = 0; gSendCmd[2] = 0;

View File

@ -283,7 +283,7 @@ static void Task_LinkupAwaitConfirmation(u8 taskId)
if (linkPlayerCount < tMinPlayers) if (linkPlayerCount < tMinPlayers)
return; return;
sub_800AA04(linkPlayerCount); SaveLinkPlayers(linkPlayerCount);
ClearLinkPlayerCountWindow(tWindowId); ClearLinkPlayerCountWindow(tWindowId);
ConvertIntToDecimalStringN(gStringVar1, linkPlayerCount, STR_CONV_MODE_LEFT_ALIGN, 1); ConvertIntToDecimalStringN(gStringVar1, linkPlayerCount, STR_CONV_MODE_LEFT_ALIGN, 1);
ShowFieldAutoScrollMessage(gText_ConfirmStartLinkWithXPlayers); ShowFieldAutoScrollMessage(gText_ConfirmStartLinkWithXPlayers);
@ -372,7 +372,7 @@ static void Task_LinkupExchangeDataWithLeader(u8 taskId)
{ {
gFieldLinkPlayerCount = GetLinkPlayerCount_2(); gFieldLinkPlayerCount = GetLinkPlayerCount_2();
gLocalLinkPlayerId = GetMultiplayerId(); gLocalLinkPlayerId = GetMultiplayerId();
sub_800AA04(gFieldLinkPlayerCount); SaveLinkPlayers(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer; card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card); TrainerCard_GenerateCardForPlayer(card);
card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL); card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL);
@ -420,7 +420,7 @@ static void Task_LinkupCheckStatusAfterConfirm(u8 taskId)
{ {
gFieldLinkPlayerCount = GetLinkPlayerCount_2(); gFieldLinkPlayerCount = GetLinkPlayerCount_2();
gLocalLinkPlayerId = GetMultiplayerId(); gLocalLinkPlayerId = GetMultiplayerId();
sub_800AA04(gFieldLinkPlayerCount); SaveLinkPlayers(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer; card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card); TrainerCard_GenerateCardForPlayer(card);
card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL); card->monSpecies[0] = GetMonData(&gPlayerParty[gSelectedOrderFromParty[0] - 1], MON_DATA_SPECIES, NULL);
@ -516,7 +516,7 @@ static void Task_LinkupAwaitTrainerCardData(u8 taskId)
if (CheckLinkErrored(taskId) == TRUE) if (CheckLinkErrored(taskId) == TRUE)
return; return;
if (GetBlockReceivedStatus() != sub_800A9A8()) if (GetBlockReceivedStatus() != GetSavedLinkPlayerCountAsBitFlags())
return; return;
for (index = 0; index < GetLinkPlayerCount(); index++) for (index = 0; index < GetLinkPlayerCount(); index++)
@ -800,8 +800,8 @@ static void Task_ReestablishLinkAwaitConfirmation(u8 taskId)
if (gReceivedRemoteLinkPlayers == TRUE if (gReceivedRemoteLinkPlayers == TRUE
&& IsLinkPlayerDataExchangeComplete() == TRUE) && IsLinkPlayerDataExchangeComplete() == TRUE)
{ {
sub_800AB18(); CheckLinkPlayersMatchSaved();
sub_8009F18(); StartSendingKeysToLink();
DestroyTask(taskId); DestroyTask(taskId);
} }
} }
@ -901,7 +901,7 @@ static void Task_StartWirelessCableClubBattle(u8 taskId)
tState = 3; tState = 3;
break; break;
case 3: case 3:
if (GetBlockReceivedStatus() == sub_800A9D8()) if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
{ {
for (i = 0; i < GetLinkPlayerCount(); i++) for (i = 0; i < GetLinkPlayerCount(); i++)
{ {
@ -1236,7 +1236,7 @@ void Task_WaitForLinkPlayerConnection(u8 taskId)
// Players connected, destroy task // Players connected, destroy task
if (gWirelessCommType == 0) if (gWirelessCommType == 0)
{ {
if (!sub_800AA60()) if (!DoesLinkPlayerCountMatchSaved())
{ {
CloseLink(); CloseLink();
SetMainCallback2(CB2_LinkError); SetMainCallback2(CB2_LinkError);

View File

@ -36,7 +36,7 @@ bool8 sub_80FC530(u8 arg0)
bool8 sub_80FC55C(void) bool8 sub_80FC55C(void)
{ {
if (GetBlockReceivedStatus() == sub_800A9D8()) if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
{ {
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
return TRUE; return TRUE;

View File

@ -832,9 +832,9 @@ static void sub_8025158(void)
static bool32 sub_8025170(void) static bool32 sub_8025170(void)
{ {
u8 r4 = GetBlockReceivedStatus(); u8 recvStatus = GetBlockReceivedStatus();
u8 r0 = sub_800A9D8(); u8 playerFlags = GetLinkPlayerCountAsBitFlags();
if (r4 == r0) if (recvStatus == playerFlags)
{ {
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
return TRUE; return TRUE;

View File

@ -215,7 +215,7 @@ static void Task_ReturnToFieldWirelessLink(u8 taskId)
case 2: case 2:
if (WaitForWeatherFadeIn() == TRUE) if (WaitForWeatherFadeIn() == TRUE)
{ {
sub_8009F18(); StartSendingKeysToLink();
ScriptContext2_Disable(); ScriptContext2_Disable();
DestroyTask(taskId); DestroyTask(taskId);
} }
@ -240,7 +240,7 @@ void Task_ReturnToFieldRecordMixing(u8 taskId)
} }
break; break;
case 2: case 2:
sub_8009F18(); StartSendingKeysToLink();
ResetAllMultiplayerState(); ResetAllMultiplayerState();
ScriptContext2_Disable(); ScriptContext2_Disable();
DestroyTask(taskId); DestroyTask(taskId);

View File

@ -1,5 +1,3 @@
// Includes
#include "global.h" #include "global.h"
#include "m4a.h" #include "m4a.h"
#include "malloc.h" #include "malloc.h"
@ -30,10 +28,6 @@
#include "constants/rgb.h" #include "constants/rgb.h"
#include "constants/trade.h" #include "constants/trade.h"
extern u16 gHeldKeyCodeToSend;
// Static type declarations
struct BlockTransfer struct BlockTransfer
{ {
u16 pos; u16 pos;
@ -51,15 +45,13 @@ struct LinkTestBGInfo
u32 dummy_C; u32 dummy_C;
}; };
// Static RAM declarations
static struct BlockTransfer sBlockSend; static struct BlockTransfer sBlockSend;
static struct BlockTransfer sBlockRecv[MAX_LINK_PLAYERS]; static struct BlockTransfer sBlockRecv[MAX_LINK_PLAYERS];
static u32 sBlockSendDelayCounter; static u32 sBlockSendDelayCounter;
static u32 gUnknown_03000D54; static bool32 sDummy1; // Never read
static u8 gUnknown_03000D58; static bool8 sDummy2; // Never assigned, read in unused function
static u32 sPlayerDataExchangeStatus; static u32 sPlayerDataExchangeStatus;
static u32 gUnknown_03000D60; static bool32 sDummy3; // Never read
static u8 sLinkTestLastBlockSendPos; static u8 sLinkTestLastBlockSendPos;
static u8 sLinkTestLastBlockRecvPos[MAX_LINK_PLAYERS]; static u8 sLinkTestLastBlockRecvPos[MAX_LINK_PLAYERS];
static u8 sNumVBlanksWithoutSerialIntr; static u8 sNumVBlanksWithoutSerialIntr;
@ -74,15 +66,15 @@ u32 gLinkDebugSeed;
struct LinkPlayerBlock gLocalLinkPlayerBlock; struct LinkPlayerBlock gLocalLinkPlayerBlock;
bool8 gLinkErrorOccurred; bool8 gLinkErrorOccurred;
u32 gLinkDebugFlags; u32 gLinkDebugFlags;
u32 gFiller_03003074; u32 gLinkFiller1;
bool8 gRemoteLinkPlayersNotReceived[MAX_LINK_PLAYERS]; bool8 gRemoteLinkPlayersNotReceived[MAX_LINK_PLAYERS];
u8 gBlockReceivedStatus[MAX_LINK_PLAYERS]; u8 gBlockReceivedStatus[MAX_LINK_PLAYERS];
u32 gFiller_03003080; u32 gLinkFiller2;
u16 gLinkHeldKeys; u16 gLinkHeldKeys;
u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH]; u16 gRecvCmds[MAX_RFU_PLAYERS][CMD_LENGTH];
u32 gLinkStatus; u32 gLinkStatus;
bool8 gUnknown_030030E4; bool8 gLinkDummy1; // Never read
bool8 gUnknown_030030E8; bool8 gLinkDummy2; // Never read
bool8 gUnknown_030030EC[MAX_LINK_PLAYERS]; bool8 gUnknown_030030EC[MAX_LINK_PLAYERS];
bool8 gUnknown_030030F0[MAX_LINK_PLAYERS]; bool8 gUnknown_030030F0[MAX_LINK_PLAYERS];
u16 gUnknown_030030F4; u16 gUnknown_030030F4;
@ -97,15 +89,15 @@ void (*gLinkCallback)(void);
u8 gShouldAdvanceLinkState; u8 gShouldAdvanceLinkState;
u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS]; u16 gLinkTestBlockChecksums[MAX_LINK_PLAYERS];
u8 gBlockRequestType; u8 gBlockRequestType;
u32 gFiller_03003154; u32 gLinkFiller3;
u32 gFiller_03003158; u32 gLinkFiller4;
u32 gFiller_0300315c; u32 gLinkFiller5;
u8 gLastSendQueueCount; u8 gLastSendQueueCount;
struct Link gLink; struct Link gLink;
u8 gLastRecvQueueCount; u8 gLastRecvQueueCount;
u16 gLinkSavedIme; u16 gLinkSavedIme;
u32 gFiller_03004138; u32 gLinkFiller6;
u32 gFiller_0300413C; u32 gLinkFiller7;
EWRAM_DATA u8 gLinkTestDebugValuesEnabled = 0; EWRAM_DATA u8 gLinkTestDebugValuesEnabled = 0;
EWRAM_DATA u8 gUnknown_020223BD = 0; EWRAM_DATA u8 gUnknown_020223BD = 0;
@ -130,10 +122,10 @@ static EWRAM_DATA void *sLinkErrorBgTilemapBuffer = NULL;
// Static ROM declarations // Static ROM declarations
static void InitLocalLinkPlayer(void); static void InitLocalLinkPlayer(void);
static void sub_80096BC(void); static void VBlankCB_LinkError(void);
static void CB2_LinkTest(void); static void CB2_LinkTest(void);
static void ProcessRecvCmds(u8 unused); static void ProcessRecvCmds(u8 unused);
static void sub_8009F70(void); static void LinkCB_SendHeldKeys(void);
static void ResetBlockSend(void); static void ResetBlockSend(void);
static bool32 InitBlockSend(const void *src, size_t size); static bool32 InitBlockSend(const void *src, size_t size);
static void LinkCB_BlockSendBegin(void); static void LinkCB_BlockSendBegin(void);
@ -243,7 +235,7 @@ static const u8 sUnused_082ED224[] = {0x00, 0xFF, 0xFE, 0xFF, 0x00};
bool8 IsWirelessAdapterConnected(void) bool8 IsWirelessAdapterConnected(void)
{ {
SetWirelessCommType1(); SetWirelessCommType1();
sub_800E700(); InitRFUAPI();
if (rfu_LMAN_REQBN_softReset_and_checkID() == 0x8001) if (rfu_LMAN_REQBN_softReset_and_checkID() == 0x8001)
{ {
rfu_REQ_stopMode(); rfu_REQ_stopMode();
@ -301,7 +293,7 @@ void LinkTestScreen(void)
ResetSpriteData(); ResetSpriteData();
FreeAllSpritePalettes(); FreeAllSpritePalettes();
ResetTasks(); ResetTasks();
SetVBlankCallback(sub_80096BC); SetVBlankCallback(VBlankCB_LinkError);
ResetBlockSend(); ResetBlockSend();
gLinkType = LINKTYPE_TRADE; gLinkType = LINKTYPE_TRADE;
OpenLink(); OpenLink();
@ -317,7 +309,7 @@ void LinkTestScreen(void)
AnimateSprites(); AnimateSprites();
BuildOamBuffer(); BuildOamBuffer();
UpdatePaletteFade(); UpdatePaletteFade();
gUnknown_03000D60 = 0; sDummy3 = FALSE;
InitLocalLinkPlayer(); InitLocalLinkPlayer();
CreateTask(Task_PrintTestData, 0); CreateTask(Task_PrintTestData, 0);
SetMainCallback2(CB2_LinkTest); SetMainCallback2(CB2_LinkTest);
@ -344,7 +336,7 @@ static void InitLocalLinkPlayer(void)
} }
} }
static void sub_80096BC(void) static void VBlankCB_LinkError(void)
{ {
LoadOam(); LoadOam();
ProcessSpriteCopyRequests(); ProcessSpriteCopyRequests();
@ -355,9 +347,9 @@ static void InitLink(void)
{ {
int i; int i;
for (i = 0; i < 8; i++) for (i = 0; i < CMD_LENGTH; i++)
{ {
gSendCmd[i] = 0xefff; gSendCmd[i] = 0xEfff;
} }
gLinkOpen = TRUE; gLinkOpen = TRUE;
EnableSerial(); EnableSerial();
@ -386,15 +378,15 @@ void OpenLink(void)
gSuppressLinkErrorMessage = FALSE; gSuppressLinkErrorMessage = FALSE;
ResetBlockReceivedFlags(); ResetBlockReceivedFlags();
ResetBlockSend(); ResetBlockSend();
gUnknown_03000D54 = 0; sDummy1 = FALSE;
gUnknown_030030E8 = FALSE; gLinkDummy2 = FALSE;
gUnknown_030030E4 = FALSE; gLinkDummy1 = FALSE;
gUnknown_030030F4 = 0; gUnknown_030030F4 = 0;
CreateTask(Task_TriggerHandshake, 2); CreateTask(Task_TriggerHandshake, 2);
} }
else else
{ {
sub_800E700(); InitRFUAPI();
} }
gReceivedRemoteLinkPlayers = 0; gReceivedRemoteLinkPlayers = 0;
for (i = 0; i < MAX_LINK_PLAYERS; i++) for (i = 0; i < MAX_LINK_PLAYERS; i++)
@ -503,7 +495,7 @@ u16 LinkMain2(const u16 *heldKeys)
{ {
return 0; return 0;
} }
for (i = 0; i < 8; i++) for (i = 0; i < CMD_LENGTH; i++)
{ {
gSendCmd[i] = 0; gSendCmd[i] = 0;
} }
@ -566,10 +558,10 @@ static void ProcessRecvCmds(u8 unused)
gLinkPartnersHeldKeys[i] = gRecvCmds[i][1]; gLinkPartnersHeldKeys[i] = gRecvCmds[i][1];
break; break;
case LINKCMD_0x5555: case LINKCMD_0x5555:
gUnknown_030030E8 = TRUE; gLinkDummy2 = TRUE;
break; break;
case LINKCMD_0x5566: case LINKCMD_0x5566:
gUnknown_030030E8 = TRUE; gLinkDummy2 = TRUE;
break; break;
case LINKCMD_INIT_BLOCK: case LINKCMD_INIT_BLOCK:
{ {
@ -726,70 +718,56 @@ static void BuildSendCmd(u16 command)
} }
} }
void sub_8009F18(void) void StartSendingKeysToLink(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{
StartSendingKeysToRfu(); StartSendingKeysToRfu();
}
gLinkCallback = sub_8009F70; gLinkCallback = LinkCB_SendHeldKeys;
} }
bool32 IsSendingKeysToLink(void) bool32 IsSendingKeysToLink(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{
return IsSendingKeysToRfu(); return IsSendingKeysToRfu();
}
if (gLinkCallback == sub_8009F70) if (gLinkCallback == LinkCB_SendHeldKeys)
{
return TRUE; return TRUE;
}
return FALSE; return FALSE;
} }
static void sub_8009F70(void) static void LinkCB_SendHeldKeys(void)
{ {
if (gReceivedRemoteLinkPlayers == TRUE) if (gReceivedRemoteLinkPlayers == TRUE)
{
BuildSendCmd(LINKCMD_SEND_HELD_KEYS_2); BuildSendCmd(LINKCMD_SEND_HELD_KEYS_2);
}
} }
void ClearLinkCallback(void) void ClearLinkCallback(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{
ClearLinkRfuCallback(); ClearLinkRfuCallback();
}
else else
{
gLinkCallback = NULL; gLinkCallback = NULL;
}
} }
void ClearLinkCallback_2(void) void ClearLinkCallback_2(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{
ClearLinkRfuCallback(); ClearLinkRfuCallback();
}
else else
{
gLinkCallback = NULL; gLinkCallback = NULL;
}
} }
u8 GetLinkPlayerCount(void) u8 GetLinkPlayerCount(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{
return Rfu_GetLinkPlayerCount(); return Rfu_GetLinkPlayerCount();
}
return EXTRACT_PLAYER_COUNT(gLinkStatus); return EXTRACT_PLAYER_COUNT(gLinkStatus);
} }
static int sub_8009FF8(u32 version1, u32 version2) static int AreAnyLinkPlayersUsingVersions(u32 version1, u32 version2)
{ {
int i; int i;
u8 nPlayers; u8 nPlayers;
@ -797,22 +775,22 @@ static int sub_8009FF8(u32 version1, u32 version2)
nPlayers = GetLinkPlayerCount(); nPlayers = GetLinkPlayerCount();
for (i = 0; i < nPlayers; i++) for (i = 0; i < nPlayers; i++)
{ {
if ((gLinkPlayers[i].version & 0xFF) == version1 || (gLinkPlayers[i].version & 0xFF) == version2) if ((gLinkPlayers[i].version & 0xFF) == version1
{ || (gLinkPlayers[i].version & 0xFF) == version2)
return 1; return 1;
}
} }
return -1; return -1;
} }
u32 sub_800A03C(void) u32 LinkDummy_Return2(void)
{ {
return 2; return 2;
} }
bool32 sub_800A040(void) // Unused
static bool32 IsFullLinkGroupWithNoRS(void)
{ {
if (GetLinkPlayerCount() != 4 || sub_8009FF8(VERSION_RUBY, VERSION_SAPPHIRE) < 0) if (GetLinkPlayerCount() != MAX_LINK_PLAYERS || AreAnyLinkPlayersUsingVersions(VERSION_RUBY, VERSION_SAPPHIRE) < 0)
{ {
return FALSE; return FALSE;
} }
@ -821,18 +799,18 @@ bool32 sub_800A040(void)
bool32 Link_AnyPartnersPlayingRubyOrSapphire(void) bool32 Link_AnyPartnersPlayingRubyOrSapphire(void)
{ {
if (sub_8009FF8(VERSION_RUBY, VERSION_SAPPHIRE) >= 0) if (AreAnyLinkPlayersUsingVersions(VERSION_RUBY, VERSION_SAPPHIRE) >= 0)
{ {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
bool32 sub_800A07C(void) bool32 Link_AnyPartnersPlayingFRLG_JP(void)
{ {
int i; int i;
i = sub_8009FF8(VERSION_FIRE_RED, VERSION_LEAF_GREEN); i = AreAnyLinkPlayersUsingVersions(VERSION_FIRE_RED, VERSION_LEAF_GREEN);
if (i >= 0 && gLinkPlayers[i].language == LANGUAGE_JAPANESE) if (i >= 0 && gLinkPlayers[i].language == LANGUAGE_JAPANESE)
{ {
return TRUE; return TRUE;
@ -983,7 +961,7 @@ static bool32 InitBlockSend(const void *src, size_t size)
sBlockSend.active = TRUE; sBlockSend.active = TRUE;
sBlockSend.size = size; sBlockSend.size = size;
sBlockSend.pos = 0; sBlockSend.pos = 0;
if (size > 0x100) if (size > BLOCK_BUFFER_SIZE)
{ {
sBlockSend.src = src; sBlockSend.src = src;
} }
@ -1016,7 +994,7 @@ static void LinkCB_BlockSend(void)
src = sBlockSend.src; src = sBlockSend.src;
gSendCmd[0] = LINKCMD_CONT_BLOCK; gSendCmd[0] = LINKCMD_CONT_BLOCK;
for (i = 0; i < 7; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
{ {
gSendCmd[i + 1] = (src[sBlockSend.pos + i * 2 + 1] << 8) | src[sBlockSend.pos + i * 2]; gSendCmd[i + 1] = (src[sBlockSend.pos + i * 2 + 1] << 8) | src[sBlockSend.pos + i * 2];
} }
@ -1313,7 +1291,7 @@ void SetLinkDebugValues(u32 seed, u32 flags)
gLinkDebugFlags = flags; gLinkDebugFlags = flags;
} }
u8 sub_800A9A8(void) u8 GetSavedLinkPlayerCountAsBitFlags(void)
{ {
int i; int i;
u8 flags; u8 flags;
@ -1326,7 +1304,7 @@ u8 sub_800A9A8(void)
return flags; return flags;
} }
u8 sub_800A9D8(void) u8 GetLinkPlayerCountAsBitFlags(void)
{ {
int i; int i;
u8 flags; u8 flags;
@ -1339,11 +1317,11 @@ u8 sub_800A9D8(void)
return flags; return flags;
} }
void sub_800AA04(u8 a0) void SaveLinkPlayers(u8 playerCount)
{ {
int i; int i;
gSavedLinkPlayerCount = a0; gSavedLinkPlayerCount = playerCount;
gSavedMultiplayerId = GetMultiplayerId(); gSavedMultiplayerId = GetMultiplayerId();
for (i = 0; i < MAX_RFU_PLAYERS; i++) for (i = 0; i < MAX_RFU_PLAYERS; i++)
{ {
@ -1358,17 +1336,17 @@ u8 GetSavedPlayerCount(void)
return gSavedLinkPlayerCount; return gSavedLinkPlayerCount;
} }
u8 sub_800AA54(void) // Unused
static u8 GetSavedMultiplayerId(void)
{ {
return gSavedMultiplayerId; return gSavedMultiplayerId;
} }
bool8 sub_800AA60(void) bool8 DoesLinkPlayerCountMatchSaved(void)
{ {
int i; int i;
unsigned count; u32 count = 0;
count = 0;
for (i = 0; i < gSavedLinkPlayerCount; i++) for (i = 0; i < gSavedLinkPlayerCount; i++)
{ {
if (gLinkPlayers[i].trainerId == gSavedLinkPlayers[i].trainerId) if (gLinkPlayers[i].trainerId == gSavedLinkPlayers[i].trainerId)
@ -1376,9 +1354,7 @@ bool8 sub_800AA60(void)
if (gLinkType == LINKTYPE_BATTLE_TOWER) if (gLinkType == LINKTYPE_BATTLE_TOWER)
{ {
if (gLinkType == gLinkPlayers[i].linkType) if (gLinkType == gLinkPlayers[i].linkType)
{
count++; count++;
}
} }
else else
{ {
@ -1396,7 +1372,7 @@ bool8 sub_800AA60(void)
return FALSE; return FALSE;
} }
void sub_800AAF4(void) void ClearSavedLinkPlayers(void)
{ {
int i; int i;
@ -1407,13 +1383,14 @@ void sub_800AAF4(void)
} }
} }
void sub_800AB18(void) void CheckLinkPlayersMatchSaved(void)
{ {
u8 i; u8 i;
for (i = 0; i < gSavedLinkPlayerCount; i++) for (i = 0; i < gSavedLinkPlayerCount; i++)
{ {
if (gSavedLinkPlayers[i].trainerId != gLinkPlayers[i].trainerId || StringCompare(gSavedLinkPlayers[i].name, gLinkPlayers[i].name) != 0) if (gSavedLinkPlayers[i].trainerId != gLinkPlayers[i].trainerId
|| StringCompare(gSavedLinkPlayers[i].name, gLinkPlayers[i].name) != 0)
{ {
gLinkErrorOccurred = TRUE; gLinkErrorOccurred = TRUE;
CloseLink(); CloseLink();
@ -1442,9 +1419,10 @@ bool8 IsLinkMaster(void)
return EXTRACT_MASTER(gLinkStatus); return EXTRACT_MASTER(gLinkStatus);
} }
u8 sub_800ABE8(void) // Unused
static u8 GetDummy2(void)
{ {
return gUnknown_03000D58; return sDummy2;
} }
void sub_800ABF4(u16 a0) void sub_800ABF4(u16 a0)
@ -1458,7 +1436,7 @@ void sub_800ABF4(u16 a0)
if (gLinkCallback == NULL) if (gLinkCallback == NULL)
{ {
gLinkCallback = sub_800AC80; gLinkCallback = sub_800AC80;
gUnknown_030030E4 = FALSE; gLinkDummy1 = FALSE;
gUnknown_030030F4 = a0; gUnknown_030030F4 = a0;
} }
} }
@ -1479,7 +1457,7 @@ void sub_800AC34(void)
else else
{ {
gLinkCallback = sub_800AC80; gLinkCallback = sub_800AC80;
gUnknown_030030E4 = FALSE; gLinkDummy1 = FALSE;
gUnknown_030030F4 = 0; gUnknown_030030F4 = 0;
} }
} }
@ -1515,7 +1493,7 @@ static void sub_800ACAC(void)
gLinkVSyncDisabled = TRUE; gLinkVSyncDisabled = TRUE;
CloseLink(); CloseLink();
gLinkCallback = NULL; gLinkCallback = NULL;
gUnknown_030030E4 = TRUE; gLinkDummy1 = TRUE;
} }
} }
@ -1534,7 +1512,7 @@ void sub_800AD10(void)
else else
{ {
gLinkCallback = sub_800AD5C; gLinkCallback = sub_800AD5C;
gUnknown_030030E4 = FALSE; gLinkDummy1 = FALSE;
gUnknown_030030F4 = 0; gUnknown_030030F4 = 0;
} }
} }
@ -1574,7 +1552,7 @@ static void sub_800AD88(void)
gLinkVSyncDisabled = TRUE; gLinkVSyncDisabled = TRUE;
CloseLink(); CloseLink();
gLinkCallback = NULL; gLinkCallback = NULL;
gUnknown_030030E4 = TRUE; gLinkDummy1 = TRUE;
} }
} }
@ -1590,7 +1568,7 @@ void sub_800ADF8(void)
{ {
gLinkCallback = sub_800AE30; gLinkCallback = sub_800AE30;
} }
gUnknown_030030E4 = FALSE; gLinkDummy1 = FALSE;
} }
} }
@ -1642,7 +1620,7 @@ static void CheckErrorStatus(void)
} }
} }
void sub_800AF18(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, u8 unk_06) void BufferLinkErrorInfo(u32 status, u8 lastSendQueueCount, u8 lastRecvQueueCount, bool8 unk_06)
{ {
sLinkErrorBuffer.status = status; sLinkErrorBuffer.status = status;
sLinkErrorBuffer.lastSendQueueCount = lastSendQueueCount; sLinkErrorBuffer.lastSendQueueCount = lastSendQueueCount;
@ -1673,7 +1651,7 @@ void CB2_LinkError(void)
} }
ResetLinkRfuGFLayer(); ResetLinkRfuGFLayer();
} }
SetVBlankCallback(sub_80096BC); SetVBlankCallback(VBlankCB_LinkError);
ResetBgsAndClearDma3BusyFlags(0); ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sLinkErrorBgTemplates, ARRAY_COUNT(sLinkErrorBgTemplates)); InitBgsFromTemplates(0, sLinkErrorBgTemplates, ARRAY_COUNT(sLinkErrorBgTemplates));
sLinkErrorBgTilemapBuffer = tilemapBuffer = malloc(0x800); sLinkErrorBgTilemapBuffer = tilemapBuffer = malloc(0x800);

View File

@ -28,17 +28,31 @@ struct SioInfo
u8 filler[92]; u8 filler[92];
}; };
struct RfuDebug
{
u8 filler0[6];
u16 unk_06;
u8 filler1[6];
vu8 unk_0e;
u8 unk_0f;
u8 filler2[84];
u16 unk_64;
u8 filler3[29];
u8 unk_83;
u8 filler4[88];
};
u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4]; u32 gf_rfu_REQ_api[RFU_API_BUFF_SIZE_RAM / 4];
struct GFRfuManager Rfu; struct GFRfuManager Rfu;
BSS_DATA u8 gUnknown_03000D78[8]; static u8 sHeldKeyCount;
BSS_DATA u8 sResendBlock8[16]; static u8 sResendBlock8[16];
BSS_DATA u16 sResendBlock16[8]; static u16 sResendBlock16[8];
EWRAM_DATA struct GFtgtGname gHostRFUtgtGnameBuffer = {}; EWRAM_DATA struct GFtgtGname gHostRFUtgtGnameBuffer = {};
EWRAM_DATA ALIGNED(2) u8 gHostRFUtgtUnameBuffer[PLAYER_NAME_LENGTH + 1] = {}; EWRAM_DATA u8 gHostRFUtgtUnameBuffer[PLAYER_NAME_LENGTH + 1] = {};
EWRAM_DATA INIT_PARAM sRfuReqConfig = {}; static EWRAM_DATA INIT_PARAM sRfuReqConfig = {};
EWRAM_DATA struct UnkLinkRfuStruct_02022B44 gUnknown_02022B44 = {}; static EWRAM_DATA struct RfuDebug sRfuDebug = {};
static void ResetSendDataManager(struct RfuBlockSend *); static void ResetSendDataManager(struct RfuBlockSend *);
static void sub_800EAB4(void); static void sub_800EAB4(void);
@ -146,8 +160,8 @@ static const struct {
}; };
static const u16 sAcceptedSerialNos[] = { static const u16 sAcceptedSerialNos[] = {
0x0002, // Pokemon FR/LG/EM 0x0002,
0x7f7d, RFU_SERIAL_7F7D,
0x0000, 0x0000,
0xFFFF 0xFFFF
}; };
@ -225,11 +239,11 @@ void ResetLinkRfuGFLayer(void)
{ {
Rfu.errorState = 0; Rfu.errorState = 0;
} }
for (i = 0; i < 5; i++) for (i = 0; i < MAX_RFU_PLAYERS; i++)
{ {
ResetSendDataManager(Rfu.unk_80 + i); ResetSendDataManager(&Rfu.recvBlock[i]);
} }
ResetSendDataManager(&Rfu.unk_6c); ResetSendDataManager(&Rfu.sendBlock);
RfuRecvQueue_Reset(&Rfu.recvQueue); RfuRecvQueue_Reset(&Rfu.recvQueue);
RfuSendQueue_Reset(&Rfu.sendQueue); RfuSendQueue_Reset(&Rfu.sendQueue);
CpuFill16(0, gSendCmd, sizeof gSendCmd); CpuFill16(0, gSendCmd, sizeof gSendCmd);
@ -241,7 +255,7 @@ void InitRFU(void)
{ {
IntrFunc serialIntr = gIntrTable[1]; IntrFunc serialIntr = gIntrTable[1];
IntrFunc timerIntr = gIntrTable[2]; IntrFunc timerIntr = gIntrTable[2];
sub_800E700(); InitRFUAPI();
rfu_REQ_stopMode(); rfu_REQ_stopMode();
rfu_waitREQComplete(); rfu_waitREQComplete();
REG_IME = 0; REG_IME = 0;
@ -250,12 +264,12 @@ void InitRFU(void)
REG_IME = INTR_FLAG_VBLANK; REG_IME = INTR_FLAG_VBLANK;
} }
void sub_800E700(void) void InitRFUAPI(void)
{ {
if (!rfu_initializeAPI((void *)gf_rfu_REQ_api, sizeof gf_rfu_REQ_api, gIntrTable + 1, TRUE)) if (!rfu_initializeAPI((void *)gf_rfu_REQ_api, sizeof gf_rfu_REQ_api, gIntrTable + 1, TRUE))
{ {
gLinkType = 0; gLinkType = 0;
sub_800AAF4(); ClearSavedLinkPlayers();
sub_80111B0(FALSE); sub_80111B0(FALSE);
ResetLinkRfuGFLayer(); ResetLinkRfuGFLayer();
rfu_setTimerInterrupt(3, gIntrTable + 2); rfu_setTimerInterrupt(3, gIntrTable + 2);
@ -288,7 +302,7 @@ static void Task_LinkLeaderSearchForChildren(u8 taskId)
case 5: case 5:
break; break;
case 18: case 18:
Rfu.unk_cdb = 0; Rfu.unk_cdb = FALSE;
rfu_LMAN_setMSCCallback(sub_800EDBC); rfu_LMAN_setMSCCallback(sub_800EDBC);
sub_800EAB4(); sub_800EAB4();
sub_800EAFC(); sub_800EAFC();
@ -392,10 +406,10 @@ static void Task_JoinGroupSearchForParent(u8 taskId)
rfu_UNI_setSendData(bmChildSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c)); rfu_UNI_setSendData(bmChildSlot, Rfu.unk_4c, sizeof(Rfu.unk_4c));
gTasks[taskId].data[1] = 8; gTasks[taskId].data[1] = 8;
DestroyTask(taskId); DestroyTask(taskId);
if (gUnknown_02022B44.unk_0f == 0) if (sRfuDebug.unk_0f == 0)
{ {
Debug_PrintEmpty(); Debug_PrintEmpty();
gUnknown_02022B44.unk_0f++; sRfuDebug.unk_0f++;
} }
CreateTask(sub_801084C, 5); CreateTask(sub_801084C, 5);
break; break;
@ -474,7 +488,7 @@ static void Task_LinkRfu_UnionRoomListen(u8 taskId)
case 15: case 15:
break; break;
case 16: case 16:
Rfu.unk_cdb = 0; Rfu.unk_cdb = FALSE;
rfu_LMAN_setMSCCallback(sub_800EDBC); rfu_LMAN_setMSCCallback(sub_800EDBC);
UpdateGameData_GroupLockedIn(TRUE); UpdateGameData_GroupLockedIn(TRUE);
sub_800EAB4(); sub_800EAB4();
@ -513,7 +527,7 @@ static void sub_800ED34(u16 unused)
{ {
Rfu.unk_cd0++; Rfu.unk_cd0++;
RfuRecvQueue_Enqueue(&Rfu.recvQueue, Rfu.unk_c3f); RfuRecvQueue_Enqueue(&Rfu.recvQueue, Rfu.unk_c3f);
gUnknown_02022B44.unk_06++; sRfuDebug.unk_06++;
UpdateBackupQueue(); UpdateBackupQueue();
rfu_UNI_readySendData(Rfu.childSlot); rfu_UNI_readySendData(Rfu.childSlot);
rfu_UNI_clearRecvNewDataFlag(Rfu.childSlot); rfu_UNI_clearRecvNewDataFlag(Rfu.childSlot);
@ -523,7 +537,7 @@ static void sub_800ED34(u16 unused)
static void sub_800EDBC(u16 unused) static void sub_800EDBC(u16 unused)
{ {
Rfu.unk_cdb = 1; Rfu.unk_cdb = TRUE;
} }
void LinkRfu_Shutdown(void) void LinkRfu_Shutdown(void)
@ -657,11 +671,11 @@ static void sub_800EFB0(void)
static void sub_800F014(void) static void sub_800F014(void)
{ {
s32 i; s32 i;
for (i = 0; i < 7; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
{ {
gRecvCmds[0][i] = gSendCmd[i]; gRecvCmds[0][i] = gSendCmd[i];
} }
for (i = 0; i < 7; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
{ {
gSendCmd[i] = 0; gSendCmd[i] = 0;
} }
@ -695,9 +709,9 @@ bool32 IsRfuRecvQueueEmpty(void)
{ {
return FALSE; 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) if (gRecvCmds[i][j] != 0)
{ {
@ -718,7 +732,7 @@ static bool32 sub_800F0F8(void)
} }
else else
{ {
Rfu.unk_cdb = 0; Rfu.unk_cdb = FALSE;
if ((Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag) == Rfu.unk_ce2 && (Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag)) if ((Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag) == Rfu.unk_ce2 && (Rfu.unk_ce2 & gRfuLinkStatus->connSlotFlag))
{ {
if (!Rfu.unk_cdc) if (!Rfu.unk_cdc)
@ -748,7 +762,7 @@ static bool32 sub_800F0F8(void)
{ {
rfu_REQ_PARENT_resumeRetransmitAndChange(); rfu_REQ_PARENT_resumeRetransmitAndChange();
} }
Rfu.unk_0e = 1; Rfu.unk_0e = TRUE;
} }
} }
return FALSE; return FALSE;
@ -762,10 +776,10 @@ static bool32 sub_800F1E0(void)
u16 j; u16 j;
u8 retval; u8 retval;
if (Rfu.state >= 20 && Rfu.unk_0e == 1) if (Rfu.state >= 20 && Rfu.unk_0e == TRUE)
{ {
rfu_waitREQComplete(); rfu_waitREQComplete();
while (Rfu.unk_cdb == 0) while (Rfu.unk_cdb == FALSE)
{ {
if (Rfu.errorState != 0) if (Rfu.errorState != 0)
{ {
@ -776,8 +790,8 @@ static bool32 sub_800F1E0(void)
rfu_waitREQComplete(); rfu_waitREQComplete();
if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2) if ((lman.parentAck_flag & Rfu.unk_ce2) == Rfu.unk_ce2)
{ {
Rfu.unk_cdc = 0; Rfu.unk_cdc = FALSE;
gUnknown_02022B44.unk_06++; sRfuDebug.unk_06++;
flags = lman.acceptSlot_flag; flags = lman.acceptSlot_flag;
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
@ -813,7 +827,7 @@ static bool32 sub_800F1E0(void)
CallRfuFunc(); CallRfuFunc();
if (Rfu.unk_ce5 && !Rfu.unk_cd9) if (Rfu.unk_ce5 && !Rfu.unk_cd9)
{ {
gUnknown_02022B44.unk_0e = 0; sRfuDebug.unk_0e = FALSE;
rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, Rfu.unk_cda); rfu_clearSlot(TYPE_UNI_SEND | TYPE_UNI_RECV, Rfu.unk_cda);
for (i = 0; i < RFU_CHILD_MAX; i++) for (i = 0; i < RFU_CHILD_MAX; i++)
{ {
@ -833,10 +847,10 @@ static bool32 sub_800F1E0(void)
} }
else else
{ {
Rfu.unk_cdc = 1; Rfu.unk_cdc = TRUE;
Rfu.unk_0e = 0; Rfu.unk_0e = FALSE;
} }
Rfu.unk_0e = 0; Rfu.unk_0e = FALSE;
} }
retval = Rfu.unk_cdc; retval = Rfu.unk_cdc;
return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE; return gRfuLinkStatus->sendSlotUNIFlag ? retval & 1 : FALSE;
@ -914,8 +928,8 @@ static void HandleSendFailure(u8 unused, u32 flags)
{ {
s32 i, j; s32 i, j;
const u8 *r10 = Rfu.unk_6c.payload; const u8 *r10 = Rfu.sendBlock.payload;
for (i = 0; i < Rfu.unk_6c.count; i++) for (i = 0; i < Rfu.sendBlock.count; i++)
{ {
if (!(flags & 1)) if (!(flags & 1))
{ {
@ -932,7 +946,7 @@ static void HandleSendFailure(u8 unused, u32 flags)
j++;j--; // Needed to match; j++;j--; // Needed to match;
} }
RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8);
Rfu.unk_6c.failedFlags |= (1 << i); Rfu.sendBlock.failedFlags |= (1 << i);
} }
flags >>= 1; flags >>= 1;
} }
@ -949,7 +963,7 @@ void Rfu_SetBlockReceivedFlag(u8 linkPlayerId)
void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId) void Rfu_ResetBlockReceivedFlag(u8 linkPlayerId)
{ {
Rfu.blockReceived[linkPlayerId] = FALSE; Rfu.blockReceived[linkPlayerId] = FALSE;
Rfu.unk_80[linkPlayerId].receiving = 0; Rfu.recvBlock[linkPlayerId].receiving = 0;
} }
static u8 sub_800F74C(const u8 *a0) static u8 sub_800F74C(const u8 *a0)
@ -971,8 +985,8 @@ static void RfuFunc_SendKeysToRfu(void)
&& gHeldKeyCodeToSend != LINK_KEY_CODE_NULL && gHeldKeyCodeToSend != LINK_KEY_CODE_NULL
&& gLinkTransferringData != TRUE) && gLinkTransferringData != TRUE)
{ {
gUnknown_03000D78[0]++; sHeldKeyCount++;
gHeldKeyCodeToSend |= (gUnknown_03000D78[0] << 8); gHeldKeyCodeToSend |= (sHeldKeyCount << 8);
RfuPrepareSendBuffer(RFU_COMMAND_0xBE00); RfuPrepareSendBuffer(RFU_COMMAND_0xBE00);
} }
} }
@ -1032,28 +1046,28 @@ static void RfuHandleReceiveCommand(u8 unused)
} }
break; break;
case RFU_COMMAND_0x8800: case RFU_COMMAND_0x8800:
if (Rfu.unk_80[i].receiving == 0) if (Rfu.recvBlock[i].receiving == 0)
{ {
Rfu.unk_80[i].next = 0; Rfu.recvBlock[i].next = 0;
Rfu.unk_80[i].count = gRecvCmds[i][1]; Rfu.recvBlock[i].count = gRecvCmds[i][1];
Rfu.unk_80[i].owner = gRecvCmds[i][2]; Rfu.recvBlock[i].owner = gRecvCmds[i][2];
Rfu.unk_80[i].receivedFlags = 0; Rfu.recvBlock[i].receivedFlags = 0;
Rfu.unk_80[i].receiving = 1; Rfu.recvBlock[i].receiving = 1;
Rfu.blockReceived[i] = FALSE; Rfu.blockReceived[i] = FALSE;
} }
break; break;
case RFU_COMMAND_0x8900: case RFU_COMMAND_0x8900:
if (Rfu.unk_80[i].receiving == 1) if (Rfu.recvBlock[i].receiving == 1)
{ {
Rfu.unk_80[i].next = gRecvCmds[i][0] & 0xff; Rfu.recvBlock[i].next = gRecvCmds[i][0] & 0xff;
Rfu.unk_80[i].receivedFlags |= (1 << Rfu.unk_80[i].next); Rfu.recvBlock[i].receivedFlags |= (1 << Rfu.recvBlock[i].next);
for (j = 0; j < 6; j++) for (j = 0; j < 6; j++)
gBlockRecvBuffer[i][Rfu.unk_80[i].next * 6 + j] = gRecvCmds[i][j + 1]; gBlockRecvBuffer[i][Rfu.recvBlock[i].next * 6 + j] = gRecvCmds[i][j + 1];
if (Rfu.unk_80[i].receivedFlags == sAllBlocksReceived[Rfu.unk_80[i].count]) if (Rfu.recvBlock[i].receivedFlags == sAllBlocksReceived[Rfu.recvBlock[i].count])
{ {
Rfu.unk_80[i].receiving = 2; Rfu.recvBlock[i].receiving = 2;
Rfu_SetBlockReceivedFlag(i); Rfu_SetBlockReceivedFlag(i);
if (GetHostRFUtgtGname()->activity == 0x45 && gReceivedRemoteLinkPlayers != 0 && Rfu.parentChild == MODE_CHILD) if (GetHostRFUtgtGname()->activity == (ACTIVITY_CHAT | IN_UNION_ROOM) && gReceivedRemoteLinkPlayers != 0 && Rfu.parentChild == MODE_CHILD)
ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer); ValidateAndReceivePokemonSioInfo(gBlockRecvBuffer);
} }
} }
@ -1123,7 +1137,7 @@ static bool8 AreNoPlayersReceiving(void)
for (i = 0; i < MAX_RFU_PLAYERS; i++) for (i = 0; i < MAX_RFU_PLAYERS; i++)
{ {
if (Rfu.unk_80[i].receiving) if (Rfu.recvBlock[i].receiving)
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -1135,7 +1149,7 @@ static bool8 sub_800FC88(void)
for (i = 0; i < Rfu.playerCount; i++) for (i = 0; i < Rfu.playerCount; i++)
{ {
if (Rfu.unk_80[i].receiving != 2 || Rfu.blockReceived[i] != TRUE) if (Rfu.recvBlock[i].receiving != 2 || Rfu.blockReceived[i] != TRUE)
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -1159,7 +1173,7 @@ u8 Rfu_GetBlockReceivedStatus(void)
for (i = 0; i < MAX_RFU_PLAYERS; i++) for (i = 0; i < MAX_RFU_PLAYERS; i++)
{ {
if (Rfu.unk_80[i].receiving == 2 && Rfu.blockReceived[i] == TRUE) if (Rfu.recvBlock[i].receiving == 2 && Rfu.blockReceived[i] == TRUE)
{ {
flags |= (1 << i); flags |= (1 << i);
} }
@ -1177,8 +1191,8 @@ static void RfuPrepareSendBuffer(u16 command)
switch (command) switch (command)
{ {
case RFU_COMMAND_0x8800: case RFU_COMMAND_0x8800:
gSendCmd[1] = Rfu.unk_6c.count; gSendCmd[1] = Rfu.sendBlock.count;
gSendCmd[2] = Rfu.unk_6c.owner + 0x80; gSendCmd[2] = Rfu.sendBlock.owner + 0x80;
break; break;
case RFU_COMMAND_0xA100: case RFU_COMMAND_0xA100:
if (AreNoPlayersReceiving()) if (AreNoPlayersReceiving())
@ -1231,23 +1245,23 @@ bool32 Rfu_InitBlockSend(const u8 *src, size_t size)
return FALSE; return FALSE;
if (gSendCmd[0] != 0) if (gSendCmd[0] != 0)
return FALSE; return FALSE;
if (Rfu.unk_6c.sending) if (Rfu.sendBlock.sending)
{ {
gUnknown_02022B44.unk_83++; sRfuDebug.unk_83++;
return FALSE; return FALSE;
} }
r4 = (size % 12) != 0; r4 = (size % 12) != 0;
Rfu.unk_6c.owner = GetMultiplayerId(); Rfu.sendBlock.owner = GetMultiplayerId();
Rfu.unk_6c.sending = TRUE; Rfu.sendBlock.sending = TRUE;
Rfu.unk_6c.count = (size / 12) + r4; Rfu.sendBlock.count = (size / 12) + r4;
Rfu.unk_6c.next = 0; Rfu.sendBlock.next = 0;
if (size > 0x100) if (size > 0x100)
Rfu.unk_6c.payload = src; Rfu.sendBlock.payload = src;
else else
{ {
if (src != gBlockSendBuffer) if (src != gBlockSendBuffer)
memcpy(gBlockSendBuffer, src, size); memcpy(gBlockSendBuffer, src, size);
Rfu.unk_6c.payload = gBlockSendBuffer; Rfu.sendBlock.payload = gBlockSendBuffer;
} }
RfuPrepareSendBuffer(RFU_COMMAND_0x8800); RfuPrepareSendBuffer(RFU_COMMAND_0x8800);
Rfu.callback = HandleBlockSend; Rfu.callback = HandleBlockSend;
@ -1276,34 +1290,34 @@ static void HandleBlockSend(void)
static void SendNextBlock(void) static void SendNextBlock(void)
{ {
s32 i; s32 i;
const u8 *src = Rfu.unk_6c.payload; const u8 *src = Rfu.sendBlock.payload;
gSendCmd[0] = RFU_COMMAND_0x8900 | Rfu.unk_6c.next; gSendCmd[0] = RFU_COMMAND_0x8900 | Rfu.sendBlock.next;
for (i = 0; i < 7; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
gSendCmd[i + 1] = (src[(i << 1) + Rfu.unk_6c.next * 12 + 1] << 8) | src[(i << 1) + Rfu.unk_6c.next * 12 + 0]; gSendCmd[i + 1] = (src[(i << 1) + Rfu.sendBlock.next * 12 + 1] << 8) | src[(i << 1) + Rfu.sendBlock.next * 12 + 0];
Rfu.unk_6c.next++; Rfu.sendBlock.next++;
if (Rfu.unk_6c.count <= Rfu.unk_6c.next) if (Rfu.sendBlock.count <= Rfu.sendBlock.next)
{ {
Rfu.unk_6c.sending = FALSE; Rfu.sendBlock.sending = FALSE;
Rfu.callback = SendLastBlock; Rfu.callback = SendLastBlock;
} }
} }
static void SendLastBlock(void) static void SendLastBlock(void)
{ {
const u8 *src = Rfu.unk_6c.payload; const u8 *src = Rfu.sendBlock.payload;
u8 mpId = GetMultiplayerId(); u8 mpId = GetMultiplayerId();
s32 i; s32 i;
if (Rfu.parentChild == MODE_CHILD) if (Rfu.parentChild == MODE_CHILD)
{ {
gSendCmd[0] = RFU_COMMAND_0x8900 | (Rfu.unk_6c.count - 1); gSendCmd[0] = RFU_COMMAND_0x8900 | (Rfu.sendBlock.count - 1);
for (i = 0; i < 7; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
gSendCmd[i + 1] = (src[(i << 1) + (Rfu.unk_6c.count - 1) * 12 + 1] << 8) | src[(i << 1) + (Rfu.unk_6c.count - 1) * 12 + 0]; 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.unk_6c.count - 1) if ((u8)gRecvCmds[mpId][0] == Rfu.sendBlock.count - 1)
{ {
if (Rfu.unk_80[mpId].receivedFlags != sAllBlocksReceived[Rfu.unk_80[mpId].count]) if (Rfu.recvBlock[mpId].receivedFlags != sAllBlocksReceived[Rfu.recvBlock[mpId].count])
{ {
HandleSendFailure(mpId, Rfu.unk_80[mpId].receivedFlags); HandleSendFailure(mpId, Rfu.recvBlock[mpId].receivedFlags);
gUnknown_02022B44.unk_64++; sRfuDebug.unk_64++;
} }
else else
Rfu.callback = NULL; Rfu.callback = NULL;
@ -1898,7 +1912,7 @@ static void RfuCheckErrorStatus(void)
gWirelessCommType = 2; gWirelessCommType = 2;
SetMainCallback2(CB2_LinkError); SetMainCallback2(CB2_LinkError);
gMain.savedCallback = CB2_LinkError; gMain.savedCallback = CB2_LinkError;
sub_800AF18((Rfu.linkmanMsg << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.recvQueue.count, Rfu.sendQueue.count, RfuGetErrorStatus() == 2); BufferLinkErrorInfo((Rfu.linkmanMsg << 16) | (Rfu.unk_10 << 8) | Rfu.unk_12, Rfu.recvQueue.count, Rfu.sendQueue.count, RfuGetErrorStatus() == 2);
Rfu.errorState = 2; Rfu.errorState = 2;
CloseLink(); CloseLink();
} }
@ -1964,7 +1978,7 @@ static void CopyPlayerNameToUnameBuffer(void)
void ClearAndInitHostRFUtgtGname(void) void ClearAndInitHostRFUtgtGname(void)
{ {
memset(&gHostRFUtgtGnameBuffer, 0, RFU_GAME_NAME_LENGTH); 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) void SetHostRFUtgtGname(u8 activity, u32 child_sprite_genders, u32 started)
@ -2160,7 +2174,7 @@ static void sub_801120C(u8 msg, u8 paramCount)
case LMAN_MSG_RFU_FATAL_ERROR: case LMAN_MSG_RFU_FATAL_ERROR:
GetLinkmanErrorParams(msg); GetLinkmanErrorParams(msg);
RfuSetErrorStatus(1, msg); RfuSetErrorStatus(1, msg);
Rfu.unk_cdb = 1; Rfu.unk_cdb = TRUE;
break; break;
} }
} }
@ -2231,7 +2245,7 @@ void sub_8011404(u8 msg, u8 unused1)
case LMAN_MSG_RFU_FATAL_ERROR: case LMAN_MSG_RFU_FATAL_ERROR:
RfuSetErrorStatus(1, msg); RfuSetErrorStatus(1, msg);
GetLinkmanErrorParams(msg); GetLinkmanErrorParams(msg);
Rfu.unk_cdb = 1; Rfu.unk_cdb = TRUE;
break; break;
} }
} }
@ -2304,7 +2318,7 @@ static void sub_8011674(u8 msg, u8 paramCount)
Rfu.unk_ce4 = 2; Rfu.unk_ce4 = 2;
} }
} }
else if (GetHostRFUtgtGname()->activity == 0x54) else if (GetHostRFUtgtGname()->activity == (ACTIVITY_PLYRTALK | IN_UNION_ROOM))
{ {
rfu_REQ_disconnect(lman.acceptSlot_flag); rfu_REQ_disconnect(lman.acceptSlot_flag);
rfu_waitREQComplete(); rfu_waitREQComplete();
@ -2408,7 +2422,7 @@ static void sub_8011674(u8 msg, u8 paramCount)
case LMAN_MSG_RFU_FATAL_ERROR: case LMAN_MSG_RFU_FATAL_ERROR:
GetLinkmanErrorParams(msg); GetLinkmanErrorParams(msg);
RfuSetErrorStatus(1, msg); RfuSetErrorStatus(1, msg);
Rfu.unk_cdb = 0; Rfu.unk_cdb = FALSE;
break; break;
} }
} }

View File

@ -7,9 +7,20 @@
#include "text.h" #include "text.h"
#include "event_data.h" #include "event_data.h"
enum {
WIRELESS_STATUS_ANIM_3_BARS,
WIRELESS_STATUS_ANIM_2_BARS,
WIRELESS_STATUS_ANIM_1_BAR,
WIRELESS_STATUS_ANIM_SEARCHING,
WIRELESS_STATUS_ANIM_ERROR,
};
#define UNUSED_QUEUE_NUM_SLOTS 2
#define UNUSED_QUEUE_SLOT_LENGTH 256
struct RfuUnusedQueue struct RfuUnusedQueue
{ {
u8 slots[2][256]; u8 slots[UNUSED_QUEUE_NUM_SLOTS][UNUSED_QUEUE_SLOT_LENGTH];
vu8 recvSlot; vu8 recvSlot;
vu8 sendSlot; vu8 sendSlot;
vu8 count; vu8 count;
@ -234,8 +245,7 @@ static const struct OamData sWirelessStatusIndicatorOamData =
.paletteNum = 0, .paletteNum = 0,
}; };
static const union AnimCmd sWirelessStatusIndicatorAnim0[] = { static const union AnimCmd sWirelessStatusIndicator_3Bars[] = {
// 3 bars
ANIMCMD_FRAME( 4, 5), ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5), ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 5), ANIMCMD_FRAME(12, 5),
@ -245,8 +255,7 @@ static const union AnimCmd sWirelessStatusIndicatorAnim0[] = {
ANIMCMD_JUMP(0) ANIMCMD_JUMP(0)
}; };
static const union AnimCmd sWirelessStatusIndicatorAnim1[] = { static const union AnimCmd sWirelessStatusIndicator_2Bars[] = {
// 2 bars
ANIMCMD_FRAME( 4, 5), ANIMCMD_FRAME( 4, 5),
ANIMCMD_FRAME( 8, 5), ANIMCMD_FRAME( 8, 5),
ANIMCMD_FRAME(12, 10), ANIMCMD_FRAME(12, 10),
@ -254,33 +263,30 @@ static const union AnimCmd sWirelessStatusIndicatorAnim1[] = {
ANIMCMD_JUMP(0) ANIMCMD_JUMP(0)
}; };
static const union AnimCmd sWirelessStatusIndicatorAnim2[] = { static const union AnimCmd sWirelessStatusIndicator_1Bar[] = {
// 1 bar
ANIMCMD_FRAME(4, 5), ANIMCMD_FRAME(4, 5),
ANIMCMD_FRAME(8, 5), ANIMCMD_FRAME(8, 5),
ANIMCMD_JUMP(0) ANIMCMD_JUMP(0)
}; };
static const union AnimCmd sWirelessStatusIndicatorAnim3[] = { static const union AnimCmd sWirelessStatusIndicator_Searching[] = {
// searching
ANIMCMD_FRAME( 4, 10), ANIMCMD_FRAME( 4, 10),
ANIMCMD_FRAME(20, 10), ANIMCMD_FRAME(20, 10),
ANIMCMD_JUMP(0) ANIMCMD_JUMP(0)
}; };
static const union AnimCmd sWirelessStatusIndicatorAnim4[] = { static const union AnimCmd sWirelessStatusIndicator_Error[] = {
// error
ANIMCMD_FRAME(24, 10), ANIMCMD_FRAME(24, 10),
ANIMCMD_FRAME( 4, 10), ANIMCMD_FRAME( 4, 10),
ANIMCMD_JUMP(0) ANIMCMD_JUMP(0)
}; };
static const union AnimCmd *const sWirelessStatusIndicatorAnims[] = { static const union AnimCmd *const sWirelessStatusIndicatorAnims[] = {
sWirelessStatusIndicatorAnim0, [WIRELESS_STATUS_ANIM_3_BARS] = sWirelessStatusIndicator_3Bars,
sWirelessStatusIndicatorAnim1, [WIRELESS_STATUS_ANIM_2_BARS] = sWirelessStatusIndicator_2Bars,
sWirelessStatusIndicatorAnim2, [WIRELESS_STATUS_ANIM_1_BAR] = sWirelessStatusIndicator_1Bar,
sWirelessStatusIndicatorAnim3, [WIRELESS_STATUS_ANIM_SEARCHING] = sWirelessStatusIndicator_Searching,
sWirelessStatusIndicatorAnim4 [WIRELESS_STATUS_ANIM_ERROR] = sWirelessStatusIndicator_Error
}; };
static const struct CompressedSpriteSheet sWirelessStatusIndicatorSpriteSheet = { static const struct CompressedSpriteSheet sWirelessStatusIndicatorSpriteSheet = {
@ -292,13 +298,13 @@ static const struct SpritePalette sWirelessStatusIndicatorSpritePalette = {
}; };
static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = {
0xD431, .tileTag = 0xD431,
0xD432, .paletteTag = 0xD432,
&sWirelessStatusIndicatorOamData, .oam = &sWirelessStatusIndicatorOamData,
sWirelessStatusIndicatorAnims, .anims = sWirelessStatusIndicatorAnims,
NULL, .images = NULL,
gDummySpriteAffineAnimTable, .affineAnims = gDummySpriteAffineAnimTable,
SpriteCallbackDummy .callback = SpriteCallbackDummy
}; };
void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) void RfuRecvQueue_Reset(struct RfuRecvQueue *queue)
@ -306,9 +312,9 @@ void RfuRecvQueue_Reset(struct RfuRecvQueue *queue)
s32 i; s32 i;
s32 j; s32 j;
for (i = 0; i < 32; 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; queue->slots[i][j] = 0;
} }
@ -324,9 +330,9 @@ void RfuSendQueue_Reset(struct RfuSendQueue *queue)
s32 i; s32 i;
s32 j; 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++)
{ {
queue->slots[i][j] = 0; queue->slots[i][j] = 0;
} }
@ -342,9 +348,9 @@ static void RfuUnusedQueue_Reset(struct RfuUnusedQueue *queue)
s32 i; s32 i;
s32 j; 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++)
{ {
queue->slots[i][j] = 0; queue->slots[i][j] = 0;
} }
@ -361,31 +367,27 @@ void RfuRecvQueue_Enqueue(struct RfuRecvQueue *queue, u8 *data)
u16 imeBak; u16 imeBak;
u8 count; u8 count;
if (queue->count < 32) if (queue->count < RECV_QUEUE_NUM_SLOTS)
{ {
imeBak = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
count = 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 (data[i] == 0 && data[i + 1] == 0)
{
count++; 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->recvSlot][i] = data[i]; queue->slots[queue->recvSlot][i] = data[i];
}
queue->recvSlot++; queue->recvSlot++;
queue->recvSlot %= 32; queue->recvSlot %= RECV_QUEUE_NUM_SLOTS;
queue->count++; queue->count++;
for (i = 0; i < 70; i++)
{ for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++)
data[i] = 0; data[i] = 0;
}
} }
REG_IME = imeBak; REG_IME = imeBak;
} }
@ -400,30 +402,27 @@ void RfuSendQueue_Enqueue(struct RfuSendQueue *queue, u8 *data)
s32 i; s32 i;
u16 imeBak; u16 imeBak;
if (queue->count < 40) if (queue->count < SEND_QUEUE_NUM_SLOTS)
{ {
imeBak = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
for (i = 0; i < 14; i++) for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++)
{ {
if (data[i] != 0) if (data[i] != 0)
{
break; 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->recvSlot][i] = data[i]; queue->slots[queue->recvSlot][i] = data[i];
} }
queue->recvSlot++; queue->recvSlot++;
queue->recvSlot %= 40; queue->recvSlot %= SEND_QUEUE_NUM_SLOTS;
queue->count++; queue->count++;
for (i = 0; i < 14; i++)
{ for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++)
data[i] = 0; data[i] = 0;
}
} }
REG_IME = imeBak; REG_IME = imeBak;
} }
@ -442,19 +441,18 @@ bool8 RfuRecvQueue_Dequeue(struct RfuRecvQueue *queue, u8 *src)
REG_IME = 0; REG_IME = 0;
if (queue->recvSlot == queue->sendSlot || queue->full) if (queue->recvSlot == queue->sendSlot || queue->full)
{ {
for (i = 0; i < 70; i++) for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++)
{
src[i] = 0; src[i] = 0;
}
REG_IME = imeBak; REG_IME = imeBak;
return FALSE; return FALSE;
} }
for (i = 0; i < 70; i++) for (i = 0; i < RECV_QUEUE_SLOT_LENGTH; i++)
{ {
src[i] = queue->slots[queue->sendSlot][i]; src[i] = queue->slots[queue->sendSlot][i];
} }
queue->sendSlot++; queue->sendSlot++;
queue->sendSlot %= 32; queue->sendSlot %= RECV_QUEUE_NUM_SLOTS;
queue->count--; queue->count--;
REG_IME = imeBak; REG_IME = imeBak;
return TRUE; return TRUE;
@ -470,12 +468,11 @@ bool8 RfuSendQueue_Dequeue(struct RfuSendQueue *queue, u8 *src)
imeBak = REG_IME; imeBak = REG_IME;
REG_IME = 0; REG_IME = 0;
for (i = 0; i < 14; i++) for (i = 0; i < SEND_QUEUE_SLOT_LENGTH; i++)
{
src[i] = queue->slots[queue->sendSlot][i]; src[i] = queue->slots[queue->sendSlot][i];
}
queue->sendSlot++; queue->sendSlot++;
queue->sendSlot %= 40; queue->sendSlot %= SEND_QUEUE_NUM_SLOTS;
queue->count--; queue->count--;
REG_IME = imeBak; REG_IME = imeBak;
return TRUE; return TRUE;
@ -491,20 +488,16 @@ void RfuBackupQueue_Enqueue(struct RfuBackupQueue *queue, const u8 *data)
} }
else else
{ {
for (i = 0; i < 14; i++) for (i = 0; i < BACKUP_QUEUE_SLOT_LENGTH; i++)
{
queue->slots[queue->recvSlot][i] = data[i]; queue->slots[queue->recvSlot][i] = data[i];
}
queue->recvSlot++; queue->recvSlot++;
queue->recvSlot %= 2; queue->recvSlot %= BACKUP_QUEUE_NUM_SLOTS;
if (queue->count < 2)
{ if (queue->count < BACKUP_QUEUE_NUM_SLOTS)
queue->count++; queue->count++;
}
else else
{
queue->sendSlot = queue->recvSlot; queue->sendSlot = queue->recvSlot;
}
} }
} }
@ -517,13 +510,11 @@ bool8 RfuBackupQueue_Dequeue(struct RfuBackupQueue *queue, u8 *src)
if (src != NULL) if (src != NULL)
{ {
for (i = 0; i < 14; i++) for (i = 0; i < BACKUP_QUEUE_SLOT_LENGTH; i++)
{
src[i] = queue->slots[queue->sendSlot][i]; src[i] = queue->slots[queue->sendSlot][i];
}
} }
queue->sendSlot++; queue->sendSlot++;
queue->sendSlot %= 2; queue->sendSlot %= BACKUP_QUEUE_NUM_SLOTS;
queue->count--; queue->count--;
return TRUE; return TRUE;
} }
@ -532,14 +523,13 @@ static void RfuUnusedQueue_Enqueue(struct RfuUnusedQueue *queue, u8 *data)
{ {
s32 i; 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->recvSlot][i] = data[i]; queue->slots[queue->recvSlot][i] = data[i];
}
queue->recvSlot++; queue->recvSlot++;
queue->recvSlot %= 2; queue->recvSlot %= UNUSED_QUEUE_NUM_SLOTS;
queue->count++; queue->count++;
} }
else else
@ -555,17 +545,17 @@ static bool8 RfuUnusedQueue_Dequeue(struct RfuUnusedQueue *queue, u8 *dest)
if (queue->recvSlot == queue->sendSlot || queue->full) if (queue->recvSlot == queue->sendSlot || queue->full)
return FALSE; return FALSE;
for (i = 0; i < 256; i++) for (i = 0; i < UNUSED_QUEUE_SLOT_LENGTH; i++)
{
dest[i] = queue->slots[queue->sendSlot][i]; dest[i] = queue->slots[queue->sendSlot][i];
}
queue->sendSlot++; queue->sendSlot++;
queue->sendSlot %= 2; queue->sendSlot %= UNUSED_QUEUE_NUM_SLOTS;
queue->count--; queue->count--;
return TRUE; return TRUE;
} }
void sub_800DBF8(u8 *q1, u8 mode) // Unused
static void sub_800DBF8(u8 *q1, u8 mode)
{ {
s32 i; s32 i;
u8 rval; u8 rval;
@ -797,7 +787,7 @@ bool8 LinkRfu_GetNameIfCompatible(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx) bool8 LinkRfu_GetNameIfSerial7F7D(struct GFtgtGname *buff1, u8 *buff2, u8 idx)
{ {
bool8 retVal = FALSE; bool8 retVal = FALSE;
if (gRfuLinkStatus->partner[idx].serialNo == 0x7F7D) if (gRfuLinkStatus->partner[idx].serialNo == RFU_SERIAL_7F7D)
{ {
memcpy(buff1, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH); memcpy(buff1, gRfuLinkStatus->partner[idx].gname, RFU_GAME_NAME_LENGTH);
memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1); memcpy(buff2, gRfuLinkStatus->partner[idx].uname, PLAYER_NAME_LENGTH + 1);
@ -817,6 +807,15 @@ void LinkRfu3_SetGnameUnameFromStaticBuffers(struct GFtgtGname *buff1, u8 *buff2
memcpy(buff2, gHostRFUtgtUnameBuffer, PLAYER_NAME_LENGTH + 1); memcpy(buff2, gHostRFUtgtUnameBuffer, PLAYER_NAME_LENGTH + 1);
} }
#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) void CreateWirelessStatusIndicatorSprite(u8 x, u8 y)
{ {
u8 sprId; u8 sprId;
@ -829,25 +828,25 @@ void CreateWirelessStatusIndicatorSprite(u8 x, u8 y)
if (gRfuLinkStatus->parentChild == MODE_PARENT) if (gRfuLinkStatus->parentChild == MODE_PARENT)
{ {
sprId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0); sprId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[sprId].data[7] = 0x1234; gSprites[sprId].sValidator = STATUS_INDICATOR_ACTIVE;
gSprites[sprId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); gSprites[sprId].sTileStart = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[sprId].invisible = TRUE; gSprites[sprId].invisible = TRUE;
gWirelessStatusIndicatorSpriteId = sprId; gWirelessStatusIndicatorSpriteId = sprId;
} }
else else
{ {
gWirelessStatusIndicatorSpriteId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0); gWirelessStatusIndicatorSpriteId = CreateSprite(&sWirelessStatusIndicatorSpriteTemplate, x, y, 0);
gSprites[gWirelessStatusIndicatorSpriteId].data[7] = 0x1234; gSprites[gWirelessStatusIndicatorSpriteId].sValidator = STATUS_INDICATOR_ACTIVE;
gSprites[gWirelessStatusIndicatorSpriteId].data[6] = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag); gSprites[gWirelessStatusIndicatorSpriteId].sTileStart = GetSpriteTileStartByTag(sWirelessStatusIndicatorSpriteSheet.tag);
gSprites[gWirelessStatusIndicatorSpriteId].invisible = TRUE; gSprites[gWirelessStatusIndicatorSpriteId].invisible = TRUE;
} }
} }
void DestroyWirelessStatusIndicatorSprite(void) 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]); DestroySprite(&gSprites[gWirelessStatusIndicatorSpriteId]);
gMain.oamBuffer[125] = gDummyOamData; gMain.oamBuffer[125] = gDummyOamData;
CpuCopy16(&gDummyOamData, (struct OamData *)OAM + 125, sizeof(struct OamData)); CpuCopy16(&gDummyOamData, (struct OamData *)OAM + 125, sizeof(struct OamData));
@ -879,19 +878,19 @@ static u8 GetParentSignalStrength(void)
return 0; return 0;
} }
static void SetWirelessStatusIndicatorAnim(struct Sprite *sprite, s32 signalStrengthAnimNum) static void SetWirelessStatusIndicatorAnim(struct Sprite *sprite, s32 animNum)
{ {
if (sprite->data[2] != signalStrengthAnimNum) if (sprite->sCurrAnimNum != animNum)
{ {
sprite->data[2] = signalStrengthAnimNum; sprite->sCurrAnimNum = animNum;
sprite->data[3] = 0; sprite->sFrameDelay = 0;
sprite->data[4] = 0; sprite->sFrameIdx = 0;
} }
} }
void UpdateWirelessStatusIndicatorSprite(void) 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]; struct Sprite *sprite = &gSprites[gWirelessStatusIndicatorSpriteId];
u8 signalStrength = RFU_LINK_ICON_LEVEL4_MAX; u8 signalStrength = RFU_LINK_ICON_LEVEL4_MAX;
@ -912,47 +911,47 @@ void UpdateWirelessStatusIndicatorSprite(void)
} }
if (IsRfuRecoveringFromLinkLoss() == TRUE) if (IsRfuRecoveringFromLinkLoss() == TRUE)
{ {
sprite->data[0] = 4; sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_ERROR;
} }
else if (signalStrength <= RFU_LINK_ICON_LEVEL1_MAX) else if (signalStrength <= RFU_LINK_ICON_LEVEL1_MAX)
{ {
sprite->data[0] = 3; sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_SEARCHING;
} }
else if (signalStrength >= RFU_LINK_ICON_LEVEL2_MIN && signalStrength <= RFU_LINK_ICON_LEVEL2_MAX) else if (signalStrength >= RFU_LINK_ICON_LEVEL2_MIN && signalStrength <= RFU_LINK_ICON_LEVEL2_MAX)
{ {
sprite->data[0] = 2; sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_1_BAR;
} }
else if (signalStrength >= RFU_LINK_ICON_LEVEL3_MIN && signalStrength <= RFU_LINK_ICON_LEVEL3_MAX) else if (signalStrength >= RFU_LINK_ICON_LEVEL3_MIN && signalStrength <= RFU_LINK_ICON_LEVEL3_MAX)
{ {
sprite->data[0] = 1; sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_2_BARS;
} }
else if (signalStrength >= RFU_LINK_ICON_LEVEL4_MIN) else if (signalStrength >= RFU_LINK_ICON_LEVEL4_MIN)
{ {
sprite->data[0] = 0; sprite->sNextAnimNum = WIRELESS_STATUS_ANIM_3_BARS;
} }
if (sprite->data[0] != sprite->data[1]) if (sprite->sNextAnimNum != sprite->sSavedAnimNum)
{ {
SetWirelessStatusIndicatorAnim(sprite, sprite->data[0]); SetWirelessStatusIndicatorAnim(sprite, sprite->sNextAnimNum);
sprite->data[1] = sprite->data[0]; 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->sFrameIdx++;
sprite->data[3] = 0; sprite->sFrameDelay = 0;
if (sprite->anims[sprite->data[2]][sprite->data[4]].type == -2) if (sprite->anims[sprite->sCurrAnimNum][sprite->sFrameIdx].type == -2)
{ {
sprite->data[4] = 0; sprite->sFrameIdx = 0;
} }
} }
else else
{ {
sprite->data[3]++; sprite->sFrameDelay++;
} }
gMain.oamBuffer[125] = sWirelessStatusIndicatorOamData; gMain.oamBuffer[125] = sWirelessStatusIndicatorOamData;
gMain.oamBuffer[125].x = sprite->pos1.x + sprite->centerToCornerVecX; gMain.oamBuffer[125].x = sprite->pos1.x + sprite->centerToCornerVecX;
gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY; gMain.oamBuffer[125].y = sprite->pos1.y + sprite->centerToCornerVecY;
gMain.oamBuffer[125].paletteNum = sprite->oam.paletteNum; 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)); CpuCopy16(gMain.oamBuffer + 125, (struct OamData *)OAM + 125, sizeof(struct OamData));
if (RfuGetErrorStatus() == 1) if (RfuGetErrorStatus() == 1)
{ {
@ -961,6 +960,14 @@ void UpdateWirelessStatusIndicatorSprite(void)
} }
} }
#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) static void CopyTrainerRecord(struct TrainerNameRecord *dest, u32 trainerId, const u8 *name)
{ {
dest->trainerId = trainerId; dest->trainerId = trainerId;
@ -988,7 +995,7 @@ void RecordMixTrainerNames(void)
s32 j; s32 j;
s32 nextSpace; s32 nextSpace;
s32 connectedTrainerRecordIndices[5]; s32 connectedTrainerRecordIndices[5];
struct TrainerNameRecord *newRecords = calloc(20, sizeof(struct TrainerNameRecord)); struct TrainerNameRecord *newRecords = calloc(ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords), sizeof(struct TrainerNameRecord));
// Check if we already have a record saved for connected trainers. // Check if we already have a record saved for connected trainers.
for (i = 0; i < GetLinkPlayerCount(); i++) for (i = 0; i < GetLinkPlayerCount(); i++)

View File

@ -231,7 +231,7 @@ static void PrepareExchangePacket(void)
if (Link_AnyPartnersPlayingRubyOrSapphire()) if (Link_AnyPartnersPlayingRubyOrSapphire())
{ {
if (sub_800A03C() == 0) if (LinkDummy_Return2() == 0)
PrepareUnknownExchangePacket(&sSentRecord->ruby); PrepareUnknownExchangePacket(&sSentRecord->ruby);
else else
PrepareExchangePacketForRubySapphire(&sSentRecord->ruby); PrepareExchangePacketForRubySapphire(&sSentRecord->ruby);
@ -526,7 +526,7 @@ static void Task_CopyReceiveBuffer(u8 taskId)
u8 status = GetBlockReceivedStatus(); u8 status = GetBlockReceivedStatus();
u8 handledPlayers = 0; u8 handledPlayers = 0;
if (status == sub_800A9D8()) if (status == GetLinkPlayerCountAsBitFlags())
{ {
u8 i; u8 i;

View File

@ -1237,7 +1237,7 @@ static void Task_SaveAfterLinkBattle(u8 taskId)
if (gWirelessCommType != 0 && InUnionRoom()) if (gWirelessCommType != 0 && InUnionRoom())
{ {
if (sub_800A07C()) if (Link_AnyPartnersPlayingFRLG_JP())
{ {
*state = 1; *state = 1;
} }

View File

@ -1361,7 +1361,7 @@ static void Task_ExchangeCards(u8 taskId)
gTasks[taskId].data[0]++; gTasks[taskId].data[0]++;
break; break;
case 1: case 1:
if (GetBlockReceivedStatus() == sub_800A9D8()) if (GetBlockReceivedStatus() == GetLinkPlayerCountAsBitFlags())
{ {
s32 i; s32 i;
u16 *recvBuff; u16 *recvBuff;