diff --git a/asm/cable_club.s b/asm/cable_club.s index e00866a1c..5b4e77619 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -426,7 +426,7 @@ sub_80B2688: @ 80B2688 adds r4, r0, r1 movs r0, 0 strh r0, [r4, 0xE] - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 @@ -1645,7 +1645,7 @@ sub_80B3194: @ 80B3194 lsrs r0, 24 cmp r0, 0x1 bls _080B31DA - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 @@ -2786,7 +2786,7 @@ _080B3B68: lsls r0, 24 cmp r4, r0 bcc _080B3BB8 - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 beq _080B3B96 diff --git a/asm/link.s b/asm/link.s index 5c517544e..63273c8b5 100644 --- a/asm/link.s +++ b/asm/link.s @@ -5,100 +5,6 @@ .text - thumb_func_start sub_800ABBC -sub_800ABBC: @ 800ABBC - push {lr} - ldr r0, =gSerialIsRFU - ldrb r0, [r0] - cmp r0, 0 - bne _0800ABDC - ldr r0, =gLinkStatus - ldr r0, [r0] - lsrs r0, 5 - movs r1, 0x1 - ands r0, r1 - b _0800ABE4 - .pool -_0800ABDC: - bl sub_8011AB0 - lsls r0, 24 - lsrs r0, 24 -_0800ABE4: - pop {r1} - bx r1 - thumb_func_end sub_800ABBC - - thumb_func_start sub_800ABE8 -sub_800ABE8: @ 800ABE8 - ldr r0, =gUnknown_03000D58 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_800ABE8 - - thumb_func_start sub_800ABF4 -sub_800ABF4: @ 800ABF4 - push {lr} - lsls r0, 16 - lsrs r3, r0, 16 - ldr r0, =gSerialIsRFU - ldrb r0, [r0] - cmp r0, 0x1 - bne _0800AC0C - bl task_add_05_task_del_08FA224_when_no_RfuFunc - b _0800AC20 - .pool -_0800AC0C: - ldr r2, =gLinkCallback - ldr r1, [r2] - cmp r1, 0 - bne _0800AC20 - ldr r0, =sub_800AC80 - str r0, [r2] - ldr r0, =gUnknown_030030E4 - strb r1, [r0] - ldr r0, =gUnknown_030030F4 - strh r3, [r0] -_0800AC20: - pop {r0} - bx r0 - .pool - thumb_func_end sub_800ABF4 - - thumb_func_start sub_800AC34 -sub_800AC34: @ 800AC34 - push {lr} - ldr r0, =gSerialIsRFU - ldrb r0, [r0] - cmp r0, 0x1 - bne _0800AC48 - bl task_add_05_task_del_08FA224_when_no_RfuFunc - b _0800AC70 - .pool -_0800AC48: - ldr r2, =gLinkCallback - ldr r1, [r2] - cmp r1, 0 - beq _0800AC64 - ldr r1, =gUnknown_02022B08 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - b _0800AC70 - .pool -_0800AC64: - ldr r0, =sub_800AC80 - str r0, [r2] - ldr r0, =gUnknown_030030E4 - strb r1, [r0] - ldr r0, =gUnknown_030030F4 - strh r1, [r0] -_0800AC70: - pop {r0} - bx r0 - .pool - thumb_func_end sub_800AC34 - thumb_func_start sub_800AC80 sub_800AC80: @ 800AC80 push {lr} diff --git a/asm/link_rfu.s b/asm/link_rfu.s index 87d80bba7..934de184f 100644 --- a/asm/link_rfu.s +++ b/asm/link_rfu.s @@ -7537,13 +7537,13 @@ sub_8011A9C: @ 8011A9C .pool thumb_func_end sub_8011A9C - thumb_func_start sub_8011AB0 -sub_8011AB0: @ 8011AB0 + thumb_func_start Rfu_IsMaster +Rfu_IsMaster: @ 8011AB0 ldr r0, =gUnknown_03005000 ldrb r0, [r0, 0xC] bx lr .pool - thumb_func_end sub_8011AB0 + thumb_func_end Rfu_IsMaster thumb_func_start LinkVSync LinkVSync: @ 8011ABC diff --git a/asm/mystery_event_menu.s b/asm/mystery_event_menu.s index ad9da463e..4915c199c 100644 --- a/asm/mystery_event_menu.s +++ b/asm/mystery_event_menu.s @@ -566,7 +566,7 @@ _08178E58: ands r0, r1 cmp r0, 0 beq _08178E98 - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 bne _08178E98 diff --git a/asm/pokenav.s b/asm/pokenav.s index 414ca3672..98a0a4951 100755 --- a/asm/pokenav.s +++ b/asm/pokenav.s @@ -28128,7 +28128,7 @@ _081D4EBA: thumb_func_start sub_81D4EC0 sub_81D4EC0: @ 81D4EC0 push {lr} - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 beq _081D4EDC @@ -28186,7 +28186,7 @@ _081D4F20: .4byte _081D4FEC .4byte _081D4FF8 _081D4F38: - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 beq _081D4F88 diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 9de2911ea..1c84ba801 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -768,7 +768,7 @@ _080E73B8: bl GetLinkPlayerCount_2 lsls r0, 24 lsrs r4, r0, 24 - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 diff --git a/asm/trade.s b/asm/trade.s index 8235dc0df..aafa9f245 100644 --- a/asm/trade.s +++ b/asm/trade.s @@ -473,7 +473,7 @@ _0807758C: bcs _080775A0 b _08077B46 _080775A0: - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 beq _080775D8 @@ -7367,7 +7367,7 @@ _0807AFAC: b _0807B0E4 .pool _0807AFBC: - bl sub_800ABBC + bl IsLinkMaster lsls r0, 24 cmp r0, 0 bne _0807AFC8 diff --git a/include/link.h b/include/link.h index 605d32aec..d4610eed5 100644 --- a/include/link.h +++ b/include/link.h @@ -205,7 +205,7 @@ void sub_800ADF8(void); void sub_800B488(void); void sub_800A620(void); void sub_8011BD0(void); -u8 sub_800ABBC(void); +u8 IsLinkMaster(void); void sub_800AC34(void); void SetLinkDebugValues(u32 seed, u32 flags); diff --git a/include/link_rfu.h b/include/link_rfu.h index 71b35b25c..39f68d1f1 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -21,5 +21,7 @@ u8 sub_80104F4(void); u8 rfu_get_multiplayer_id(void); bool8 sub_8010100(u8 a0); bool8 sub_8010500(void); +bool8 Rfu_IsMaster(void); +void task_add_05_task_del_08FA224_when_no_RfuFunc(void); #endif //GUARD_LINK_RFU_H diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 431f5d97a..b82a0a40e 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -793,7 +793,7 @@ static void Task_HandleSendLinkBuffersData(u8 taskId) if (GetLinkPlayerCount_2() >= var) { - if (sub_800ABBC()) + if (IsLinkMaster()) { sub_800A620(); gTasks[taskId].data[11]++; diff --git a/src/link.c b/src/link.c index d6cc1b5de..3ab9acb7c 100644 --- a/src/link.c +++ b/src/link.c @@ -107,6 +107,12 @@ EWRAM_DATA u16 gLinkTimeOutCounter = 0; EWRAM_DATA struct LinkPlayer gLocalLinkPlayer = {}; EWRAM_DATA struct LinkPlayer gLinkPlayers[MAX_RFU_PLAYERS] = {}; EWRAM_DATA struct LinkPlayer gSavedLinkPlayers[MAX_RFU_PLAYERS] = {}; +EWRAM_DATA struct { + u32 status; + u8 unk_04; +} gUnknown_02022B00 = {}; +EWRAM_DATA u16 gUnknown_02022B08 = 0; +EWRAM_DATA void *gUnknown_02022B0C = NULL; // Static ROM declarations @@ -125,6 +131,7 @@ static u16 LinkTestCalcBlockChecksum(const u16 *src, u16 size); static void LinkTest_prnthex(u32 pos, u8 a0, u8 a1, u8 a2); static void LinkCB_RequestPlayerDataExchange(void); static void Task_PrintTestData(u8 taskId); +void sub_800AC80(void); void sub_800AEB4(void); u8 sub_800B2F8(void); void sub_800B4A4(void); @@ -1368,3 +1375,55 @@ u8 GetLinkPlayerCount_2(void) { return EXTRACT_PLAYER_COUNT(gLinkStatus); } + +bool8 IsLinkMaster(void) +{ + if (gSerialIsRFU) + { + return Rfu_IsMaster(); + } + return EXTRACT_MASTER(gLinkStatus); +} + +u8 sub_800ABE8(void) +{ + return gUnknown_03000D58; +} + +void sub_800ABF4(u16 a0) +{ + if (gSerialIsRFU == TRUE) + { + task_add_05_task_del_08FA224_when_no_RfuFunc(); + } + else + { + if (gLinkCallback == NULL) + { + gLinkCallback = sub_800AC80; + gUnknown_030030E4 = 0; + gUnknown_030030F4 = a0; + } + } +} + +void sub_800AC34(void) +{ + if (gSerialIsRFU == TRUE) + { + task_add_05_task_del_08FA224_when_no_RfuFunc(); + } + else + { + if (gLinkCallback != NULL) + { + gUnknown_02022B08 ++; + } + else + { + gLinkCallback = sub_800AC80; + gUnknown_030030E4 = 0; + gUnknown_030030F4 = 0; + } + } +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 2a1218996..c0c08848d 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -20,15 +20,6 @@ gStringVar4: @ 2021FC4 .include "src/string_util.o" .include "src/link.o" -gUnknown_02022B00: @ 2022B00 - .space 0x8 - -gUnknown_02022B08: @ 2022B08 - .space 0x4 - -gUnknown_02022B0C: @ 2022B0C - .space 0x4 - gUnknown_02022B10: @ 2022B10 .space 0x4