From cc82358864afc54281326734487bec1354fa4d9d Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sun, 19 Nov 2017 16:54:49 -0500 Subject: [PATCH] sub_800C54C --- asm/link_rfu.s | 229 --------------------------------------------- include/librfu.h | 17 ++++ include/link_rfu.h | 11 ++- src/link_rfu.c | 127 +++++++++++++++++++++++++ 4 files changed, 153 insertions(+), 231 deletions(-) diff --git a/asm/link_rfu.s b/asm/link_rfu.s index dfc434f67..169279f43 100644 --- a/asm/link_rfu.s +++ b/asm/link_rfu.s @@ -5,235 +5,6 @@ .text - thumb_func_start rfu_syncVBlank_ -rfu_syncVBlank_: @ 800C530 - push {lr} - bl rfu_syncVBlank - lsls r0, 16 - cmp r0, 0 - beq _0800C548 - movs r0, 0xF1 - movs r1, 0 - bl sub_800D30C - bl sub_800D610 -_0800C548: - pop {r0} - bx r0 - thumb_func_end rfu_syncVBlank_ - - thumb_func_start sub_800C54C -sub_800C54C: @ 800C54C - push {r4,lr} - adds r3, r0, 0 - ldr r1, =gUnknown_03004140 - ldr r2, [r1, 0x40] - cmp r2, 0 - bne _0800C568 - ldrb r0, [r1, 0x4] - cmp r0, 0 - beq _0800C568 - strb r2, [r1, 0x4] - b _0800C736 - .pool -_0800C568: - ldr r0, =gUnknown_03004140 - ldrb r0, [r0, 0x7] - cmp r0, 0 - beq _0800C576 - adds r0, r3, 0 - bl sub_800C744 -_0800C576: - ldr r4, =gUnknown_03004140 - ldrb r0, [r4, 0x4] - cmp r0, 0 - bne _0800C580 - b _0800C700 -_0800C580: - bl rfu_waitREQComplete - movs r0, 0x1 - strb r0, [r4, 0xE] - ldrb r0, [r4, 0x4] - subs r0, 0x1 - cmp r0, 0x16 - bls _0800C592 - b _0800C6F6 -_0800C592: - lsls r0, 2 - ldr r1, =_0800C5A4 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0800C5A4: - .4byte _0800C624 - .4byte _0800C65C - .4byte _0800C662 - .4byte _0800C678 - .4byte _0800C690 - .4byte _0800C696 - .4byte _0800C69C - .4byte _0800C6F6 - .4byte _0800C6A2 - .4byte _0800C6A8 - .4byte _0800C6AE - .4byte _0800C6B4 - .4byte _0800C6C4 - .4byte _0800C6CA - .4byte _0800C6F6 - .4byte _0800C6D0 - .4byte _0800C6E0 - .4byte _0800C6E6 - .4byte _0800C6EC - .4byte _0800C6F6 - .4byte _0800C6F2 - .4byte _0800C6F6 - .4byte _0800C600 -_0800C600: - bl sub_800BEC0 - ldr r1, =0x00008001 - movs r2, 0xFF - cmp r0, r1 - bne _0800C60E - movs r2, 0x44 -_0800C60E: - ldr r1, =gUnknown_03004140 - movs r0, 0 - strb r0, [r1, 0x5] - strb r0, [r1, 0x4] - adds r0, r2, 0 - b _0800C64E - .pool -_0800C624: - bl sub_800BEC0 - ldr r1, =0x00008001 - cmp r0, r1 - bne _0800C644 - ldr r0, =gUnknown_03004140 - ldrb r1, [r0, 0x5] - strb r1, [r0, 0x4] - movs r1, 0x3 - strb r1, [r0, 0x5] - b _0800C6F6 - .pool -_0800C644: - ldr r1, =gUnknown_03004140 - movs r0, 0 - strb r0, [r1, 0x5] - strb r0, [r1, 0x4] - movs r0, 0xFF -_0800C64E: - movs r1, 0 - bl sub_800D30C - b _0800C6F6 - .pool -_0800C65C: - bl rfu_REQ_reset - b _0800C6F6 -_0800C662: - ldr r0, =gUnknown_03004140 - ldr r2, [r0, 0x3C] - ldrh r0, [r2, 0x2] - ldrb r1, [r2] - ldrb r2, [r2, 0x1] - bl rfu_REQ_configSystem - b _0800C6F6 - .pool -_0800C678: - ldr r0, =gUnknown_03004140 - ldr r3, [r0, 0x3C] - ldrb r0, [r3, 0x4] - ldrh r1, [r3, 0x6] - ldr r2, [r3, 0x8] - ldr r3, [r3, 0xC] - bl rfu_REQ_configGameData - b _0800C6F6 - .pool -_0800C690: - bl rfu_REQ_startSearchChild - b _0800C6F6 -_0800C696: - bl rfu_REQ_pollSearchChild - b _0800C6F6 -_0800C69C: - bl rfu_REQ_endSearchChild - b _0800C6F6 -_0800C6A2: - bl rfu_REQ_startSearchParent - b _0800C6F6 -_0800C6A8: - bl rfu_REQ_pollSearchParent - b _0800C6F6 -_0800C6AE: - bl rfu_REQ_endSearchParent - b _0800C6F6 -_0800C6B4: - ldr r0, =gUnknown_03004140 - ldrh r0, [r0, 0x1E] - bl rfu_REQ_startConnectParent - b _0800C6F6 - .pool -_0800C6C4: - bl rfu_REQ_pollConnectParent - b _0800C6F6 -_0800C6CA: - bl rfu_REQ_endConnectParent - b _0800C6F6 -_0800C6D0: - ldr r0, =gUnknown_03007890 - ldr r0, [r0] - ldrb r0, [r0, 0x3] - bl rfu_REQ_CHILD_startConnectRecovery - b _0800C6F6 - .pool -_0800C6E0: - bl rfu_REQ_CHILD_pollConnectRecovery - b _0800C6F6 -_0800C6E6: - bl rfu_REQ_CHILD_endConnectRecovery - b _0800C6F6 -_0800C6EC: - bl rfu_REQ_changeMasterSlave - b _0800C6F6 -_0800C6F2: - bl rfu_REQ_stopMode -_0800C6F6: - bl rfu_waitREQComplete - ldr r1, =gUnknown_03004140 - movs r0, 0 - strb r0, [r1, 0xE] -_0800C700: - ldr r0, =gUnknown_03004140 - ldrb r0, [r0, 0x4] - subs r0, 0x12 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bhi _0800C710 - b _0800C576 -_0800C710: - ldr r0, =gUnknown_03007890 - ldr r0, [r0] - ldrb r0, [r0] - cmp r0, 0x1 - bne _0800C726 - movs r0, 0 - bl sub_800C36C - lsls r0, 24 - cmp r0, 0 - bne _0800C736 -_0800C726: - bl sub_800CF34 - bl sub_800D158 - bl sub_800D268 - bl sub_800D434 -_0800C736: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_800C54C - thumb_func_start sub_800C744 sub_800C744: @ 800C744 push {r4,lr} diff --git a/include/librfu.h b/include/librfu.h index 45b3e1cd3..cdc33c91a 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -158,3 +158,20 @@ void rfu_setMSCCallback(void (*func)(u16)); void rfu_setREQCallback(void (*func)(u16, u16)); bool8 rfu_getMasterSlave(void); void rfu_REQBN_watchLink(u16 a0, u8 *a1, u8 *a2, u8 *a3); +bool16 rfu_syncVBlank(void); +void rfu_REQ_reset(void); +void rfu_REQ_configSystem(u16, u8, u8); +void rfu_REQ_configGameData(u8, u16, u32, u32); +void rfu_REQ_startSearchChild(void); +void rfu_REQ_pollSearchChild(void); +void rfu_REQ_endSearchChild(void); +void rfu_REQ_startSearchParent(void); +void rfu_REQ_pollSearchParent(void); +void rfu_REQ_endSearchParent(void); +void rfu_REQ_startConnectParent(u16); +void rfu_REQ_pollConnectParent(void); +void rfu_REQ_endConnectParent(void); +void rfu_REQ_CHILD_startConnectRecovery(u8); +void rfu_REQ_CHILD_pollConnectRecovery(void); +void rfu_REQ_CHILD_endConnectRecovery(void); +void rfu_REQ_changeMasterSlave(void); diff --git a/include/link_rfu.h b/include/link_rfu.h index e9b6548a5..12ff03330 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -24,7 +24,13 @@ struct UnkLinkRfuStruct_02022B14 struct UnkLinkRfuStruct_02022B2C { - u8 filler_00[16]; + u8 unk_00; + u8 unk_01; + u16 unk_02; + u8 unk_04; + u16 unk_06; + u32 unk_08; + u32 unk_0c; u8 unk_10; u8 unk_11; u16 unk_12; @@ -46,7 +52,8 @@ struct UnkRfuStruct_1 { /* 0x00b */ u8 unk_0b; /* 0x00c */ u8 unk_0c; /* 0x00d */ u8 unk_0d; - /* 0x00e */ u8 filler_0e[2]; + /* 0x00e */ u8 unk_0e; + /* 0x00f */ u8 unk_0f; /* 0x010 */ u8 unk_10; /* 0x011 */ u8 unk_11; /* 0x012 */ u8 unk_12; diff --git a/src/link_rfu.c b/src/link_rfu.c index f0439eac3..6e0d3e249 100644 --- a/src/link_rfu.c +++ b/src/link_rfu.c @@ -29,6 +29,11 @@ void sub_800C7B4(u16 unk0, u16 unk1); void sub_800D30C(u8 a0, u8 a1); void sub_800D334(u8 a0); void sub_800D610(void); +void sub_800C744(u32 a0); +void sub_800CF34(void); +void sub_800D158(void); +void sub_800D268(void); +void sub_800D434(void); // .rodata @@ -442,3 +447,125 @@ bool8 sub_800C36C(u16 a0) } return retVal; } + +void rfu_syncVBlank_(void) +{ + if (rfu_syncVBlank()) + { + sub_800D30C(0xF1, 0x00); + sub_800D610(); + } +} + +void sub_800C54C(u32 a0) +{ + u8 r2; + + if (gUnknown_03004140.unk_40 == NULL && gUnknown_03004140.unk_04 != 0) + { + gUnknown_03004140.unk_04 = 0; + } + else + { + if (gUnknown_03004140.unk_07 != 0) + { + sub_800C744(a0); + } + do { + + if (gUnknown_03004140.unk_04 != 0) + { + rfu_waitREQComplete(); + gUnknown_03004140.unk_0e = 1; + switch (gUnknown_03004140.unk_04) + { + case 23: + r2 = sub_800BEC0() == 0x8001 ? 0x44 : 0xFF; + gUnknown_03004140.unk_04 = gUnknown_03004140.unk_05 = 0; + sub_800D30C(r2, 0); + break; + case 1: + if (sub_800BEC0() == 0x8001) + { + gUnknown_03004140.unk_04 = gUnknown_03004140.unk_05; + gUnknown_03004140.unk_05 = 3; + } + else + { + gUnknown_03004140.unk_04 = gUnknown_03004140.unk_05 = 0; + sub_800D30C(0xFF, 0); + } + break; + case 2: + rfu_REQ_reset(); + break; + case 3: + rfu_REQ_configSystem(gUnknown_03004140.unk_3c->unk_02, gUnknown_03004140.unk_3c->unk_00, gUnknown_03004140.unk_3c->unk_01); + break; + case 4: + rfu_REQ_configGameData(gUnknown_03004140.unk_3c->unk_04, gUnknown_03004140.unk_3c->unk_06, gUnknown_03004140.unk_3c->unk_08, gUnknown_03004140.unk_3c->unk_0c); + break; + case 5: + rfu_REQ_startSearchChild(); + break; + case 6: + rfu_REQ_pollSearchChild(); + break; + case 7: + rfu_REQ_endSearchChild(); + break; + case 8: + break; + case 9: + rfu_REQ_startSearchParent(); + break; + case 10: + rfu_REQ_pollSearchParent(); + break; + case 11: + rfu_REQ_endSearchParent(); + break; + case 12: + rfu_REQ_startConnectParent(gUnknown_03004140.unk_1e); + break; + case 13: + rfu_REQ_pollConnectParent(); + break; + case 14: + rfu_REQ_endConnectParent(); + break; + case 15: + break; + case 16: + rfu_REQ_CHILD_startConnectRecovery(gUnknown_03007890->unk_03); + break; + case 17: + rfu_REQ_CHILD_pollConnectRecovery(); + break; + case 18: + rfu_REQ_CHILD_endConnectRecovery(); + break; + case 19: + rfu_REQ_changeMasterSlave(); + break; + case 20: + break; + case 21: + rfu_REQ_stopMode(); + break; + case 22: + break; + } + rfu_waitREQComplete(); + gUnknown_03004140.unk_0e = 0; + } + } while (gUnknown_03004140.unk_04 == 18 || gUnknown_03004140.unk_04 == 19); + if (gUnknown_03007890->unk_00 != 1 || !sub_800C36C(0)) + { + sub_800CF34(); + sub_800D158(); + sub_800D268(); + sub_800D434(); + } + } +}