From b082f000afee689eb6a73ba7a938c4f371c09225 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 1 Dec 2018 18:54:59 +0100 Subject: [PATCH] Start working on link rfu --- asm/link_rfu.s | 1503 +------------------------------------------- include/librfu.h | 9 +- include/link_rfu.h | 27 +- src/librfu_stwi.c | 34 +- src/link_rfu.c | 602 +++++++++++++++++- 5 files changed, 617 insertions(+), 1558 deletions(-) diff --git a/asm/link_rfu.s b/asm/link_rfu.s index 1179b9866..4060c4959 100644 --- a/asm/link_rfu.s +++ b/asm/link_rfu.s @@ -5,1508 +5,7 @@ .text - thumb_func_start sub_8011404 -sub_8011404: @ 8011404 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x31 - bne _08011410 - b _08011570 -_08011410: - cmp r4, 0x31 - bgt _0801143E - cmp r4, 0x22 - beq _08011494 - cmp r4, 0x22 - bgt _0801142C - cmp r4, 0x20 - beq _0801147C - cmp r4, 0x20 - ble _08011426 - b _080115DE -_08011426: - cmp r4, 0 - beq _0801146E - b _080115DE -_0801142C: - cmp r4, 0x24 - beq _080114BA - cmp r4, 0x24 - blt _080114B0 - cmp r4, 0x25 - beq _08011504 - cmp r4, 0x30 - beq _0801150E - b _080115DE -_0801143E: - cmp r4, 0x44 - bgt _08011454 - cmp r4, 0x42 - blt _08011448 - b _080115DE -_08011448: - cmp r4, 0x33 - beq _08011522 - cmp r4, 0x33 - bge _08011452 - b _0801158C -_08011452: - b _080115DE -_08011454: - cmp r4, 0xF3 - bne _0801145A - b _080115AC -_0801145A: - cmp r4, 0xF3 - bgt _08011466 - cmp r4, 0xF0 - bge _08011464 - b _080115DE -_08011464: - b _080115C4 -_08011466: - cmp r4, 0xFF - bne _0801146C - b _080115C4 -_0801146C: - b _080115DE -_0801146E: - ldr r1, =gUnknown_03005000 - movs r0, 0x6 - strh r0, [r1, 0x4] - b _080115DE - .pool -_0801147C: - ldr r0, =gUnknown_03005000 - ldr r1, =gUnknown_03004140 - ldrh r1, [r1, 0x14] - ldr r2, =0x00000ccd - adds r0, r2 - b _080115DC - .pool -_08011494: - ldr r0, =gUnknown_03005000 - ldr r1, =gUnknown_03004140 - ldrh r1, [r1, 0x14] - ldr r2, =0x00000c3e - adds r0, r2 - ldrb r2, [r0] - b _080115DC - .pool -_080114B0: - movs r0, 0x2 - adds r1, r4, 0 - bl sub_8011A64 - b _080115DE -_080114BA: - ldr r4, =gUnknown_03005000 - movs r1, 0 - movs r0, 0xB - strh r0, [r4, 0x4] - ldr r2, =0x00000c85 - adds r0, r4, r2 - strb r1, [r0] - ldr r0, =0x00000c86 - adds r2, r4, r0 - strb r1, [r2] - ldr r1, =0x00000c3e - adds r5, r4, r1 - ldrb r1, [r5] - movs r0, 0x20 - movs r3, 0x1 - bl rfu_setRecvBuffer - ldrb r1, [r5] - ldr r2, =0x00000c3f - adds r4, r2 - movs r0, 0x10 - adds r2, r4, 0 - movs r3, 0x46 - bl rfu_setRecvBuffer - b _080115DE - .pool -_08011504: - movs r0, 0x2 - movs r1, 0x25 - bl sub_8011A64 - b _080115DE -_0801150E: - ldr r0, =gUnknown_03005000 - adds r2, r0, 0 - adds r2, 0xF0 - movs r1, 0x2 - strb r1, [r2] - ldr r1, =0x00000c86 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x6 - beq _080115DE -_08011522: - ldr r2, =gUnknown_03005000 - adds r1, r2, 0 - adds r1, 0xF0 - ldrb r0, [r1] - cmp r0, 0x2 - beq _08011532 - movs r0, 0x4 - strb r0, [r1] -_08011532: - ldr r1, =0x00000c86 - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0x9 - beq _08011544 - movs r0, 0x2 - adds r1, r4, 0 - bl sub_8011A64 -_08011544: - ldr r0, =gUnknown_082ED7FC - movs r1, 0x5 - movs r2, 0x5 - bl nullsub_5 - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0x1 - bne _080115DE - adds r0, r4, 0 - bl sub_8011170 - b _080115DE - .pool -_08011570: - ldr r0, =gUnknown_03005000 - adds r0, 0xF0 - movs r1, 0x1 - strb r1, [r0] - ldr r0, =gUnknown_082ED814 - movs r1, 0x5 - movs r2, 0x5 - bl nullsub_5 - b _080115DE - .pool -_0801158C: - ldr r1, =gUnknown_03005000 - adds r2, r1, 0 - adds r2, 0xF0 - movs r0, 0x3 - strb r0, [r2] - ldr r2, =0x00000c3c - adds r1, r2 - ldrb r0, [r1] - movs r0, 0x1 - strb r0, [r1] - b _080115DE - .pool -_080115AC: - movs r0, 0x1 - movs r1, 0xF3 - bl sub_8011A64 - movs r0, 0xF3 - bl sub_8011170 - ldr r0, =gUnknown_03005000 - adds r0, 0xEF - b _080115DA - .pool -_080115C4: - movs r0, 0x1 - adds r1, r4, 0 - bl sub_8011A64 - adds r0, r4, 0 - bl sub_8011170 - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000cdb - adds r0, r1 - ldrb r1, [r0] -_080115DA: - movs r1, 0x1 -_080115DC: - strb r1, [r0] -_080115DE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011404 - thumb_func_start sub_80115EC -sub_80115EC: @ 80115EC - push {r4-r6,lr} - adds r3, r0, 0 - movs r2, 0 - movs r6, 0x1 - ldr r0, =gUnknown_03005000 - ldr r4, =0x00000cea - adds r1, r0, r4 - movs r5, 0 - movs r4, 0xFF -_080115FE: - adds r0, r3, 0 - asrs r0, r2 - ands r0, r6 - cmp r0, 0 - beq _08011610 - strb r5, [r1] - ldrb r0, [r1, 0x4] - orrs r0, r4 - strb r0, [r1, 0x4] -_08011610: - adds r1, 0x1 - adds r2, 0x1 - cmp r2, 0x3 - ble _080115FE - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80115EC - - thumb_func_start sub_8011628 -sub_8011628: @ 8011628 - push {r4-r7,lr} - adds r5, r0, 0 - movs r3, 0 - movs r2, 0 - movs r4, 0x1 - ldr r6, =gUnknown_03007890 - movs r7, 0x7F -_08011636: - adds r0, r5, 0 - asrs r0, r2 - ands r0, r4 - cmp r0, 0 - beq _0801165C - lsls r1, r2, 5 - adds r1, 0x14 - ldr r0, [r6] - adds r0, r1 - ldrb r1, [r0, 0x10] - adds r0, r7, 0 - ands r0, r1 - cmp r0, 0x45 - bne _0801165C - adds r0, r4, 0 - lsls r0, r2 - orrs r3, r0 - lsls r0, r3, 24 - lsrs r3, r0, 24 -_0801165C: - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x3 - bls _08011636 - adds r0, r3, 0 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8011628 - - thumb_func_start sub_8011674 -sub_8011674: @ 8011674 - push {r4-r7,lr} - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x25 - bne _08011680 - b _080118EC -_08011680: - cmp r4, 0x25 - bgt _080116C2 - cmp r4, 0x14 - bne _0801168A - b _08011804 -_0801168A: - cmp r4, 0x14 - bgt _080116A2 - cmp r4, 0x11 - beq _08011722 - cmp r4, 0x11 - ble _08011698 - b _08011A42 -_08011698: - cmp r4, 0 - beq _0801170C - cmp r4, 0x10 - beq _08011718 - b _08011A42 -_080116A2: - cmp r4, 0x22 - bne _080116A8 - b _08011868 -_080116A8: - cmp r4, 0x22 - bgt _080116B4 - cmp r4, 0x20 - bne _080116B2 - b _08011850 -_080116B2: - b _08011A42 -_080116B4: - cmp r4, 0x23 - bne _080116BA - b _08011884 -_080116BA: - cmp r4, 0x24 - bne _080116C0 - b _080118BA -_080116C0: - b _08011A42 -_080116C2: - cmp r4, 0x44 - bgt _080116F2 - cmp r4, 0x42 - blt _080116CC - b _08011A42 -_080116CC: - cmp r4, 0x32 - bne _080116D2 - b _08011914 -_080116D2: - cmp r4, 0x32 - bgt _080116E4 - cmp r4, 0x30 - bne _080116DC - b _08011940 -_080116DC: - cmp r4, 0x31 - bne _080116E2 - b _080118F6 -_080116E2: - b _08011A42 -_080116E4: - cmp r4, 0x33 - bne _080116EA - b _08011948 -_080116EA: - cmp r4, 0x40 - bne _080116F0 - b _080119FC -_080116F0: - b _08011A42 -_080116F2: - cmp r4, 0xF3 - bne _080116F8 - b _08011A0C -_080116F8: - cmp r4, 0xF3 - bgt _08011704 - cmp r4, 0xF0 - bge _08011702 - b _08011A42 -_08011702: - b _08011A28 -_08011704: - cmp r4, 0xFF - bne _0801170A - b _08011A28 -_0801170A: - b _08011A42 -_0801170C: - ldr r1, =gUnknown_03005000 - movs r0, 0x11 - strh r0, [r1, 0x4] - b _08011A42 - .pool -_08011718: - movs r0, 0x4 - movs r1, 0 - bl sub_8011A64 - b _08011A42 -_08011722: - bl sub_800F7DC - ldrb r1, [r0, 0xA] - movs r0, 0x7F - ands r0, r1 - cmp r0, 0x45 - bne _080117DC - ldr r5, =gUnknown_03005000 - ldr r1, =0x00000cd9 - adds r0, r5, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _080117DC - ldr r0, =gUnknown_03004140 - ldrh r0, [r0, 0x14] - bl sub_8011628 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - beq _080117A6 - adds r0, r4, 0 - bl sub_800E87C - movs r2, 0x1 - mov r12, r2 - mov r1, r12 - lsls r1, r0 - lsls r1, 24 - lsrs r1, 24 - ldr r7, =0x00000ce6 - adds r6, r5, r7 - ldrb r2, [r6] - cmp r2, 0 - bne _08011798 - ldr r0, =0x00000ce8 - adds r3, r5, r0 - ldrb r0, [r3] - cmp r0, 0 - bne _08011798 - subs r7, 0x1 - adds r0, r5, r7 - strb r1, [r0] - eors r1, r4 - orrs r1, r2 - strb r1, [r6] - mov r0, r12 - strb r0, [r3] - b _080117A6 - .pool -_08011798: - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000ce6 - adds r0, r1 - ldrb r2, [r0] - adds r1, r4, 0 - orrs r1, r2 - strb r1, [r0] -_080117A6: - ldr r0, =gUnknown_03004140 - ldrh r1, [r0, 0x14] - cmp r4, r1 - beq _080117F6 - ldr r2, =gUnknown_03005000 - ldr r7, =0x00000ce3 - adds r3, r2, r7 - adds r0, r4, 0 - eors r0, r1 - ldrb r1, [r3] - orrs r0, r1 - strb r0, [r3] - ldr r0, =0x00000ce4 - adds r2, r0 - movs r0, 0x2 - strb r0, [r2] - b _080117F6 - .pool -_080117DC: - bl sub_800F7DC - ldrb r1, [r0, 0xA] - movs r0, 0x7F - ands r0, r1 - cmp r0, 0x54 - bne _080117F6 - ldr r0, =gUnknown_03004140 - ldrb r0, [r0] - bl rfu_REQ_disconnect - bl rfu_waitREQComplete -_080117F6: - ldr r0, =gUnknown_03004140 - ldrh r0, [r0, 0x14] - bl sub_80115EC - b _08011A42 - .pool -_08011804: - bl sub_800F7DC - ldrb r1, [r0, 0xA] - movs r0, 0x7F - ands r0, r1 - cmp r0, 0x45 - beq _08011836 - ldr r4, =gUnknown_03004140 - ldrb r0, [r4, 0x1] - cmp r0, 0x1 - bls _08011836 - ldrb r0, [r4, 0x14] - bl sub_800E87C - movs r1, 0x80 - lsls r1, 17 - lsls r1, r0 - lsrs r1, 24 - ldrb r0, [r4] - eors r1, r0 - adds r0, r1, 0 - bl rfu_REQ_disconnect - bl rfu_waitREQComplete -_08011836: - ldr r1, =gUnknown_03005000 - ldrh r0, [r1, 0x4] - cmp r0, 0xF - beq _08011840 - b _08011A42 -_08011840: - movs r0, 0x10 - strh r0, [r1, 0x4] - b _08011A42 - .pool -_08011850: - ldr r0, =gUnknown_03005000 - ldr r1, =gUnknown_03004140 - ldrh r1, [r1, 0x14] - ldr r2, =0x00000ccd - adds r0, r2 - b _08011A40 - .pool -_08011868: - ldr r0, =gUnknown_03005000 - ldr r1, =gUnknown_03004140 - ldrh r1, [r1, 0x14] - ldr r7, =0x00000c3e - adds r0, r7 - ldrb r2, [r0] - b _08011A40 - .pool -_08011884: - ldr r1, =gUnknown_03005000 - movs r0, 0x12 - strh r0, [r1, 0x4] - ldr r0, =0x00000ccf - adds r1, r0 - ldrb r0, [r1] - cmp r0, 0x1 - bhi _080118B0 - adds r0, 0x1 - strb r0, [r1] - ldr r0, =sub_801209C - movs r1, 0x2 - bl CreateTask - b _08011A42 - .pool -_080118B0: - movs r0, 0x2 - movs r1, 0x23 - bl sub_8011A64 - b _08011A42 -_080118BA: - ldr r4, =gUnknown_03005000 - movs r0, 0xD - strh r0, [r4, 0x4] - movs r0, 0x3 - movs r1, 0 - bl sub_8011A64 - ldr r1, =0x00000c3e - adds r0, r4, r1 - ldrb r1, [r0] - ldr r2, =0x00000c3f - adds r4, r2 - movs r0, 0x10 - adds r2, r4, 0 - movs r3, 0x46 - bl rfu_setRecvBuffer - b _08011A42 - .pool -_080118EC: - movs r0, 0x2 - movs r1, 0x25 - bl sub_8011A64 - b _08011A42 -_080118F6: - ldr r0, =gUnknown_03004140 - ldrb r1, [r0] - ldrh r0, [r0, 0x14] - ands r1, r0 - cmp r1, 0 - bne _08011904 - b _08011A42 -_08011904: - ldr r0, =gUnknown_03005000 - adds r0, 0xF0 - movs r1, 0x1 - b _08011A40 - .pool -_08011914: - ldr r2, =gUnknown_03005000 - adds r1, r2, 0 - adds r1, 0xF0 - movs r0, 0x3 - strb r0, [r1] - ldr r0, =gUnknown_03007890 - ldr r0, [r0] - ldrb r0, [r0] - cmp r0, 0 - beq _0801192A - b _08011A42 -_0801192A: - ldr r7, =0x00000c3c - adds r0, r2, r7 - ldrb r1, [r0] - movs r1, 0x1 - b _08011A40 - .pool -_08011940: - ldr r0, =gUnknown_03005000 - adds r0, 0xF0 - movs r1, 0x2 - strb r1, [r0] -_08011948: - ldr r2, =gUnknown_03005000 - adds r1, r2, 0 - adds r1, 0xF0 - ldrb r0, [r1] - cmp r0, 0x2 - beq _08011958 - movs r0, 0x4 - strb r0, [r1] -_08011958: - ldrb r0, [r2, 0xC] - cmp r0, 0x1 - bne _08011996 - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0x1 - bne _080119B4 - ldr r0, =0x00000ce2 - adds r2, r0 - ldr r0, =gUnknown_03004140 - ldrb r1, [r0, 0x14] - ldrb r0, [r2] - bics r0, r1 - strb r0, [r2] - cmp r0, 0 - bne _08011990 - adds r0, r4, 0 - bl sub_8011170 - b _080119B4 - .pool -_08011990: - bl sub_80111FC - b _080119B4 -_08011996: - ldr r1, =0x00000ce4 - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0x2 - beq _080119B4 - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0x1 - bne _080119B4 - adds r0, r4, 0 - bl sub_8011170 - movs r0, 0 - bl sub_800C27C -_080119B4: - ldr r0, =gUnknown_03007890 - ldr r0, [r0] - ldrb r0, [r0] - cmp r0, 0xFF - bne _080119DA - ldr r0, =gUnknown_03004140 - ldrb r0, [r0, 0x7] - cmp r0, 0 - bne _080119DA - ldr r0, =sub_800EB44 - bl FuncIsActiveTask - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080119DA - ldr r1, =gUnknown_03005000 - movs r0, 0x11 - strh r0, [r1, 0x4] -_080119DA: - movs r0, 0x2 - adds r1, r4, 0 - bl sub_8011A64 - b _08011A42 - .pool -_080119FC: - ldr r0, =gUnknown_03005000 - ldr r2, =0x00000ce3 - adds r0, r2 - b _08011A3E - .pool -_08011A0C: - movs r0, 0x1 - movs r1, 0xF3 - bl sub_8011A64 - movs r0, 0xF3 - bl sub_8011170 - ldr r0, =gUnknown_03005000 - adds r0, 0xEF - movs r1, 0x1 - b _08011A40 - .pool -_08011A28: - adds r0, r4, 0 - bl sub_8011170 - movs r0, 0x1 - adds r1, r4, 0 - bl sub_8011A64 - ldr r0, =gUnknown_03005000 - ldr r7, =0x00000cdb - adds r0, r7 - ldrb r1, [r0] -_08011A3E: - movs r1, 0 -_08011A40: - strb r1, [r0] -_08011A42: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011674 - - thumb_func_start sub_8011A50 -sub_8011A50: @ 8011A50 - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000ce4 - adds r0, r1 - movs r1, 0x2 - strb r1, [r0] - bx lr - .pool - thumb_func_end sub_8011A50 - - thumb_func_start sub_8011A64 -sub_8011A64: @ 8011A64 - ldr r2, =gUnknown_03005000 - adds r3, r2, 0 - adds r3, 0xF1 - strb r0, [r3] - strh r1, [r2, 0xA] - bx lr - .pool - thumb_func_end sub_8011A64 - - thumb_func_start sub_8011A74 -sub_8011A74: @ 8011A74 - ldr r0, =gUnknown_03005000 - adds r0, 0xF1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8011A74 - - thumb_func_start sub_8011A80 -sub_8011A80: @ 8011A80 - push {lr} - bl sub_8011A74 - lsls r0, 24 - lsrs r0, 24 - subs r0, 0x1 - cmp r0, 0x1 - bls _08011A94 - movs r0, 0 - b _08011A96 -_08011A94: - movs r0, 0x1 -_08011A96: - pop {r1} - bx r1 - thumb_func_end sub_8011A80 - - thumb_func_start sub_8011A9C -sub_8011A9C: @ 8011A9C - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000ce8 - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_8011A9C - - thumb_func_start Rfu_IsMaster -Rfu_IsMaster: @ 8011AB0 - ldr r0, =gUnknown_03005000 - ldrb r0, [r0, 0xC] - bx lr - .pool - thumb_func_end Rfu_IsMaster - - thumb_func_start RfuVSync -RfuVSync: @ 8011ABC - push {lr} - bl rfu_syncVBlank_ - pop {r0} - bx r0 - thumb_func_end RfuVSync - - thumb_func_start sub_8011AC8 -sub_8011AC8: @ 8011AC8 - push {lr} - sub sp, 0x4 - movs r0, 0 - str r0, [sp] - ldr r1, =gRecvCmds - ldr r2, =0x05000014 - mov r0, sp - bl CpuSet - add sp, 0x4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011AC8 - - thumb_func_start sub_8011AE8 -sub_8011AE8: @ 8011AE8 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_8011AE8 - - thumb_func_start sub_8011AFC -sub_8011AFC: @ 8011AFC - push {r4,lr} - bl ResetSpriteData - bl FreeAllSpritePalettes - bl ResetTasks - bl ResetPaletteFade - ldr r0, =sub_8011AE8 - bl SetVBlankCallback - bl IsWirelessAdapterConnected - lsls r0, 24 - cmp r0, 0 - beq _08011B70 - ldr r1, =gLinkType - ldr r2, =0x00001111 - adds r0, r2, 0 - strh r0, [r1] - bl sub_800B488 - bl OpenLink - ldr r0, =gMain - ldrh r0, [r0, 0x24] - bl SeedRng - movs r4, 0 -_08011B38: - bl Random - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - adds r1, 0xA - adds r1, r4 - strb r0, [r1] - adds r4, 0x1 - cmp r4, 0x3 - ble _08011B38 - movs r1, 0xAA - lsls r1, 5 - movs r0, 0 - bl SetGpuReg - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - bl sub_8011BA4 - ldr r0, =sub_8011BF8 - bl SetMainCallback2 -_08011B70: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011AFC - - thumb_func_start sub_8011B90 -sub_8011B90: @ 8011B90 - push {lr} - ldr r0, =sub_800EB44 - bl FuncIsActiveTask - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .pool - thumb_func_end sub_8011B90 - - thumb_func_start sub_8011BA4 -sub_8011BA4: @ 8011BA4 - push {r4,lr} - ldr r4, =nullsub_89 - adds r0, r4, 0 - bl FuncIsActiveTask - lsls r0, 24 - cmp r0, 0 - bne _08011BC2 - adds r0, r4, 0 - movs r1, 0 - bl CreateTask - ldr r1, =gUnknown_03005000 - adds r1, 0x66 - strb r0, [r1] -_08011BC2: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011BA4 - - thumb_func_start sub_8011BD0 -sub_8011BD0: @ 8011BD0 - push {lr} - ldr r0, =nullsub_89 - bl FuncIsActiveTask - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _08011BEA - ldr r0, =gUnknown_03005000 - adds r0, 0x66 - ldrb r0, [r0] - bl DestroyTask -_08011BEA: - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011BD0 - - thumb_func_start sub_8011BF8 -sub_8011BF8: @ 8011BF8 - push {lr} - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - pop {r0} - bx r0 - thumb_func_end sub_8011BF8 - - thumb_func_start sub_8011C10 -sub_8011C10: @ 8011C10 - push {r4-r6,lr} - adds r4, r0, 0 - ldr r1, =gUnknown_03005000 - movs r0, 0x1 - strb r0, [r1, 0xC] - bl sub_8010F48 - ldr r0, =sub_801120C - movs r1, 0 - bl sub_800BF4C - ldr r2, =gUnknown_02022B2C - adds r1, r2, 0 - ldr r0, =gUnknown_082ED608 - ldm r0!, {r3,r5,r6} - stm r1!, {r3,r5,r6} - ldm r0!, {r3,r5,r6} - stm r1!, {r3,r5,r6} - ldr r0, =gUnknown_082ED620 - subs r4, 0x1 - adds r4, r0 - ldrb r0, [r4] - strh r0, [r2, 0x2] - bl sub_800EE78 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011C10 - - thumb_func_start sub_8011C5C -sub_8011C5C: @ 8011C5C - push {lr} - ldr r1, =gUnknown_03005000 - movs r0, 0 - strb r0, [r1, 0xC] - bl sub_8010F48 - ldr r0, =sub_8011404 - ldr r1, =sub_800ED34 - bl sub_800BF4C - bl sub_800EF00 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011C5C - - thumb_func_start sub_8011C84 -sub_8011C84: @ 8011C84 - push {r4-r7,lr} - ldr r4, =gUnknown_03005000 - movs r5, 0 - movs r0, 0x2 - strb r0, [r4, 0xC] - bl sub_8010F48 - ldr r0, =sub_8011674 - movs r1, 0 - bl sub_800BF4C - ldr r2, =gUnknown_02022B2C - adds r1, r2, 0 - ldr r0, =gUnknown_082ED608 - ldm r0!, {r3,r6,r7} - stm r1!, {r3,r6,r7} - ldm r0!, {r3,r6,r7} - stm r1!, {r3,r6,r7} - strb r5, [r2, 0x11] - movs r0, 0x96 - lsls r0, 2 - strh r0, [r2, 0x12] - ldr r0, =sub_800EB44 - movs r1, 0x1 - bl CreateTask - adds r4, 0x67 - strb r0, [r4] - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011C84 - - thumb_func_start sub_8011CD8 -sub_8011CD8: @ 8011CD8 - ldrb r1, [r0, 0x1] - lsls r1, 8 - ldrb r0, [r0] - orrs r0, r1 - bx lr - thumb_func_end sub_8011CD8 - - thumb_func_start sub_8011CE4 -sub_8011CE4: @ 8011CE4 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x4 - str r0, [sp] - lsls r1, 16 - lsrs r1, 16 - mov r10, r1 - movs r0, 0xFF - mov r9, r0 - movs r7, 0 - ldr r1, =gUnknown_03007890 - mov r8, r1 -_08011D02: - lsls r4, r7, 5 - adds r5, r4, 0 - adds r5, 0x14 - mov r1, r8 - ldr r0, [r1] - adds r0, r5 - adds r0, 0x8 - bl sub_8011CD8 - lsls r0, 16 - lsrs r6, r0, 16 - mov r1, r8 - ldr r0, [r1] - adds r0, r4 - ldrh r0, [r0, 0x18] - bl sub_8010454 - cmp r0, 0 - beq _08011D4C - mov r0, r8 - ldr r1, [r0] - adds r1, r5 - adds r1, 0x15 - ldr r0, [sp] - bl StringCompare - cmp r0, 0 - bne _08011D4C - cmp r10, r6 - bne _08011D4C - mov r9, r7 - mov r1, r8 - ldr r0, [r1] - adds r0, r4 - ldrb r0, [r0, 0x16] - cmp r0, 0xFF - bne _08011D56 -_08011D4C: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - cmp r7, 0x3 - bls _08011D02 -_08011D56: - mov r0, r9 - add sp, 0x4 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8011CE4 - - thumb_func_start sub_8011D6C -sub_8011D6C: @ 8011D6C - push {r4-r6,lr} - adds r6, r0, 0 - lsls r0, r6, 24 - lsrs r0, 24 - bl rfu_REQ_disconnect - bl rfu_waitREQComplete - ldr r4, =gUnknown_03005000 - ldr r0, =0x00000ce2 - adds r5, r4, r0 - ldrb r0, [r5] - bics r0, r6 - strb r0, [r5] - ldr r1, =0x00000cda - adds r6, r4, r1 - ldrb r1, [r6] - movs r0, 0x1 - bl rfu_clearSlot - ldrb r0, [r5] - ldr r1, =0x00000c87 - adds r4, r1 - adds r1, r4, 0 - movs r2, 0x46 - bl rfu_UNI_setSendData - ldrb r0, [r5] - bl sub_800E87C - strb r0, [r6] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011D6C - - thumb_func_start sub_8011DC0 -sub_8011DC0: @ 8011DC0 - push {lr} - lsls r1, 16 - lsrs r1, 16 - bl sub_8011CE4 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0xFF - beq _08011DDA - movs r0, 0x1 - lsls r0, r1 - bl sub_8011D6C -_08011DDA: - pop {r0} - bx r0 - thumb_func_end sub_8011DC0 - - thumb_func_start sub_8011DE0 -sub_8011DE0: @ 8011DE0 - push {r4-r6,lr} - adds r4, r0, 0 - cmp r4, 0 - beq _08011E20 - movs r3, 0 - movs r2, 0 - ldr r5, =gUnknown_03005000+0xCDE - adds r6, r5, 0x4 -_08011DF0: - adds r0, r2, r5 - ldrb r0, [r0] - cmp r0, r4 - bne _08011E0E - ldrb r0, [r6] - asrs r0, r2 - movs r1, 0x1 - ands r0, r1 - cmp r0, 0 - beq _08011E0E - adds r0, r1, 0 - lsls r0, r2 - orrs r3, r0 - lsls r0, r3, 24 - lsrs r3, r0, 24 -_08011E0E: - adds r2, 0x1 - cmp r2, 0x3 - ble _08011DF0 - cmp r3, 0 - beq _08011E20 - adds r0, r3, 0 - movs r1, 0x2 - bl sub_8011E94 -_08011E20: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011DE0 - - thumb_func_start sub_8011E2C -sub_8011E2C: @ 8011E2C - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r6, =gSendCmd - ldrh r0, [r6] - cmp r0, 0 - bne _08011E7A - ldr r5, =gUnknown_03005000 - ldr r1, =0x00000ce8 - adds r0, r5, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _08011E7A - movs r0, 0xED - lsls r0, 8 - bl sub_800FD14 - ldr r1, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r1 - ldrh r1, [r0, 0x8] - strh r1, [r6, 0x2] - ldrh r1, [r0, 0xA] - strh r1, [r6, 0x4] - ldr r1, =gUnknown_082ED695 - movs r2, 0x8 - ldrsh r0, [r0, r2] - adds r0, r1 - ldrb r1, [r5, 0xD] - ldrb r0, [r0] - subs r1, r0 - strb r1, [r5, 0xD] - ldrb r0, [r5, 0xD] - strh r0, [r6, 0x6] - adds r0, r4, 0 - bl DestroyTask -_08011E7A: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011E2C - - thumb_func_start sub_8011E94 -sub_8011E94: @ 8011E94 - push {r4-r6,lr} - adds r4, r0, 0 - adds r6, r1, 0 - ldr r5, =sub_8011E2C - adds r0, r5, 0 - bl FindTaskIdByFunc - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0xFF - bne _08011ECC - adds r0, r5, 0 - movs r1, 0x5 - bl CreateTask - lsls r0, 24 - lsrs r2, r0, 24 - ldr r1, =gTasks - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 3 - adds r0, r1 - strh r4, [r0, 0x8] - b _08011EDC - .pool -_08011ECC: - ldr r0, =gTasks - lsls r1, r2, 2 - adds r1, r2 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0x8] - orrs r4, r0 - strh r4, [r1, 0x8] -_08011EDC: - ldr r1, =gTasks - lsls r0, r2, 2 - adds r0, r2 - lsls r0, 3 - adds r0, r1 - strh r6, [r0, 0xA] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011E94 - - thumb_func_start sub_8011EF4 -sub_8011EF4: @ 8011EF4 - push {r4-r6,lr} - lsls r0, 24 - lsrs r6, r0, 24 - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r4, r0, r1 - bl sub_800EE94 - lsls r0, 24 - cmp r0, 0 - beq _08011FA4 - adds r0, r4, 0 - adds r0, 0x10 - bl sub_8011CD8 - adds r1, r0, 0 - lsls r1, 16 - lsrs r1, 16 - adds r0, r4, 0 - bl sub_8011CE4 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0xFF - beq _08011F8C - ldr r0, =gUnknown_03007890 - ldr r0, [r0] - lsls r1, r2, 5 - adds r0, r1 - ldrb r0, [r0, 0x16] - cmp r0, 0xFF - beq _08011F5C - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000c3d - adds r0, r1 - strb r2, [r0] - bl sub_800EEBC - cmp r0, 0 - beq _08011FAA - b _08011F84 - .pool -_08011F5C: - bl sub_800F7DC - ldrb r1, [r0, 0xA] - movs r5, 0x7F - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x15 - beq _08011FA4 - bl sub_800F7DC - ldrb r1, [r0, 0xA] - adds r0, r5, 0 - ands r0, r1 - cmp r0, 0x16 - beq _08011FA4 - movs r1, 0xE0 - lsls r1, 7 - movs r0, 0x2 - bl sub_8011A64 -_08011F84: - adds r0, r6, 0 - bl DestroyTask - b _08011FAA -_08011F8C: - ldrh r0, [r4, 0x1E] - adds r0, 0x1 - strh r0, [r4, 0x1E] - ldr r0, =gUnknown_03005000 - ldr r1, =0x00000c3d - adds r0, r1 - strb r2, [r0] - b _08011FAA - .pool -_08011FA4: - ldrh r0, [r4, 0x1E] - adds r0, 0x1 - strh r0, [r4, 0x1E] -_08011FAA: - movs r1, 0x1E - ldrsh r0, [r4, r1] - cmp r0, 0xF0 - ble _08011FC2 - movs r1, 0xE0 - lsls r1, 7 - movs r0, 0x2 - bl sub_8011A64 - adds r0, r6, 0 - bl DestroyTask -_08011FC2: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8011EF4 - - thumb_func_start sub_8011FC8 -sub_8011FC8: @ 8011FC8 - push {r4-r6,lr} - adds r6, r0, 0 - lsls r5, r1, 16 - lsrs r5, 16 - ldr r0, =gUnknown_03005000 - adds r0, 0xF1 - movs r1, 0 - strb r1, [r0] - ldr r0, =sub_8011EF4 - movs r1, 0x3 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - lsls r4, r0, 2 - adds r4, r0 - lsls r4, 3 - ldr r0, =gTasks + 0x8 - adds r4, r0 - adds r0, r4, 0 - adds r1, r6, 0 - bl StringCopy - strh r5, [r4, 0x10] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8011FC8 - - thumb_func_start sub_801200C -sub_801200C: @ 801200C - push {r4,r5,lr} - adds r4, r1, 0 - lsls r0, 16 - lsrs r5, r0, 16 - bl sub_800F7DC - ldrb r1, [r0, 0xA] - movs r2, 0x7F - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x45 - bne _08012032 - ldrb r1, [r4, 0xA] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x45 - beq _08012092 -_0801202E: - movs r0, 0x1 - b _08012094 -_08012032: - ldrb r1, [r4, 0xA] - adds r0, r2, 0 - ands r0, r1 - cmp r0, 0x40 - bne _0801202E - cmp r5, 0x44 - bne _08012092 - ldr r5, =gUnknown_03005000+0x10A - ldrh r0, [r5, 0x8] - ldr r3, =0x000003ff - adds r2, r3, 0 - ands r2, r0 - movs r0, 0xCE - lsls r0, 1 - cmp r2, r0 - bne _08012068 - ldrh r1, [r4, 0x8] - adds r0, r3, 0 - ands r0, r1 - cmp r0, r2 - beq _08012092 - b _0801202E - .pool -_08012068: - ldrh r1, [r4, 0x8] - adds r0, r3, 0 - ands r0, r1 - cmp r0, r2 - bne _0801202E - ldrb r2, [r4, 0xB] - movs r0, 0xFE - ldrb r3, [r5, 0xB] - adds r1, r0, 0 - ands r1, r2 - ands r0, r3 - cmp r1, r0 - bne _0801202E - ldrb r2, [r4, 0x9] - movs r0, 0xFC - ldrb r3, [r5, 0x9] - adds r1, r0, 0 - ands r1, r2 - ands r0, r3 - cmp r1, r0 - bne _0801202E -_08012092: - movs r0, 0 -_08012094: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_801200C thumb_func_start sub_801209C sub_801209C: @ 801209C @@ -1557,7 +56,7 @@ _080120E4: movs r2, 0x86 lsls r2, 1 adds r0, r6, r2 - bl sub_8011CD8 + bl ReadU16 adds r1, r0, 0 lsls r1, 16 lsrs r1, 16 diff --git a/include/librfu.h b/include/librfu.h index 9d131f027..ba6e535d4 100644 --- a/include/librfu.h +++ b/include/librfu.h @@ -81,7 +81,7 @@ struct UnkLinkRfuStruct_02022B14Substruct u8 playerTrainerId[2]; }; -struct __attribute__((packed)) UnkLinkRfuStruct_02022B14 +struct __attribute__((packed, aligned(2))) UnkLinkRfuStruct_02022B14 { struct UnkLinkRfuStruct_02022B14Substruct unk_00; u8 unk_04[4]; @@ -169,13 +169,14 @@ struct RfuUnk3 u32 unk_dc; }; -struct RfuUnk5Sub { +struct RfuUnk5Sub +{ u16 unk_00; u8 unk_02; u16 unk_04; struct UnkLinkRfuStruct_02022B14 unk_06; - u8 fill_13[2]; - u8 unk_15[8]; + u8 fill_13[1]; + u8 playerName[PLAYER_NAME_LENGTH + 1]; }; struct RfuUnk5 diff --git a/include/link_rfu.h b/include/link_rfu.h index c3ca75604..eb24addbe 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -32,7 +32,8 @@ struct UnkLinkRfuStruct_02022B44 u8 fill_84[0x58]; }; -struct UnkRfuStruct_1 { +struct UnkRfuStruct_1 +{ /* 0x000 */ u8 unk_00; /* 0x001 */ u8 unk_01; /* 0x002 */ vu8 unk_02; @@ -75,7 +76,8 @@ struct UnkRfuStruct_1 { /* 0xeb4 */ u8 filler_e64[12]; }; -struct UnkRfuStruct_2_Sub_6c { +struct UnkRfuStruct_2_Sub_6c +{ /* 0x00 */ u16 unk_00; /* 0x02 */ u16 unk_02; /* 0x04 */ const u8 *unk_04; @@ -86,7 +88,8 @@ struct UnkRfuStruct_2_Sub_6c { /* 0x12 */ u8 unk_12; }; -struct UnkRfuStruct_2_Sub_124 { +struct UnkRfuStruct_2_Sub_124 +{ /* 0x000 */ u8 unk_00[32][70]; /* 0x8c0 */ vu8 unk_8c0; /* 0x8c1 */ vu8 unk_8c1; @@ -94,7 +97,8 @@ struct UnkRfuStruct_2_Sub_124 { /* 0x8c3 */ vu8 unk_8c3; }; -struct UnkRfuStruct_2_Sub_9e8 { +struct UnkRfuStruct_2_Sub_9e8 +{ /* 0x000 */ u8 unk_00[40][14]; /* 0x230 */ vu8 unk_230; /* 0x231 */ vu8 unk_231; @@ -102,14 +106,16 @@ struct UnkRfuStruct_2_Sub_9e8 { /* 0x233 */ vu8 unk_233; }; -struct UnkRfuStruct_2_Sub_c1c { +struct UnkRfuStruct_2_Sub_c1c +{ /* 0x00 */ u8 unk_00[2][14]; /* 0x1c */ vu8 unk_1c; /* 0x1d */ vu8 unk_1d; /* 0x1e */ vu8 unk_1e; }; -struct UnkRfuStruct_Sub_Unused { +struct UnkRfuStruct_Sub_Unused +{ /* 0x000 */ u8 unk_00[2][256]; /* 0x200 */ vu8 unk_200; /* 0x201 */ vu8 unk_201; @@ -117,7 +123,8 @@ struct UnkRfuStruct_Sub_Unused { /* 0x203 */ vu8 unk_203; }; -struct UnkRfuStruct_2 { +struct UnkRfuStruct_2 +{ /* 0x000 */ void (*unk_00)(void); /* 0x004 */ u16 unk_04; /* 0x006 */ u8 filler_06[4]; @@ -149,7 +156,9 @@ struct UnkRfuStruct_2 { /* 0x0fe */ u16 unk_fe; /* 0x100 */ u16 unk_100; /* 0x102 */ u8 unk_102; - /* 0x103 */ u8 filler_103[0x21]; + /* 0x103 */ u8 filler_103[0x10A - 0x103]; + /* 0x10A */ struct UnkLinkRfuStruct_02022B14 unk_10A; + u8 filler_120[12]; /* 0x124 */ struct UnkRfuStruct_2_Sub_124 unk_124; /* 0x9e8 */ struct UnkRfuStruct_2_Sub_9e8 unk_9e8; /* 0xc1c */ struct UnkRfuStruct_2_Sub_c1c unk_c1c; @@ -252,7 +261,7 @@ void sub_800E3A8(void); void sub_800ED10(void); void sub_800ED28(void); void sub_8011090(u8 a0, u32 a1, u32 a2); -void sub_8011FC8(u8 *a0, u16 a1); +void sub_8011FC8(const u8 *src, u16 trainerId); void sub_8010FA0(bool32 a0, bool32 a1); void sub_8010F60(void); void sub_8010FCC(u32 a0, u32 a1, u32 a2); diff --git a/src/librfu_stwi.c b/src/librfu_stwi.c index 21d38bb38..556b79bf8 100644 --- a/src/librfu_stwi.c +++ b/src/librfu_stwi.c @@ -246,7 +246,7 @@ void STWI_send_SystemConfigREQ(u16 unk1, u8 unk2, u8 unk3) if (!STWI_init(RFU_SYSTEM_CONFIG)) { u8 *packetBytes; - + gRfuState->txParams = 1; packetBytes = gRfuState->txPacket->rfuPacket8.data; @@ -348,7 +348,7 @@ void STWI_send_DataTxREQ(void *in, u8 size) u8 txParams = (size / sizeof(u32)); if (size & (sizeof(u32) - 1)) txParams += 1; - + gRfuState->txParams = txParams; CpuCopy32(in, gRfuState->txPacket->rfuPacket32.data, gRfuState->txParams * sizeof(u32)); STWI_start_Command(); @@ -469,11 +469,11 @@ void STWI_send_CPR_StartREQ(u16 unk0, u16 unk1, u8 unk2) { u32 *packetData; u32 arg1; - + if (!STWI_init(RFU_CPR_START)) { gRfuState->txParams = 2; - + arg1 = unk1 | (unk0 << 16); packetData = gRfuState->txPacket->rfuPacket32.data; packetData[0] = arg1; @@ -569,7 +569,7 @@ void STWI_set_timer(u8 unk) void STWI_stop_timer(void) { gRfuState->timerState = 0; - + REG_TMCNT_L(gRfuState->timerSelect) = 0; REG_TMCNT_H(gRfuState->timerSelect) = 0; } @@ -612,7 +612,7 @@ u16 STWI_init(u8 request) gRfuState->timerActive = 0; gRfuState->unk_12 = 0; gRfuState->unk_15 = 0; - + REG_RCNT = 0x100; REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; return FALSE; @@ -622,22 +622,22 @@ u16 STWI_init(u8 request) int STWI_start_Command() { u16 imeTemp; - + // Yes, it matters that it's casted to a u32... *(u32*)gRfuState->txPacket->rfuPacket8.data = 0x99660000 | (gRfuState->txParams << 8) | gRfuState->activeCommand; REG_SIODATA32 = gRfuState->txPacket->rfuPacket32.command; - + gRfuState->unk_0 = 0; gRfuState->unk_5 = 1; - + imeTemp = REG_IME; REG_IME = 0; REG_IE |= (INTR_FLAG_TIMER0 << gRfuState->timerSelect); REG_IE |= INTR_FLAG_SERIAL; REG_IME = imeTemp; - + REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_MULTI_BUSY | SIO_115200_BPS; - + return 0; } @@ -654,7 +654,7 @@ int STWI_restart_Command(void) { gRfuState->unk_12 = 1; gRfuState->unk_2c = 0; - + if (gRfuState->callbackM) gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); } @@ -662,18 +662,18 @@ int STWI_restart_Command(void) { gRfuState->unk_12 = 1; gRfuState->unk_2c = 0; - + if (gRfuState->callbackM) gRfuState->callbackM(gRfuState->activeCommand, gRfuState->unk_12); - + gRfuState->unk_0 = 4; //TODO: what's 4 } } - + return 0; } -int STWI_reset_ClockCounter() +int STWI_reset_ClockCounter(void) { gRfuState->unk_0 = 5; //TODO: what is 5 gRfuState->txParams = 0; @@ -682,6 +682,6 @@ int STWI_reset_ClockCounter() REG_SIOCNT = 0; REG_SIOCNT = SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS; REG_SIOCNT = (SIO_INTR_ENABLE | SIO_32BIT_MODE | SIO_115200_BPS) + 0x7F; - + return 0; } diff --git a/src/link_rfu.c b/src/link_rfu.c index e85cc7dc3..f026ca3c3 100644 --- a/src/link_rfu.c +++ b/src/link_rfu.c @@ -1,5 +1,3 @@ - -// Includes #include "global.h" #include "malloc.h" #include "battle.h" @@ -15,12 +13,12 @@ #include "librfu.h" #include "rom_8011DC0.h" #include "link_rfu.h" +#include "palette.h" +#include "gpu_regs.h" +#include "constants/species.h" extern u16 gUnknown_03005DA8; - -// Static type declarations - -// Static RAM declarations +extern void nullsub_89(u8 taskId); struct UnkRfuStruct_1 gUnknown_03004140; struct UnkRfuStruct_2 gUnknown_03005000; @@ -32,12 +30,11 @@ IWRAM_DATA u16 gUnknown_03000D90[8]; EWRAM_DATA u8 gWirelessStatusIndicatorSpriteId = 0; EWRAM_DATA ALIGNED(4) struct UnkLinkRfuStruct_02022B14 gUnknown_02022B14 = {}; -EWRAM_DATA ALIGNED(2) u8 gUnknown_02022B22[8] = {}; +EWRAM_DATA ALIGNED(2) u8 gUnknown_02022B22[PLAYER_NAME_LENGTH + 1] = {}; EWRAM_DATA struct UnkLinkRfuStruct_02022B2C gUnknown_02022B2C = {}; EWRAM_DATA struct UnkLinkRfuStruct_02022B44 gUnknown_02022B44 = {}; // Static ROM declarations - static void sub_800C000(void); static void sub_800C7B4(u16 r8, u16 r6); static void sub_800C744(u32 a0); @@ -74,12 +71,15 @@ void sub_80109E8(u16 a0); void sub_8010A70(void *a0); void sub_8010AAC(u8 taskId); void sub_8010D0C(u8 taskId); -void sub_80115EC(u16 a0); +void sub_80115EC(s32 a0); u8 sub_8011CE4(const u8 *a0, u16 a1); -void sub_8011D6C(u8 a0); -void sub_8011E94(u8 a0, u8 a1); +void sub_8011D6C(u32 a0); +void sub_8011E94(u32 a0, u32 a1); u8 sub_8012224(void); void sub_801227C(void); +void sub_801209C(u8 taskId); +void sub_8011BF8(void); +void sub_8011BA4(void); // .rodata @@ -474,7 +474,6 @@ u8 sub_800C054(u8 r5, u16 r7, u16 r8, const u16 *r6) u8 sub_800C12C(u16 r6, u16 r8) { u8 i; - struct RfuUnk5 *tmp; if (gUnknown_03004140.unk_04 != 0 && (gUnknown_03004140.unk_04 < 9 || gUnknown_03004140.unk_04 > 11)) { @@ -2151,12 +2150,12 @@ bool8 sub_800DE7C(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx) if (sub_8010454(gUnknown_03007890->unk_14[idx].unk_04) && ((gUnknown_03007890->unk_07 >> idx) & 1)) { memcpy(buff1, &gUnknown_03007890->unk_14[idx].unk_06, 0xD); - memcpy(buff2, gUnknown_03007890->unk_14[idx].unk_15, sizeof(gUnknown_03007890->unk_14[idx].unk_15)); + memcpy(buff2, gUnknown_03007890->unk_14[idx].playerName, PLAYER_NAME_LENGTH + 1); } else { memset(buff1, 0, 0xD); - memset(buff2, 0, sizeof(gUnknown_03007890->unk_14[idx].unk_15)); + memset(buff2, 0, sizeof(gUnknown_03007890->unk_14[idx].playerName)); } } else @@ -2165,12 +2164,12 @@ bool8 sub_800DE7C(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx) if (sub_8010454(gUnknown_03007890->unk_14[idx].unk_04)) { memcpy(buff1, &gUnknown_03007890->unk_14[idx].unk_06, 0xD); - memcpy(buff2, gUnknown_03007890->unk_14[idx].unk_15, sizeof(gUnknown_03007890->unk_14[idx].unk_15)); + memcpy(buff2, gUnknown_03007890->unk_14[idx].playerName, PLAYER_NAME_LENGTH + 1); } else { memset(buff1, 0, 0xD); - memset(buff2, 0, sizeof(gUnknown_03007890->unk_14[idx].unk_15)); + memset(buff2, 0, PLAYER_NAME_LENGTH + 1); } } return retVal; @@ -2181,13 +2180,13 @@ bool8 sub_800DF34(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx) bool8 retVal = FALSE; if (gUnknown_03007890->unk_14[idx].unk_04 == 0x7F7D) { - *buff1 = gUnknown_03007890->unk_14[idx].unk_06; - memcpy(buff2, gUnknown_03007890->unk_14[idx].unk_15, 8); + memcpy(buff1, &gUnknown_03007890->unk_14[idx].unk_06, 0xD); + memcpy(buff2, gUnknown_03007890->unk_14[idx].playerName, 8); retVal = TRUE; } else { - *buff1 = (struct UnkLinkRfuStruct_02022B14){}; + memset(buff1, 0, 0xD); memset(buff2, 0, 8); } return retVal; @@ -2195,7 +2194,7 @@ bool8 sub_800DF34(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2, u8 idx) void sub_800DF90(struct UnkLinkRfuStruct_02022B14 *buff1, u8 *buff2) { - *buff1 = gUnknown_02022B14; + memcpy(buff1, &gUnknown_02022B14, 0xD); memcpy(buff2, gUnknown_02022B22, 8); } @@ -2441,7 +2440,7 @@ void sub_800E5AC(void) } } -void nullsub_5(void *unused_0, u8 unused_1, u8 unused_2) +void nullsub_5(const char *unused_0, u8 unused_1, u8 unused_2) { // debug? } @@ -2537,7 +2536,7 @@ void sub_800E748(u8 taskId) } } -u8 sub_800E87C(u8 idx) +s32 sub_800E87C(u8 idx) { return gUnknown_082ED6A5[idx]; } @@ -2815,7 +2814,7 @@ bool8 sub_800EE94(void) return FALSE; } -bool8 sub_800EEBC(void) +bool32 sub_800EEBC(void) { if (gUnknown_03005000.unk_04 == 7 && !sub_800C12C(gUnknown_03007890->unk_14[gUnknown_03005000.unk_c3d].unk_00, 240)) { @@ -3503,7 +3502,7 @@ void sub_800FD14(u16 command) void sub_800FE50(u16 *a0) { - if (gSendCmd[0] == 0 && sub_8011A80() == 0) + if (gSendCmd[0] == 0 && !sub_8011A80()) { memcpy(gUnknown_03005000.unk_f2, a0, sizeof(gUnknown_03005000.unk_f2)); sub_800FD14(0x2f00); @@ -4246,7 +4245,7 @@ void sub_8010F48(void) void sub_8010F60(void) { - gUnknown_02022B14 = (struct UnkLinkRfuStruct_02022B14){}; + memset(&gUnknown_02022B14, 0, 0xD); sub_800DD94(&gUnknown_02022B14, 0, 0, 0); } @@ -4359,7 +4358,7 @@ void sub_80111FC(void) gUnknown_03005000.unk_00 = sub_80111DC; } -void sub_801120C(u8 a0) +void sub_801120C(u8 a0, u8 unused1) { u8 i; u8 r6 = 0; @@ -4443,3 +4442,554 @@ void sub_801120C(u8 a0) break; } } + +void sub_8011404(u8 a0, u8 unused1) +{ + switch (a0) + { + case 0x00: + gUnknown_03005000.unk_04 = 6; + break; + case 0x20: + gUnknown_03005000.unk_ccd = gUnknown_03004140.unk_14; + break; + case 0x21: + break; + case 0x22: + gUnknown_03005000.unk_c3e = gUnknown_03004140.unk_14; + break; + case 0x23: + sub_8011A64(2, a0); + break; + case 0x24: + gUnknown_03005000.unk_04 = 11; + gUnknown_03005000.unk_c85 = 0; + gUnknown_03005000.unk_c86 = 0; + rfu_setRecvBuffer(0x20, gUnknown_03005000.unk_c3e, &gUnknown_03005000.unk_c86, 1); + rfu_setRecvBuffer(0x10, gUnknown_03005000.unk_c3e, gUnknown_03005000.unk_c3f, 70); + break; + case 0x25: + sub_8011A64(2, 0x25); + break; + case 0x30: + gUnknown_03005000.unk_f0 = 2; + if (gUnknown_03005000.unk_c86 == 6) + break; + case 0x33: + if (gUnknown_03005000.unk_f0 != 2) + gUnknown_03005000.unk_f0 = 4; + if (gUnknown_03005000.unk_c86 != 9) + sub_8011A64(2, a0); + nullsub_5(gUnknown_082ED7FC, 5, 5); + if (gReceivedRemoteLinkPlayers == 1) + sub_8011170(a0); + break; + case 0x31: + gUnknown_03005000.unk_f0 = 1; + nullsub_5(gUnknown_082ED814, 5, 5); + break; + case 0x32: + gUnknown_03005000.unk_f0 = 3; + gUnknown_03005000.unk_c3c = 1; + break; + case 0x34: + break; + case 0x42 ... 0x44: + break; + case 0xF3: + sub_8011A64(1, a0); + sub_8011170(a0); + gUnknown_03005000.unk_ef = 1; + break; + case 0xF0 ... 0xF2: + case 0xFF: + sub_8011A64(1, a0); + sub_8011170(a0); + gUnknown_03005000.unk_cdb = 1; + break; + } +} + +void sub_80115EC(s32 a0) +{ + s32 i; + + for (i = 0; i < 4; i++) + { + if ((a0 >> i) & 1) + { + gUnknown_03005000.unk_cea[i] = 0; + gUnknown_03005000.unk_cee[i] |= 0xFF; + } + } +} + +u8 sub_8011628(s32 a0) +{ + u8 ret = 0; + u8 i; + + for (i = 0; i < 4; i++) + { + if ((a0 >> i) & 1) + { + struct UnkLinkRfuStruct_02022B14 *structPtr = &gUnknown_03007890->unk_14[i].unk_06; + if (structPtr->unk_0a_0 == 0x45) + ret |= (1 << i); + } + } + + return ret; +} + +void sub_8011674(u8 a0, u8 unused1) +{ + u8 r1; + + switch (a0) + { + case 0x00: + gUnknown_03005000.unk_04 = 0x11; + break; + case 0x10: + sub_8011A64(4, 0); + break; + case 0x11: + if (sub_800F7DC()->unk_0a_0 == 0x45 && gUnknown_03005000.unk_cd9 == 0) + { + u8 idx = sub_8011628(gUnknown_03004140.unk_14); + if (idx != 0) + { + r1 = 1 << sub_800E87C(idx); + if (gUnknown_03005000.unk_ce6 == 0 && gUnknown_03005000.unk_ce8 == 0) + { + gUnknown_03005000.unk_ce5 = r1; + gUnknown_03005000.unk_ce6 |= (r1 ^ idx); + gUnknown_03005000.unk_ce8 = 1; + } + else + { + gUnknown_03005000.unk_ce6 |= idx; + } + } + if (idx != gUnknown_03004140.unk_14) + { + gUnknown_03005000.unk_ce3 |= (idx ^ gUnknown_03004140.unk_14); + gUnknown_03005000.unk_ce4 = 2; + } + } + else if (sub_800F7DC()->unk_0a_0 == 0x54) + { + rfu_REQ_disconnect(gUnknown_03004140.unk_00); + rfu_waitREQComplete(); + } + sub_80115EC(gUnknown_03004140.unk_14); + break; + case 0x12: + break; + case 0x13: + break; + case 0x14: + if (sub_800F7DC()->unk_0a_0 != 0x45 && gUnknown_03004140.unk_01 > 1) + { + r1 = 1 << sub_800E87C(gUnknown_03004140.unk_14); + rfu_REQ_disconnect(gUnknown_03004140.unk_00 ^ r1); + rfu_waitREQComplete(); + } + if (gUnknown_03005000.unk_04 == 0xF) + gUnknown_03005000.unk_04 = 0x10; + break; + break; + case 0x20: + gUnknown_03005000.unk_ccd = gUnknown_03004140.unk_14; + break; + case 0x21: + break; + case 0x22: + gUnknown_03005000.unk_c3e = gUnknown_03004140.unk_14; + break; + case 0x23: + gUnknown_03005000.unk_04 = 0x12; + if (gUnknown_03005000.unk_ccf < 2) + { + gUnknown_03005000.unk_ccf++; + CreateTask(sub_801209C, 2); + } + else + { + sub_8011A64(2, a0); + } + break; + case 0x24: + gUnknown_03005000.unk_04 = 0xD; + sub_8011A64(3, 0); + rfu_setRecvBuffer(0x10, gUnknown_03005000.unk_c3e, gUnknown_03005000.unk_c3f, 70); + break; + case 0x25: + sub_8011A64(2, a0); + break; + case 0x31: + if (gUnknown_03004140.unk_00 & gUnknown_03004140.unk_14) + gUnknown_03005000.unk_f0 = 1; + break; + case 0x32: + gUnknown_03005000.unk_f0 = 3; + if (gUnknown_03007890->unk_00 == 0) + gUnknown_03005000.unk_c3c = 1; + break; + case 0x30: + gUnknown_03005000.unk_f0 = 2; + case 0x33: + if (gUnknown_03005000.unk_f0 != 2) + gUnknown_03005000.unk_f0 = 4; + if (gUnknown_03005000.unk_0c == 1) + { + if (gReceivedRemoteLinkPlayers == 1) + { + gUnknown_03005000.unk_ce2 &= ~(gUnknown_03004140.unk_14); + if (gUnknown_03005000.unk_ce2 == 0) + sub_8011170(a0); + else + sub_80111FC(); + } + } + else if (gUnknown_03005000.unk_ce4 != 2 && gReceivedRemoteLinkPlayers == 1) + { + sub_8011170(a0); + sub_800C27C(0); + } + + if (gUnknown_03007890->unk_00 == 0xFF && gUnknown_03004140.unk_07 == 0 && FuncIsActiveTask(sub_800EB44) == TRUE) + gUnknown_03005000.unk_04 = 0x11; + + sub_8011A64(2, a0); + break; + case 0x40: + gUnknown_03005000.unk_ce3 = 0; + break; + case 0x42 ... 0x44: + break; + case 0xF3: + sub_8011A64(1, a0); + sub_8011170(a0); + gUnknown_03005000.unk_ef = 1; + break; + case 0xF0 ... 0xF2: + case 0xFF: + sub_8011170(a0); + sub_8011A64(1, a0); + gUnknown_03005000.unk_cdb = 0; + break; + } +} + +void sub_8011A50(void) +{ + gUnknown_03005000.unk_ce4 = 2; +} + +void sub_8011A64(u8 a0, u16 a1) +{ + gUnknown_03005000.unk_f1 = a0; + gUnknown_03005000.unk_0a = a1; +} + +u8 sub_8011A74(void) +{ + return gUnknown_03005000.unk_f1; +} + +bool32 sub_8011A80(void) +{ + u32 var = sub_8011A74() - 1; + if (var < 2) + return TRUE; + else + return FALSE; +} + +u8 sub_8011A9C(void) +{ + return gUnknown_03005000.unk_ce8; +} + +bool8 Rfu_IsMaster(void) +{ + return gUnknown_03005000.unk_0c; +} + +void RfuVSync(void) +{ + rfu_syncVBlank_(); +} + +void sub_8011AC8(void) +{ + CpuFill32(0, gRecvCmds, sizeof(gRecvCmds)); +} + +void sub_8011AE8(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void sub_8011AFC(void) +{ + s32 i; + + ResetSpriteData(); + FreeAllSpritePalettes(); + ResetTasks(); + ResetPaletteFade(); + SetVBlankCallback(sub_8011AE8); + if (IsWirelessAdapterConnected()) + { + gLinkType = 0x1111; + sub_800B488(); + OpenLink(); + SeedRng(gMain.vblankCounter2); + for (i = 0; i < 4; i++) + gSaveBlock2Ptr->playerTrainerId[i] = Random() % 256; + + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP); + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); + sub_8011BA4(); + SetMainCallback2(sub_8011BF8); + } +} + +bool32 sub_8011B90(void) +{ + return FuncIsActiveTask(sub_800EB44); +} + +void sub_8011BA4(void) +{ + if (!FuncIsActiveTask(nullsub_89)) + gUnknown_03005000.unk_66 = CreateTask(nullsub_89, 0); +} + +void sub_8011BD0(void) +{ + if (FuncIsActiveTask(nullsub_89) == TRUE) + DestroyTask(gUnknown_03005000.unk_66); +} + +void sub_8011BF8(void) +{ + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void sub_8011C10(u32 a0) +{ + gUnknown_03005000.unk_0c = 1; + sub_8010F48(); + sub_800BF4C(sub_801120C, NULL); + gUnknown_02022B2C = gUnknown_082ED608; + gUnknown_02022B2C.unk_02 = gUnknown_082ED620[a0 - 1]; + sub_800EE78(); +} + +void sub_8011C5C(void) +{ + gUnknown_03005000.unk_0c = 0; + sub_8010F48(); + sub_800BF4C(sub_8011404, sub_800ED34); + sub_800EF00(); +} + +void sub_8011C84(void) +{ + gUnknown_03005000.unk_0c = 2; + sub_8010F48(); + sub_800BF4C(sub_8011674, NULL); + gUnknown_02022B2C = gUnknown_082ED608; + gUnknown_02022B2C.unk_11 = 0; + gUnknown_02022B2C.unk_12 = 0x258; + gUnknown_03005000.unk_67 = CreateTask(sub_800EB44, 1); +} + +u16 ReadU16(const void *ptr) +{ + const u8 *ptr_ = ptr; + return (ptr_[1] << 8) | (ptr_[0]); +} + +u8 sub_8011CE4(const u8 *a0, u16 a1) +{ + u8 i; + u8 ret = 0xFF; + + for (i = 0; i < 4; i++) + { + u16 trainerId = ReadU16(gUnknown_03007890->unk_14[i].unk_06.unk_00.playerTrainerId); + if (sub_8010454(gUnknown_03007890->unk_14[i].unk_04) + && !StringCompare(a0, gUnknown_03007890->unk_14[i].playerName) + && a1 == trainerId) + { + ret = i; + if (gUnknown_03007890->unk_14[i].unk_02 != 0xFF) + break; + } + } + + return ret; +} + +void sub_8011D6C(u32 a0) +{ + rfu_REQ_disconnect(a0); + rfu_waitREQComplete(); + gUnknown_03005000.unk_ce2 &= ~(a0); + rfu_clearSlot(1, gUnknown_03005000.unk_cda); + rfu_UNI_setSendData(gUnknown_03005000.unk_ce2, gUnknown_03005000.unk_c87, 70); + gUnknown_03005000.unk_cda = sub_800E87C(gUnknown_03005000.unk_ce2); +} + +void sub_8011DC0(const u8 *ptr, u16 a1) +{ + u8 var = sub_8011CE4(ptr, a1); + if (var != 0xFF) + sub_8011D6C(1 << var); +} + +void sub_8011DE0(u32 a0) +{ + if (a0 != 0) + { + s32 i; + u8 var = 0; + + for (i = 0; i < 4; i++) + { + if (gUnknown_03005000.unk_cde[i] == a0 && (gUnknown_03005000.unk_ce2 >> i) & 1) + var |= 1 << i; + } + if (var) + sub_8011E94(var, 2); + } +} + +void sub_8011E2C(u8 taskId) +{ + if (gSendCmd[0] == 0 && gUnknown_03005000.unk_ce8 == 0) + { + sub_800FD14(0xED00); + gSendCmd[1] = gTasks[taskId].data[0]; + gSendCmd[2] = gTasks[taskId].data[1]; + gUnknown_03005000.playerCount -= gUnknown_082ED695[gTasks[taskId].data[0]]; + gSendCmd[3] = gUnknown_03005000.playerCount; + DestroyTask(taskId); + } +} + +void sub_8011E94(u32 a0, u32 a1) +{ + u8 taskId = FindTaskIdByFunc(sub_8011E2C); + if (taskId == 0xFF) + { + taskId = CreateTask(sub_8011E2C, 5); + gTasks[taskId].data[0] = a0; + } + else + { + gTasks[taskId].data[0] |= a0; + } + + gTasks[taskId].data[1] = a1; +} + +void sub_8011EF4(u8 taskId) +{ + s16 *data = gTasks[taskId].data; + + if (sub_800EE94()) + { + u8 id = sub_8011CE4((u8*)data, ReadU16(&data[8])); + if (id != 0xFF) + { + if (gUnknown_03007890->unk_14[id].unk_02 != 0xFF) + { + gUnknown_03005000.unk_c3d = id; + if (sub_800EEBC()) + DestroyTask(taskId); + } + else if (sub_800F7DC()->unk_0a_0 == 0x15 || sub_800F7DC()->unk_0a_0 == 0x16) + { + data[15]++; + } + else + { + sub_8011A64(2, 0x7000); + DestroyTask(taskId); + } + } + else + { + data[15]++; + gUnknown_03005000.unk_c3d = id; + } + } + else + { + data[15]++; + } + + if (data[15] > 240) + { + sub_8011A64(2, 0x7000); + DestroyTask(taskId); + } +} + +void sub_8011FC8(const u8 *src, u16 trainerId) +{ + u8 taskId; + s16 *data; + + gUnknown_03005000.unk_f1 = 0; + taskId = CreateTask(sub_8011EF4, 3); + data = gTasks[taskId].data; + StringCopy((u8*)(data), src); + data[8] = trainerId; +} + +bool32 sub_801200C(u16 a1, struct UnkLinkRfuStruct_02022B14 *structPtr) +{ + if (sub_800F7DC()->unk_0a_0 == 0x45) + { + if (structPtr->unk_0a_0 != 0x45) + return TRUE; + } + else if (structPtr->unk_0a_0 != 0x40) + { + return TRUE; + } + else if (a1 == 0x44) + { + struct UnkLinkRfuStruct_02022B14 *structPtr2 = &gUnknown_03005000.unk_10A; + if (structPtr2->species == SPECIES_EGG) + { + if (structPtr->species == structPtr2->species) + return FALSE; + else + return TRUE; + } + else if (structPtr->species != structPtr2->species + || structPtr->unk_0b_1 != structPtr2->unk_0b_1 + || structPtr->type != structPtr2->type) + { + return TRUE; + } + } + + return FALSE; +}