Done documenting link code in overworld.c

This commit is contained in:
Phlosioneer 2019-02-10 03:54:50 -05:00
parent 3fd878483f
commit f2f1b1978b
18 changed files with 380 additions and 346 deletions

View File

@ -12,7 +12,7 @@ sub_81C7078: @ 81C7078
push {r4,r5,lr} push {r4,r5,lr}
adds r5, r0, 0 adds r5, r0, 0
adds r4, r1, 0 adds r4, r1, 0
bl is_c1_link_related_active bl IsUpdateLinkStateCBActive
cmp r0, 0 cmp r0, 0
bne _081C7090 bne _081C7090
ldr r0, =sub_81C7170 ldr r0, =sub_81C7170

View File

@ -1,8 +1,8 @@
gBGTilemapBuffers1 gBGTilemapBuffers1
gBGTilemapBuffers2 gBGTilemapBuffers2
gBGTilemapBuffers3 gBGTilemapBuffers3
gUnknown_03005DA8 gHeldKeyCodeToSend
gFieldCallback gFieldCallback
gFieldCallback2 gFieldCallback2
gLinkGuestPlayerId gLinkSelfPlayerId
gFieldLinkPlayerCount gFieldLinkPlayerCount

View File

@ -967,7 +967,7 @@ RecordCorner_EventScript_2774E0:: @ 82774E0
closemessage closemessage
end end
gUnknown_082774EF:: @ 82774EF gEventScript_ConfirmLeaveTradeRoom:: @ 82774EF
msgbox Text_2783A8, MSGBOX_YESNO msgbox Text_2783A8, MSGBOX_YESNO
compare VAR_RESULT, 1 compare VAR_RESULT, 1
goto_if_eq gUnknown_08277509 goto_if_eq gUnknown_08277509

View File

@ -907,13 +907,13 @@ struct MapPosition
s8 height; s8 height;
}; };
struct TradeRoomTrainer struct TradeRoomPlayer
{ {
u8 a; u8 playerId;
u8 b; u8 isSelf;
u8 c; u8 c;
u8 facing; u8 facing;
struct MapPosition sub; struct MapPosition pos;
u16 field_C; u16 field_C;
}; };

View File

@ -312,7 +312,7 @@ void sub_800AB18(void);
void sub_8009F18(void); void sub_8009F18(void);
bool8 sub_800AA60(void); bool8 sub_800AA60(void);
void sub_800ABF4(u16 a0); void sub_800ABF4(u16 a0);
bool32 sub_8009F3C(void); bool32 IsSendingKeysToLink(void);
u32 sub_800B4DC(void); u32 GetLinkRecvQueueLength(void);
#endif // GUARD_LINK_H #endif // GUARD_LINK_H

View File

@ -218,7 +218,7 @@ void sub_800E700(void);
void sub_800EDD4(void); void sub_800EDD4(void);
void sub_800F6FC(u8 who); void sub_800F6FC(u8 who);
void sub_800F728(u8 who); void sub_800F728(u8 who);
bool32 sub_800F7E4(void); bool32 IsSendingKeysToRfu(void);
void sub_800F804(void); void sub_800F804(void);
void sub_800F850(void); void sub_800F850(void);
u8 sub_800FCD8(void); u8 sub_800FCD8(void);
@ -237,8 +237,8 @@ void sub_800E6D0(void);
bool32 sub_8010EC0(void); bool32 sub_8010EC0(void);
bool32 sub_8010F1C(void); bool32 sub_8010F1C(void);
bool32 sub_8011A80(void); bool32 sub_8011A80(void);
bool32 sub_800F0B8(void); bool32 IsRfuRecvQueueEmpty(void);
u32 sub_80124D4(void); u32 GetRfuRecvQueueLength(void);
void RfuVSync(void); void RfuVSync(void);
void sub_80111B0(bool32 a0); void sub_80111B0(bool32 a0);
u8 sub_8011A74(void); u8 sub_8011A74(void);

View File

@ -1,6 +1,18 @@
#ifndef GUARD_OVERWORLD_H #ifndef GUARD_OVERWORLD_H
#define GUARD_OVERWORLD_H #define GUARD_OVERWORLD_H
#define LINK_KEY_CODE_NULL 0x00
#define LINK_KEY_CODE_EMPTY 0x11
#define LINK_KEY_CODE_DPAD_DOWN 0x12
#define LINK_KEY_CODE_DPAD_UP 0x13
#define LINK_KEY_CODE_DPAD_LEFT 0x14
#define LINK_KEY_CODE_DPAD_RIGHT 0x15
#define LINK_KEY_CODE_UNK_2 0x16
#define LINK_KEY_CODE_UNK_3 0x17
#define LINK_KEY_CODE_START_BUTTON 0x18
#define LINK_KEY_CODE_A_BUTTON 0x19
#define LINK_KEY_CODE_UNK_4 0x1A // I'd guess this is the B button?
struct InitialPlayerAvatarState struct InitialPlayerAvatarState
{ {
u8 transitionFlags; u8 transitionFlags;
@ -22,10 +34,10 @@ extern struct LinkPlayerEventObject gLinkPlayerEventObjects[4];
extern u16 *gBGTilemapBuffers1; extern u16 *gBGTilemapBuffers1;
extern u16 *gBGTilemapBuffers2; extern u16 *gBGTilemapBuffers2;
extern u16 *gBGTilemapBuffers3; extern u16 *gBGTilemapBuffers3;
extern u16 gUnknown_03005DA8; extern u16 gHeldKeyCodeToSend;
extern void (*gFieldCallback)(void); extern void (*gFieldCallback)(void);
extern bool8 (*gFieldCallback2)(void); extern bool8 (*gFieldCallback2)(void);
extern u8 gLinkGuestPlayerId; extern u8 gLinkSelfPlayerId;
extern u8 gFieldLinkPlayerCount; extern u8 gFieldLinkPlayerCount;
// Exported ROM declarations // Exported ROM declarations
@ -103,7 +115,7 @@ u8 GetSavedWarpRegionMapSectionId(void);
u8 GetCurrentRegionMapSectionId(void); u8 GetCurrentRegionMapSectionId(void);
u8 GetCurrentMapBattleScene(void); u8 GetCurrentMapBattleScene(void);
void CleanupOverworldWindowsAndTilemaps(void); void CleanupOverworldWindowsAndTilemaps(void);
bool32 is_c1_link_related_active(void); bool32 IsUpdateLinkStateCBActive(void);
void CB1_Overworld(void); void CB1_Overworld(void);
void CB2_OverworldBasic(void); void CB2_OverworldBasic(void);
void CB2_Overworld(void); void CB2_Overworld(void);
@ -117,13 +129,13 @@ void sub_8086074(void);
void CB2_ReturnToField(void); void CB2_ReturnToField(void);
void CB2_ReturnToFieldLocal(void); void CB2_ReturnToFieldLocal(void);
void CB2_ReturnToFieldLink(void); void CB2_ReturnToFieldLink(void);
void c2_8056854(void); void CB2_ReturnToFieldFromMultiplayer(void);
void CB2_ReturnToFieldWithOpenMenu(void); void CB2_ReturnToFieldWithOpenMenu(void);
void CB2_ReturnToFieldContinueScript(void); void CB2_ReturnToFieldContinueScript(void);
void CB2_ReturnToFieldContinueScriptPlayMapMusic(void); void CB2_ReturnToFieldContinueScriptPlayMapMusic(void);
void sub_80861E8(void); void sub_80861E8(void);
void CB2_ContinueSavedGame(void); void CB2_ContinueSavedGame(void);
void sub_8086C2C(void); void ResetAllMultiplayerState(void);
u32 sub_8087214(void); u32 sub_8087214(void);
bool32 sub_808727C(void); bool32 sub_808727C(void);
u16 sub_8087288(void); u16 sub_8087288(void);

View File

@ -352,7 +352,7 @@ static void sub_80B2918(u8 taskId)
else else
{ {
gFieldLinkPlayerCount = GetLinkPlayerCount_2(); gFieldLinkPlayerCount = GetLinkPlayerCount_2();
gLinkGuestPlayerId = GetMultiplayerId(); gLinkSelfPlayerId = GetMultiplayerId();
sub_800AA04(gFieldLinkPlayerCount); sub_800AA04(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer; card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card); TrainerCard_GenerateCardForPlayer(card);
@ -399,7 +399,7 @@ static void sub_80B2A08(u8 taskId)
else else
{ {
gFieldLinkPlayerCount = GetLinkPlayerCount_2(); gFieldLinkPlayerCount = GetLinkPlayerCount_2();
gLinkGuestPlayerId = GetMultiplayerId(); gLinkSelfPlayerId = GetMultiplayerId();
sub_800AA04(gFieldLinkPlayerCount); sub_800AA04(gFieldLinkPlayerCount);
card = (struct TrainerCard *)gBlockSendBuffer; card = (struct TrainerCard *)gBlockSendBuffer;
TrainerCard_GenerateCardForPlayer(card); TrainerCard_GenerateCardForPlayer(card);
@ -972,7 +972,7 @@ void sub_80B360C(void)
if (gSpecialVar_0x8004 == 1 || gSpecialVar_0x8004 == 2) if (gSpecialVar_0x8004 == 1 || gSpecialVar_0x8004 == 2)
{ {
UpdatePlayerLinkBattleRecords(gLinkGuestPlayerId ^ 1); UpdatePlayerLinkBattleRecords(gLinkSelfPlayerId ^ 1);
if (gWirelessCommType) if (gWirelessCommType)
{ {
switch (gBattleOutcome) switch (gBattleOutcome)
@ -993,7 +993,7 @@ void sub_80B360C(void)
} }
else else
{ {
gMain.savedCallback = c2_8056854; gMain.savedCallback = CB2_ReturnToFieldFromMultiplayer;
} }
SetMainCallback2(sub_80A0514); SetMainCallback2(sub_80A0514);

View File

@ -146,7 +146,7 @@ static void sub_811A2A4(u8 taskId, TaskFunc taskFunc)
static void sub_811A2C0(u8 taskId) static void sub_811A2C0(u8 taskId)
{ {
if (!is_c1_link_related_active()) if (!IsUpdateLinkStateCBActive())
{ {
while (sub_811A428(taskId)); while (sub_811A428(taskId));
} }

View File

@ -255,7 +255,7 @@ void sub_80AF2B4(u8 taskId)
break; break;
case 2: case 2:
sub_8009F18(); sub_8009F18();
sub_8086C2C(); ResetAllMultiplayerState();
ScriptContext2_Disable(); ScriptContext2_Disable();
DestroyTask(taskId); DestroyTask(taskId);
break; break;

View File

@ -28,7 +28,7 @@
#include "link.h" #include "link.h"
#include "link_rfu.h" #include "link_rfu.h"
extern u16 gUnknown_03005DA8; extern u16 gHeldKeyCodeToSend;
// Static type declarations // Static type declarations
@ -695,12 +695,12 @@ static void BuildSendCmd(u16 command)
gSendCmd[0] = LINKCMD_0x5566; gSendCmd[0] = LINKCMD_0x5566;
break; break;
case LINKCMD_SEND_HELD_KEYS_2: case LINKCMD_SEND_HELD_KEYS_2:
if (gUnknown_03005DA8 == 0 || gLinkTransferringData) if (gHeldKeyCodeToSend == 0 || gLinkTransferringData)
{ {
break; break;
} }
gSendCmd[0] = LINKCMD_SEND_HELD_KEYS_2; gSendCmd[0] = LINKCMD_SEND_HELD_KEYS_2;
gSendCmd[1] = gUnknown_03005DA8; gSendCmd[1] = gHeldKeyCodeToSend;
break; break;
} }
} }
@ -714,11 +714,11 @@ void sub_8009F18(void)
gLinkCallback = sub_8009F70; gLinkCallback = sub_8009F70;
} }
bool32 sub_8009F3C(void) bool32 IsSendingKeysToLink(void)
{ {
if (gWirelessCommType) if (gWirelessCommType)
{ {
return sub_800F7E4(); return IsSendingKeysToRfu();
} }
if (gLinkCallback == sub_8009F70) if (gLinkCallback == sub_8009F70)
{ {
@ -1849,7 +1849,7 @@ bool8 HandleLinkConnection(void)
r5 = sub_8010F1C(); r5 = sub_8010F1C();
if (sub_808766C() == TRUE) if (sub_808766C() == TRUE)
{ {
if (r4 == TRUE || sub_800F0B8() || r5) if (r4 == TRUE || IsRfuRecvQueueEmpty() || r5)
{ {
return TRUE; return TRUE;
} }
@ -1882,18 +1882,18 @@ void sub_800B4C0(void)
} }
} }
u32 sub_800B4DC(void) u32 GetLinkRecvQueueLength(void)
{ {
if (gWirelessCommType != 0) if (gWirelessCommType != 0)
{ {
return sub_80124D4(); return GetRfuRecvQueueLength();
} }
return gLink.recvQueue.count; return gLink.recvQueue.count;
} }
bool8 sub_800B504(void) bool8 sub_800B504(void)
{ {
if (sub_800B4DC() > 2) if (GetLinkRecvQueueLength() > 2)
{ {
return TRUE; return TRUE;
} }

View File

@ -17,7 +17,7 @@
#include "text.h" #include "text.h"
#include "constants/species.h" #include "constants/species.h"
extern u16 gUnknown_03005DA8; extern u16 gHeldKeyCodeToSend;
extern void nullsub_89(u8 taskId); extern void nullsub_89(u8 taskId);
struct UnkRfuStruct_1 gUnknown_03004140; struct UnkRfuStruct_1 gUnknown_03004140;
@ -2978,7 +2978,7 @@ static void sub_800F048(void)
} }
} }
bool32 sub_800F0B8(void) bool32 IsRfuRecvQueueEmpty(void)
{ {
s32 i; s32 i;
s32 j; s32 j;
@ -3199,7 +3199,7 @@ bool32 sub_800F4F0(void)
for (i = 0; i < CMD_LENGTH - 1; i++) for (i = 0; i < CMD_LENGTH - 1; i++)
gSendCmd[i] = 0; gSendCmd[i] = 0;
} }
return sub_800F0B8(); return IsRfuRecvQueueEmpty();
} }
void sub_800F638(u8 unused, u32 flags) void sub_800F638(u8 unused, u32 flags)
@ -3259,10 +3259,12 @@ u8 sub_800F74C(const u8 *a0)
void rfu_func_080F97B8(void) void rfu_func_080F97B8(void)
{ {
if (gReceivedRemoteLinkPlayers && gUnknown_03005DA8 && gLinkTransferringData != 1) if (gReceivedRemoteLinkPlayers
&& gHeldKeyCodeToSend != LINK_KEY_CODE_NULL
&& gLinkTransferringData != TRUE)
{ {
gUnknown_03000D78[0]++; gUnknown_03000D78[0]++;
gUnknown_03005DA8 |= (gUnknown_03000D78[0] << 8); gHeldKeyCodeToSend |= (gUnknown_03000D78[0] << 8);
sub_800FD14(0xbe00); sub_800FD14(0xbe00);
} }
} }
@ -3272,7 +3274,7 @@ struct UnkLinkRfuStruct_02022B14 *sub_800F7DC(void)
return &gUnknown_02022B14; return &gUnknown_02022B14;
} }
bool32 sub_800F7E4(void) bool32 IsSendingKeysToRfu(void)
{ {
return gUnknown_03005000.unk_00 == rfu_func_080F97B8; return gUnknown_03005000.unk_00 == rfu_func_080F97B8;
} }
@ -3496,7 +3498,7 @@ void sub_800FD14(u16 command)
gSendCmd[1 + i] = gUnknown_03005000.unk_f2[i]; gSendCmd[1 + i] = gUnknown_03005000.unk_f2[i];
break; break;
case 0xbe00: case 0xbe00:
gSendCmd[1] = gUnknown_03005DA8; gSendCmd[1] = gHeldKeyCodeToSend;
break; break;
case 0xee00: case 0xee00:
break; break;
@ -5150,7 +5152,7 @@ u32 sub_80124C0(void)
return gUnknown_03005000.unk_9e8.unk_232; return gUnknown_03005000.unk_9e8.unk_232;
} }
u32 sub_80124D4(void) u32 GetRfuRecvQueueLength(void)
{ {
return gUnknown_03005000.unk_124.unk_8c2; return gUnknown_03005000.unk_124.unk_8c2;
} }

View File

@ -293,7 +293,7 @@ bool8 sub_8122148(u16 itemId)
bool8 itemid_80BF6D8_mail_related(u16 itemId) bool8 itemid_80BF6D8_mail_related(u16 itemId)
{ {
if (is_c1_link_related_active() != TRUE && InUnionRoom() != TRUE) if (IsUpdateLinkStateCBActive() != TRUE && InUnionRoom() != TRUE)
return TRUE; return TRUE;
else if (ItemIsMail(itemId) != TRUE) else if (ItemIsMail(itemId) != TRUE)
return TRUE; return TRUE;
@ -303,7 +303,7 @@ bool8 itemid_80BF6D8_mail_related(u16 itemId)
bool8 sub_81221AC(void) bool8 sub_81221AC(void)
{ {
if (is_c1_link_related_active() == TRUE || gReceivedRemoteLinkPlayers == 1) if (IsUpdateLinkStateCBActive() == TRUE || gReceivedRemoteLinkPlayers == 1)
return TRUE; return TRUE;
else else
return FALSE; return FALSE;

File diff suppressed because it is too large Load Diff

View File

@ -188,7 +188,7 @@ extern u8 gUnknown_02022C3E;
extern u16 gUnknown_02022C3C; extern u16 gUnknown_02022C3C;
extern u8 gUnknown_02022C20[]; extern u8 gUnknown_02022C20[];
extern u8 gFieldLinkPlayerCount; extern u8 gFieldLinkPlayerCount;
extern u8 gLinkGuestPlayerId; extern u8 gLinkSelfPlayerId;
// IWRAM vars // IWRAM vars
IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0; IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0;
@ -1641,7 +1641,7 @@ void sub_8014304(s8 mapGroup, s8 mapNum, s32 x, s32 y, u16 arg4)
gSpecialVar_0x8004 = arg4; gSpecialVar_0x8004 = arg4;
VarSet(VAR_0x4087, arg4); VarSet(VAR_0x4087, arg4);
gFieldLinkPlayerCount = GetLinkPlayerCount(); gFieldLinkPlayerCount = GetLinkPlayerCount();
gLinkGuestPlayerId = GetMultiplayerId(); gLinkSelfPlayerId = GetMultiplayerId();
SetCableClubWarp(); SetCableClubWarp();
SetWarpDestination(mapGroup, mapNum, -1, x, y); SetWarpDestination(mapGroup, mapNum, -1, x, y);
WarpIntoMap(); WarpIntoMap();

View File

@ -1203,7 +1203,7 @@ bool8 ScrCmd_turnvobject(struct ScriptContext *ctx)
bool8 ScrCmd_lockall(struct ScriptContext *ctx) bool8 ScrCmd_lockall(struct ScriptContext *ctx)
{ {
if (is_c1_link_related_active()) if (IsUpdateLinkStateCBActive())
{ {
return FALSE; return FALSE;
} }
@ -1217,7 +1217,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx)
bool8 ScrCmd_lock(struct ScriptContext *ctx) bool8 ScrCmd_lock(struct ScriptContext *ctx)
{ {
if (is_c1_link_related_active()) if (IsUpdateLinkStateCBActive())
{ {
return FALSE; return FALSE;
} }
@ -2182,7 +2182,7 @@ bool8 ScrCmd_cmdD8(struct ScriptContext *ctx)
bool8 ScrCmd_cmdD9(struct ScriptContext *ctx) bool8 ScrCmd_cmdD9(struct ScriptContext *ctx)
{ {
if (is_c1_link_related_active()) if (IsUpdateLinkStateCBActive())
{ {
return FALSE; return FALSE;
} }

View File

@ -84,7 +84,7 @@ EWRAM_DATA static bool8 sSavingComplete = FALSE;
EWRAM_DATA static u8 sSaveInfoWindowId = 0; EWRAM_DATA static u8 sSaveInfoWindowId = 0;
// Extern variables. // Extern variables.
extern u8 gLinkGuestPlayerId; extern u8 gLinkSelfPlayerId;
// Extern functions in not decompiled files. // Extern functions in not decompiled files.
extern void sub_80AF688(void); extern void sub_80AF688(void);
@ -244,7 +244,7 @@ static void BuildStartMenuActions(void)
{ {
sNumStartMenuActions = 0; sNumStartMenuActions = 0;
if (is_c1_link_related_active() == TRUE) if (IsUpdateLinkStateCBActive() == TRUE)
{ {
BuildLinkModeStartMenu(); BuildLinkModeStartMenu();
} }
@ -547,7 +547,7 @@ void sub_809FA34(u8 taskId) // Referenced in field_screen.s and rom_8011DC0.s
void ShowStartMenu(void) // Called from overworld.c and field_control_avatar.s void ShowStartMenu(void) // Called from overworld.c and field_control_avatar.s
{ {
if (!is_c1_link_related_active()) if (!IsUpdateLinkStateCBActive())
{ {
FreezeEventObjects(); FreezeEventObjects();
sub_808B864(); sub_808B864();
@ -672,7 +672,7 @@ static bool8 StartMenuPlayerNameCallback(void)
RemoveExtraStartMenuWindows(); RemoveExtraStartMenuWindows();
CleanupOverworldWindowsAndTilemaps(); CleanupOverworldWindowsAndTilemaps();
if (is_c1_link_related_active() || InUnionRoom()) if (IsUpdateLinkStateCBActive() || InUnionRoom())
ShowPlayerTrainerCard(CB2_ReturnToFieldWithOpenMenu); // Display trainer card ShowPlayerTrainerCard(CB2_ReturnToFieldWithOpenMenu); // Display trainer card
else if (FlagGet(FLAG_SYS_FRONTIER_PASS)) else if (FlagGet(FLAG_SYS_FRONTIER_PASS))
ShowFrontierPass(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass ShowFrontierPass(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass
@ -734,7 +734,7 @@ static bool8 StartMenuLinkModePlayerNameCallback(void)
{ {
PlayRainSoundEffect(); PlayRainSoundEffect();
CleanupOverworldWindowsAndTilemaps(); CleanupOverworldWindowsAndTilemaps();
ShowTrainerCardInLink(gLinkGuestPlayerId, CB2_ReturnToFieldWithOpenMenu); ShowTrainerCardInLink(gLinkSelfPlayerId, CB2_ReturnToFieldWithOpenMenu);
return TRUE; return TRUE;
} }

View File

@ -2762,7 +2762,7 @@ static void sub_80794CC(void)
Free(gUnknown_0203229C); Free(gUnknown_0203229C);
FreeAllWindowBuffers(); FreeAllWindowBuffers();
sub_800E084(); sub_800E084();
SetMainCallback2(c2_8056854); SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
} }
} }
else else
@ -2772,7 +2772,7 @@ static void sub_80794CC(void)
Free(gUnknown_02032184); Free(gUnknown_02032184);
Free(gUnknown_0203229C); Free(gUnknown_0203229C);
FreeAllWindowBuffers(); FreeAllWindowBuffers();
SetMainCallback2(c2_8056854); SetMainCallback2(CB2_ReturnToFieldFromMultiplayer);
} }
} }
} }