From 50c48d7ef63ffdb40e3019d25396baedef98a9dc Mon Sep 17 00:00:00 2001 From: jiangzhengwenjz Date: Sun, 15 Dec 2019 14:04:15 +0800 Subject: [PATCH] sub_8023BC0 --- asm/berry_crush.s | 1604 --------------------------------------------- src/berry_crush.c | 694 ++++++++++++++++++-- 2 files changed, 649 insertions(+), 1649 deletions(-) diff --git a/asm/berry_crush.s b/asm/berry_crush.s index ebf819188..247341448 100755 --- a/asm/berry_crush.s +++ b/asm/berry_crush.s @@ -5,1610 +5,6 @@ .text - thumb_func_start sub_8022F1C -sub_8022F1C: @ 8022F1C - push {r4-r7,lr} - sub sp, 0x4 - adds r5, r0, 0 - adds r2, r1, 0 - ldrb r0, [r5, 0xC] - cmp r0, 0x5 - bls _08022F2C - b _08023060 -_08022F2C: - lsls r0, 2 - ldr r1, =_08022F3C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08022F3C: - .4byte _08022F54 - .4byte _08022F74 - .4byte _08022F7A - .4byte _08022FAA - .4byte _08022FBA - .4byte _08023044 -_08022F54: - movs r0, 0x1 - str r0, [sp] - adds r0, r2, 0 - movs r1, 0x1 - movs r2, 0 - movs r3, 0 - bl sub_8024644 - movs r0, 0x9 - strb r0, [r5, 0xE] - movs r0, 0x3 - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - b _08023066 -_08022F74: - bl sub_8010434 - b _08023060 -_08022F7A: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08023066 - adds r4, r5, 0 - adds r4, 0x42 - adds r0, r4, 0 - movs r1, 0 - movs r2, 0xC - bl memset - ldrb r0, [r5, 0x8] - lsls r0, 5 - adds r0, r5, r0 - adds r0, 0xA4 - ldrh r0, [r0] - strh r0, [r4] - movs r0, 0 - adds r1, r4, 0 - movs r2, 0x2 - bl SendBlock - b _08023060 -_08022FAA: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08023066 - movs r0, 0 - strh r0, [r5, 0x10] - b _08023060 -_08022FBA: - bl GetBlockReceivedStatus - ldr r2, =gUnknown_082F4448 - ldrb r4, [r5, 0x9] - subs r1, r4, 0x2 - adds r1, r2 - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r1] - cmp r0, r1 - bne _08023066 - movs r3, 0 - cmp r3, r4 - bcs _0802301E - ldr r7, =gBlockRecvBuffer - movs r6, 0 - ldr r4, =gUnknown_0858AB24 -_08022FDC: - lsls r0, r3, 5 - adds r0, r5, r0 - lsls r1, r3, 8 - adds r1, r7 - ldrh r1, [r1] - adds r2, r0, 0 - adds r2, 0xA4 - strh r1, [r2] - lsls r1, 16 - lsrs r1, 16 - cmp r1, 0xB0 - bls _08022FF6 - strh r6, [r2] -_08022FF6: - ldrh r1, [r2] - lsls r1, 2 - adds r1, r4 - ldrh r0, [r5, 0x18] - ldrb r1, [r1] - adds r0, r1 - strh r0, [r5, 0x18] - ldrh r0, [r2] - lsls r0, 2 - adds r0, r4 - ldrh r1, [r0, 0x2] - ldr r0, [r5, 0x1C] - adds r0, r1 - str r0, [r5, 0x1C] - adds r0, r3, 0x1 - lsls r0, 24 - lsrs r3, r0, 24 - ldrb r0, [r5, 0x9] - cmp r3, r0 - bcc _08022FDC -_0802301E: - movs r0, 0 - strh r0, [r5, 0x10] - bl ResetBlockReceivedFlags - movs r1, 0x18 - ldrsh r0, [r5, r1] - lsls r0, 8 - movs r1, 0x80 - lsls r1, 6 - bl sub_81515FC - str r0, [r5, 0x20] - b _08023060 - .pool -_08023044: - movs r0, 0 - movs r1, 0x1 - bl ClearDialogWindowAndFrame - movs r0, 0xA - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - movs r1, 0 - movs r0, 0x4 - strh r0, [r5, 0x12] - strb r1, [r5, 0xC] - b _08023066 -_08023060: - ldrb r0, [r5, 0xC] - adds r0, 0x1 - strb r0, [r5, 0xC] -_08023066: - movs r0, 0 - add sp, 0x4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8022F1C - - thumb_func_start sub_8023070 -sub_8023070: @ 8023070 - push {r4,lr} - adds r4, r0, 0 - ldrb r0, [r4, 0xC] - cmp r0, 0x6 - bls _0802307C - b _080231A8 -_0802307C: - lsls r0, 2 - ldr r1, =_0802308C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0802308C: - .4byte _080230A8 - .4byte _080230BA - .4byte _080230E8 - .4byte _08023120 - .4byte _08023150 - .4byte _08023172 - .4byte _08023184 -_080230A8: - movs r0, 0x9C - lsls r0, 1 - adds r1, r4, r0 - adds r0, r4, 0 - bl sub_80214A8 - bl sub_8010434 - b _080231A8 -_080230BA: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _080231AE - movs r2, 0x9C - lsls r2, 1 - adds r1, r4, r2 - movs r0, 0 - strb r0, [r1] - ldr r3, =0x00000139 - adds r1, r4, r3 - strb r0, [r1] - adds r2, 0x2 - adds r1, r4, r2 - strb r0, [r1] - adds r3, 0x2 - adds r1, r4, r3 - strb r0, [r1] - b _080231A8 - .pool -_080230E8: - movs r0, 0x9C - lsls r0, 1 - adds r3, r4, r0 - ldrb r0, [r3] - lsls r0, 2 - movs r2, 0xB8 - lsls r2, 1 - adds r1, r4, r2 - adds r0, r1, r0 - ldr r2, [r0] - ldr r0, =sub_8021608 - str r0, [r2, 0x1C] - ldrb r0, [r3] - lsls r0, 2 - adds r1, r0 - ldr r1, [r1] - adds r1, 0x2C - ldrb r2, [r1] - movs r0, 0x7F - ands r0, r2 - strb r0, [r1] - movs r0, 0x3D - bl PlaySE - b _080231A8 - .pool -_08023120: - movs r3, 0x9C - lsls r3, 1 - adds r2, r4, r3 - ldrb r0, [r2] - lsls r0, 2 - adds r3, 0x38 - adds r1, r4, r3 - adds r3, r1, r0 - ldr r0, [r3] - ldr r1, [r0, 0x1C] - ldr r0, =sub_8021608 - cmp r1, r0 - beq _080231AE - movs r0, 0 - str r0, [r3] - ldrb r0, [r2] - adds r0, 0x1 - strb r0, [r2] - bl sub_8010434 - b _080231A8 - .pool -_08023150: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _080231AE - movs r0, 0x9C - lsls r0, 1 - adds r1, r4, r0 - ldrb r0, [r1] - ldrb r2, [r4, 0x9] - cmp r0, r2 - bcs _0802316C - movs r0, 0x2 - b _080231AC -_0802316C: - movs r0, 0 - strb r0, [r1] - b _080231A8 -_08023172: - movs r3, 0x9C - lsls r3, 1 - adds r1, r4, r3 - adds r0, r4, 0 - bl sub_80216A8 - bl sub_8010434 - b _080231A8 -_08023184: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _080231AE - movs r0, 0x2B - bl PlaySE - movs r0, 0xB - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - movs r1, 0 - movs r0, 0x5 - strh r0, [r4, 0x12] - strb r1, [r4, 0xC] - b _080231AE -_080231A8: - ldrb r0, [r4, 0xC] - adds r0, 0x1 -_080231AC: - strb r0, [r4, 0xC] -_080231AE: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8023070 - - thumb_func_start sub_80231B8 -sub_80231B8: @ 80231B8 - push {r4-r7,lr} - adds r4, r0, 0 - ldrb r1, [r4, 0xC] - cmp r1, 0x1 - beq _0802321C - cmp r1, 0x1 - bgt _080231CC - cmp r1, 0 - beq _080231D6 - b _080232DC -_080231CC: - cmp r1, 0x2 - beq _0802329C - cmp r1, 0x3 - beq _080232BE - b _080232DC -_080231D6: - ldrh r0, [r4, 0x2A] - adds r0, 0x4 - strh r0, [r4, 0x2A] - lsls r0, 16 - cmp r0, 0 - bge _080231E4 - b _080232E2 -_080231E4: - strh r1, [r4, 0x2A] - ldr r0, =0x00000139 - adds r3, r4, r0 - movs r0, 0x4 - strb r0, [r3] - movs r2, 0x9C - lsls r2, 1 - adds r1, r4, r2 - movs r0, 0 - strb r0, [r1] - ldr r2, =gUnknown_082F326C - ldrb r1, [r3] - lsls r0, r1, 3 - subs r0, r1 - adds r0, r2 - ldrb r0, [r0] - movs r2, 0x9D - lsls r2, 1 - adds r1, r4, r2 - strb r0, [r1] - movs r0, 0xD6 - bl PlaySE - b _080232DC - .pool -_0802321C: - ldr r7, =gUnknown_082F326C - movs r0, 0x9C - lsls r0, 1 - adds r6, r4, r0 - ldr r1, =0x00000139 - adds r5, r4, r1 - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - ldrb r2, [r6] - adds r0, r2 - adds r0, r7 - movs r1, 0 - ldrsb r1, [r0, r1] - strh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x12 - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1A - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1E - bl SetGpuReg - ldrb r0, [r6] - adds r0, 0x1 - strb r0, [r6] - movs r1, 0x9D - lsls r1, 1 - adds r2, r4, r1 - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r2] - cmp r0, r1 - bcc _080232E2 - ldrb r0, [r5] - cmp r0, 0 - beq _080232DC - subs r0, 0x1 - strb r0, [r5] - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - adds r0, r7 - ldrb r0, [r0] - strb r0, [r2] - movs r0, 0 - strb r0, [r6] - b _080232E2 - .pool -_0802329C: - movs r0, 0 - strh r0, [r4, 0x2C] - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - bl sub_8010434 - b _080232DC -_080232BE: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _080232E2 - movs r0, 0xC - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - movs r1, 0 - movs r0, 0x6 - strh r0, [r4, 0x12] - strb r1, [r4, 0xC] - b _080232E2 -_080232DC: - ldrb r0, [r4, 0xC] - adds r0, 0x1 - strb r0, [r4, 0xC] -_080232E2: - movs r0, 0 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80231B8 - - thumb_func_start sub_80232EC -sub_80232EC: @ 80232EC - push {r4,lr} - sub sp, 0x4 - adds r4, r0, 0 - ldrb r0, [r4, 0xC] - cmp r0, 0x1 - beq _0802330C - cmp r0, 0x1 - bgt _08023302 - cmp r0, 0 - beq _08023332 - b _0802338C -_08023302: - cmp r0, 0x2 - beq _0802332A - cmp r0, 0x3 - beq _08023338 - b _0802338C -_0802330C: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08023392 - movs r1, 0x80 - lsls r1, 5 - movs r0, 0 - str r0, [sp] - adds r0, r1, 0 - movs r2, 0x78 - movs r3, 0x50 - bl sub_802EB24 - b _0802338C -_0802332A: - bl sub_802EB84 - cmp r0, 0 - bne _08023392 -_08023332: - bl sub_8010434 - b _0802338C -_08023338: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08023392 - movs r0, 0x9C - lsls r0, 1 - adds r1, r4, r0 - movs r0, 0 - strb r0, [r1] - ldr r2, =0x00000139 - adds r1, r4, r2 - strb r0, [r1] - adds r2, 0x1 - adds r1, r4, r2 - strb r0, [r1] - adds r2, 0x1 - adds r1, r4, r2 - strb r0, [r1] - strh r0, [r4, 0x10] - ldrb r0, [r4, 0x8] - cmp r0, 0 - bne _08023378 - movs r0, 0xD - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - b _08023382 - .pool -_08023378: - movs r0, 0xE - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC -_08023382: - movs r1, 0 - movs r0, 0x7 - strh r0, [r4, 0x12] - strb r1, [r4, 0xC] - b _08023392 -_0802338C: - ldrb r0, [r4, 0xC] - adds r0, 0x1 - strb r0, [r4, 0xC] -_08023392: - movs r0, 0 - add sp, 0x4 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80232EC - - thumb_func_start sub_802339C -sub_802339C: @ 802339C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - adds r4, r0, 0 - movs r0, 0 - mov r8, r0 - movs r2, 0 - adds r7, r2, 0 - ldrb r1, [r4, 0x9] - cmp r7, r1 - bcs _080234AA - movs r2, 0x5E - adds r2, r4 - mov r9, r2 - ldr r3, =gUnknown_082F325C - mov r10, r3 -_080233C0: - lsls r0, r7, 4 - ldr r1, =gRecvCmds - adds r2, r0, r1 - ldrh r1, [r2] - movs r0, 0xFF - lsls r0, 8 - ands r0, r1 - movs r3, 0xBC - lsls r3, 6 - cmp r0, r3 - bne _0802349E - ldrh r0, [r2, 0x2] - cmp r0, 0x2 - bne _0802349E - ldrb r1, [r2, 0x4] - movs r0, 0x4 - ands r0, r1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - beq _08023496 - mov r0, r9 - ldrb r2, [r0] - lsrs r1, r2, 3 - mov r3, r10 - adds r0, r7, r3 - ldrb r0, [r0] - orrs r1, r0 - lsls r1, 3 - movs r0, 0x7 - ands r0, r2 - orrs r0, r1 - mov r1, r9 - strb r0, [r1] - lsls r2, r7, 5 - adds r3, r4, r2 - mov r12, r3 - mov r1, r12 - adds r1, 0xB5 - movs r0, 0x1 - strb r0, [r1] - subs r1, 0x7 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - mov r0, r8 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - subs r1, 0x8 - ldrh r0, [r4, 0x28] - ldrh r1, [r1] - subs r0, r1 - lsls r0, 16 - lsrs r3, r0, 16 - mov r5, r12 - adds r5, 0xAA - ldrh r1, [r5] - subs r0, r1, 0x1 - adds r6, r2, 0 - cmp r3, r0 - blt _08023468 - adds r0, r1, 0x1 - cmp r3, r0 - bgt _08023468 - mov r1, r12 - adds r1, 0xA8 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - strh r3, [r5] - mov r0, r12 - adds r0, 0xAC - ldrh r1, [r1] - ldrh r2, [r0] - cmp r1, r2 - bls _08023476 - strh r1, [r0] - b _08023476 - .pool -_08023468: - adds r0, r4, r6 - adds r2, r0, 0 - adds r2, 0xA8 - movs r1, 0 - strh r1, [r2] - adds r0, 0xAA - strh r3, [r0] -_08023476: - adds r1, r4, r6 - ldrh r0, [r4, 0x28] - adds r3, r1, 0 - adds r3, 0xA6 - movs r2, 0 - strh r0, [r3] - adds r1, 0xB4 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bls _0802349E - strb r2, [r1] - b _0802349E -_08023496: - lsls r0, r7, 5 - adds r0, r4, r0 - adds r0, 0xB5 - strb r1, [r0] -_0802349E: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - ldrb r3, [r4, 0x9] - cmp r7, r3 - bcc _080233C0 -_080234AA: - mov r0, r8 - cmp r0, 0x1 - bls _080234E0 - movs r7, 0 - ldrb r1, [r4, 0x9] - cmp r7, r1 - bcs _080234E0 - movs r3, 0x2 -_080234BA: - lsls r0, r7, 5 - adds r1, r4, r0 - adds r2, r1, 0 - adds r2, 0xB5 - ldrb r0, [r2] - cmp r0, 0 - beq _080234D4 - orrs r0, r3 - strb r0, [r2] - adds r1, 0xB0 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] -_080234D4: - adds r0, r7, 0x1 - lsls r0, 24 - lsrs r7, r0, 24 - ldrb r2, [r4, 0x9] - cmp r7, r2 - bcc _080234BA -_080234E0: - mov r3, r8 - cmp r3, 0 - beq _08023548 - ldrh r0, [r4, 0x2E] - add r0, r8 - strh r0, [r4, 0x2E] - ldr r1, =gUnknown_082F3264 - mov r0, r8 - subs r0, 0x1 - adds r0, r1 - ldrb r0, [r0] - add r0, r8 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - ldrh r0, [r4, 0x34] - add r0, r8 - strh r0, [r4, 0x34] - ldrh r0, [r4, 0x1A] - add r0, r8 - strh r0, [r4, 0x1A] - movs r1, 0x18 - ldrsh r0, [r4, r1] - movs r3, 0x1A - ldrsh r2, [r4, r3] - subs r0, r2 - cmp r0, 0 - ble _08023534 - lsls r2, 8 - ldr r1, [r4, 0x20] - adds r0, r2, 0 - bl sub_81515FC - adds r2, r0, 0 - asrs r2, 8 - adds r0, r4, 0 - adds r0, 0x24 - strb r2, [r0] - b _08023548 - .pool -_08023534: - adds r1, r4, 0 - adds r1, 0x24 - movs r0, 0x20 - strb r0, [r1] - adds r2, r4, 0 - adds r2, 0x5E - ldrb r0, [r2] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r2] -_08023548: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_802339C - - thumb_func_start sub_8023558 -sub_8023558: @ 8023558 - push {r4-r6,lr} - adds r3, r0, 0 - movs r6, 0 - movs r1, 0 - adds r4, r1, 0 - ldrb r0, [r3, 0x9] - cmp r4, r0 - bcs _080235B0 - adds r5, r3, 0 - adds r5, 0x64 -_0802356C: - lsls r0, r4, 5 - adds r1, r3, r0 - adds r0, r1, 0 - adds r0, 0xB5 - ldrb r2, [r0] - cmp r2, 0 - beq _080235A4 - adds r0, r6, 0x1 - lsls r0, 24 - lsrs r6, r0, 24 - adds r0, r1, 0 - adds r0, 0xB4 - ldrb r0, [r0] - adds r1, r0, 0x1 - movs r0, 0x2 - ands r0, r2 - cmp r0, 0 - beq _08023594 - movs r0, 0x4 - orrs r1, r0 -_08023594: - lsls r0, r4, 1 - adds r0, r4 - lsls r1, r0 - lsls r0, r1, 16 - lsrs r1, r0, 16 - ldrh r0, [r5] - orrs r1, r0 - strh r1, [r5] -_080235A4: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - ldrb r1, [r3, 0x9] - cmp r4, r1 - bcc _0802356C -_080235B0: - adds r0, r3, 0 - adds r0, 0x24 - ldrb r1, [r0] - adds r0, 0x3C - strh r1, [r0] - cmp r6, 0 - bne _080235D4 - ldr r2, =0x0000013b - adds r0, r3, r2 - ldrb r0, [r0] - cmp r0, 0 - beq _080236A0 - movs r4, 0x9C - lsls r4, 1 - adds r1, r3, r4 - b _08023612 - .pool -_080235D4: - ldr r5, =0x0000013b - adds r2, r3, r5 - ldrb r0, [r2] - cmp r0, 0 - beq _0802361A - ldr r0, =0x00000139 - adds r1, r3, r0 - ldrb r2, [r1] - cmp r6, r2 - beq _0802360C - subs r0, r6, 0x1 - strb r0, [r1] - ldr r1, =gUnknown_082F3290 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0] - movs r4, 0x9D - lsls r4, 1 - adds r1, r3, r4 - strb r0, [r1] - b _08023640 - .pool -_0802360C: - movs r5, 0x9C - lsls r5, 1 - adds r1, r3, r5 -_08023612: - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - b _08023640 -_0802361A: - movs r0, 0x9C - lsls r0, 1 - adds r1, r3, r0 - movs r0, 0 - strb r0, [r1] - subs r0, r6, 0x1 - ldr r4, =0x00000139 - adds r1, r3, r4 - strb r0, [r1] - ldr r1, =gUnknown_082F3290 - lsls r0, 2 - adds r0, r1 - ldrb r0, [r0] - movs r5, 0x9D - lsls r5, 1 - adds r1, r3, r5 - strb r0, [r1] - movs r0, 0x1 - strb r0, [r2] -_08023640: - ldr r0, =0x0000013b - adds r4, r3, r0 - ldrb r0, [r4] - cmp r0, 0 - beq _080236A0 - movs r2, 0x9C - lsls r2, 1 - adds r1, r3, r2 - movs r5, 0x9D - lsls r5, 1 - adds r2, r3, r5 - ldrb r0, [r1] - ldrb r5, [r2] - cmp r0, r5 - bcc _0802367C - movs r0, 0 - strb r0, [r1] - ldr r5, =0x00000139 - adds r1, r3, r5 - strb r0, [r1] - strb r0, [r2] - strb r0, [r4] - movs r1, 0 - b _08023690 - .pool -_0802367C: - ldr r2, =gUnknown_082F3290 - ldrb r1, [r1] - ldr r4, =0x00000139 - adds r0, r3, r4 - ldrb r0, [r0] - lsls r0, 2 - adds r0, 0x1 - adds r1, r0 - adds r1, r2 - ldrb r1, [r1] -_08023690: - adds r0, r3, 0 - adds r0, 0x5F - strb r1, [r0] - b _080236A8 - .pool -_080236A0: - adds r1, r3, 0 - adds r1, 0x5F - movs r0, 0 - strb r0, [r1] -_080236A8: - ldrh r1, [r3, 0x26] - adds r0, r3, 0 - adds r0, 0x62 - strh r1, [r0] - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8023558 - - thumb_func_start sub_80236B8 -sub_80236B8: @ 80236B8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r5, r0, 0 - ldr r3, =gMain - ldrh r1, [r3, 0x2E] - movs r4, 0x1 - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _080236DA - adds r2, r5, 0 - adds r2, 0x5E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] -_080236DA: - ldrh r1, [r3, 0x2C] - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _080236FA - ldrb r0, [r5, 0x8] - lsls r0, 5 - adds r0, r5, r0 - adds r1, r0, 0 - adds r1, 0xB2 - ldrh r0, [r1] - ldrh r2, [r5, 0x28] - cmp r0, r2 - bcs _080236FA - adds r0, 0x1 - strh r0, [r1] -_080236FA: - ldrb r0, [r5, 0x8] - adds r7, r5, 0 - adds r7, 0x5E - cmp r0, 0 - beq _08023710 - ldrb r1, [r7] - movs r0, 0x4 - ands r0, r1 - cmp r0, 0 - bne _08023710 - b _0802384C -_08023710: - adds r4, r5, 0 - adds r4, 0x5C - movs r0, 0x2 - strh r0, [r4] - ldrh r0, [r5, 0x28] - movs r1, 0x1E - bl __umodsi3 - lsls r0, 16 - mov r8, r4 - adds r6, r5, 0 - adds r6, 0x25 - cmp r0, 0 - bne _08023768 - movs r0, 0x2E - ldrsh r2, [r5, r0] - ldr r1, =gUnknown_082F4444 - ldrb r0, [r5, 0x9] - subs r0, 0x2 - adds r0, r1 - ldrb r0, [r0] - cmp r2, r0 - ble _08023754 - ldrh r0, [r5, 0x30] - adds r0, 0x1 - strh r0, [r5, 0x30] - ldrb r0, [r6] - movs r1, 0x10 - orrs r0, r1 - b _0802375C - .pool -_08023754: - ldrb r1, [r6] - movs r0, 0x11 - negs r0, r0 - ands r0, r1 -_0802375C: - strb r0, [r6] - movs r0, 0 - strh r0, [r5, 0x2E] - ldrh r0, [r5, 0x32] - adds r0, 0x1 - strh r0, [r5, 0x32] -_08023768: - ldrh r0, [r5, 0x28] - movs r1, 0xF - bl __umodsi3 - lsls r0, 16 - cmp r0, 0 - bne _080237DE - movs r0, 0x34 - ldrsh r2, [r5, r0] - ldr r3, =gUnknown_082F4434 - ldrb r0, [r5, 0x9] - subs r0, 0x2 - lsls r1, r0, 2 - adds r0, r1, r3 - ldrb r0, [r0] - cmp r2, r0 - bge _08023798 - ldrb r1, [r6] - movs r0, 0x1F - ands r0, r1 - strb r0, [r6] - b _080237D8 - .pool -_08023798: - adds r0, r3, 0x1 - adds r0, r1, r0 - ldrb r0, [r0] - cmp r2, r0 - bge _080237AC - ldrb r0, [r6] - movs r1, 0x1F - ands r1, r0 - movs r0, 0x20 - b _080237D4 -_080237AC: - adds r0, r3, 0x2 - adds r0, r1, r0 - ldrb r0, [r0] - cmp r2, r0 - bge _080237BC - movs r0, 0x2 - strh r0, [r5, 0x34] - b _080237D8 -_080237BC: - adds r0, r3, 0x3 - adds r0, r1, r0 - ldrb r0, [r0] - cmp r2, r0 - bge _080237CC - movs r0, 0x3 - strh r0, [r5, 0x34] - b _080237D8 -_080237CC: - ldrb r0, [r6] - movs r1, 0x1F - ands r1, r0 - movs r0, 0x80 -_080237D4: - orrs r1, r0 - strb r1, [r6] -_080237D8: - movs r0, 0 - strh r0, [r5, 0x34] - b _0802380A -_080237DE: - ldrh r0, [r5, 0x10] - adds r0, 0x1 - strh r0, [r5, 0x10] - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x3C - bls _0802380A - cmp r0, 0x46 - bls _080237FA - bl sub_8011AC8 - movs r0, 0 - strh r0, [r5, 0x10] - b _0802380A -_080237FA: - ldrb r0, [r7] - movs r4, 0xF8 - ands r4, r0 - cmp r4, 0 - bne _0802380A - bl sub_8011AC8 - strh r4, [r5, 0x10] -_0802380A: - ldrh r1, [r5, 0x28] - ldr r0, =0x00008c9f - cmp r1, r0 - bls _0802381A - ldrb r0, [r7] - movs r1, 0x1 - orrs r0, r1 - strb r0, [r7] -_0802381A: - ldrb r1, [r6] - lsls r1, 27 - lsrs r1, 31 - lsls r1, 1 - ldrb r2, [r7] - movs r0, 0x3 - negs r0, r0 - ands r0, r2 - orrs r0, r1 - strb r0, [r7] - ldrb r0, [r6] - lsrs r0, 5 - adds r2, r5, 0 - adds r2, 0x66 - strh r0, [r2] - adds r4, r5, 0 - adds r4, 0x42 - adds r0, r4, 0 - mov r1, r8 - movs r2, 0xC - bl memcpy - adds r0, r4, 0 - bl sub_800FE50 -_0802384C: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80236B8 - - thumb_func_start sub_802385C -sub_802385C: @ 802385C - push {r4,r5,lr} - adds r5, r0, 0 - movs r4, 0 - ldr r3, =gRecvCmds - ldrb r0, [r5, 0x9] - cmp r4, r0 - bcs _08023880 - movs r1, 0 -_0802386C: - lsls r0, r4, 5 - adds r0, r5, r0 - adds r0, 0xB5 - strb r1, [r0] - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - ldrb r0, [r5, 0x9] - cmp r4, r0 - bcc _0802386C -_08023880: - adds r2, r3, 0 - ldrh r0, [r2] - movs r1, 0xFF - lsls r1, 8 - ands r1, r0 - movs r0, 0xBC - lsls r0, 6 - cmp r1, r0 - bne _08023898 - ldrh r0, [r2, 0x2] - cmp r0, 0x2 - beq _080238AC -_08023898: - adds r2, r5, 0 - adds r2, 0x25 - ldrb r1, [r2] - movs r0, 0x5 - negs r0, r0 - ands r0, r1 - strb r0, [r2] - b _080238EA - .pool -_080238AC: - adds r4, r5, 0 - adds r4, 0x4E - adds r0, r4, 0 - adds r1, r3, 0 - movs r2, 0xE - bl memcpy - ldrh r0, [r4, 0x6] - strh r0, [r5, 0x2A] - movs r0, 0x5 - ldrsb r0, [r4, r0] - strh r0, [r5, 0x2C] - ldrh r0, [r4, 0x8] - strh r0, [r5, 0x28] - movs r0, 0x9C - lsls r0, 1 - adds r1, r5, r0 - adds r0, r5, 0 - bl sub_80216E0 - ldrb r1, [r4, 0x4] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080238EA - adds r0, r5, 0 - adds r0, 0x25 - ldrb r1, [r0] - movs r2, 0x8 - orrs r1, r2 - strb r1, [r0] -_080238EA: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_802385C - - thumb_func_start sub_80238F0 -sub_80238F0: @ 80238F0 - push {r4,lr} - adds r4, r0, 0 - adds r0, 0x5C - movs r1, 0 - movs r2, 0xC - bl memset - adds r0, r4, 0 - adds r0, 0x4E - movs r1, 0 - movs r2, 0xE - bl memset - adds r0, r4, 0 - bl sub_802385C - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x12 - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1A - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1E - bl SetGpuReg - adds r0, r4, 0 - adds r0, 0x25 - ldrb r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08023978 - ldrh r1, [r4, 0x28] - ldr r0, =0x00008c9f - cmp r1, r0 - bls _08023964 - adds r0, 0x1 - strh r0, [r4, 0x28] - movs r0, 0x10 - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - b _0802396E - .pool -_08023964: - movs r0, 0xF - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC -_0802396E: - movs r1, 0 - movs r0, 0 - strh r0, [r4, 0x10] - strb r1, [r4, 0xC] - b _08023992 -_08023978: - ldrh r0, [r4, 0x26] - adds r0, 0x1 - strh r0, [r4, 0x26] - adds r0, r4, 0 - bl sub_802339C - adds r0, r4, 0 - bl sub_8023558 - adds r0, r4, 0 - bl sub_80236B8 - movs r0, 0 -_08023992: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80238F0 - - thumb_func_start sub_8023998 -sub_8023998: @ 8023998 - push {r4,lr} - adds r4, r0, 0 - adds r0, 0x5C - movs r1, 0 - movs r2, 0xC - bl memset - adds r0, r4, 0 - adds r0, 0x4E - movs r1, 0 - movs r2, 0xE - bl memset - adds r0, r4, 0 - bl sub_802385C - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x12 - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1A - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1E - bl SetGpuReg - adds r0, r4, 0 - adds r0, 0x25 - ldrb r1, [r0] - movs r0, 0x8 - ands r0, r1 - cmp r0, 0 - beq _08023A20 - ldrh r1, [r4, 0x28] - ldr r0, =0x00008c9f - cmp r1, r0 - bls _08023A0C - adds r0, 0x1 - strh r0, [r4, 0x28] - movs r0, 0x10 - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - b _08023A16 - .pool -_08023A0C: - movs r0, 0xF - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC -_08023A16: - movs r1, 0 - movs r0, 0 - strh r0, [r4, 0x10] - strb r1, [r4, 0xC] - b _08023A28 -_08023A20: - adds r0, r4, 0 - bl sub_80236B8 - movs r0, 0 -_08023A28: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8023998 - - thumb_func_start sub_8023A30 -sub_8023A30: @ 8023A30 - push {r4-r7,lr} - adds r4, r0, 0 - ldrb r0, [r4, 0xC] - cmp r0, 0x5 - bls _08023A3C - b _08023BB2 -_08023A3C: - lsls r0, 2 - ldr r1, =_08023A4C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08023A4C: - .4byte _08023A64 - .4byte _08023A8C - .4byte _08023ADC - .4byte _08023B5C - .4byte _08023B7A - .4byte _08023B94 -_08023A64: - movs r0, 0x8 - strh r0, [r4, 0x12] - movs r0, 0xD6 - bl PlaySE - movs r0, 0x1 - negs r0, r0 - ldr r2, =0x000003ff - movs r1, 0x8 - bl BlendPalettes - movs r0, 0x9C - lsls r0, 1 - adds r1, r4, r0 - movs r0, 0x2 - strb r0, [r1] - b _08023BB2 - .pool -_08023A8C: - movs r1, 0x9C - lsls r1, 1 - adds r5, r4, r1 - ldrb r0, [r5] - subs r0, 0x1 - strb r0, [r5] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0xFF - beq _08023AA2 - b _08023BB8 -_08023AA2: - movs r0, 0x1 - negs r0, r0 - ldr r2, =0x000003ff - movs r1, 0 - bl BlendPalettes - ldr r2, =0x00000139 - adds r1, r4, r2 - movs r0, 0x4 - strb r0, [r1] - movs r0, 0 - strb r0, [r5] - ldr r2, =gUnknown_082F326C - ldrb r1, [r1] - lsls r0, r1, 3 - subs r0, r1 - adds r0, r2 - ldrb r0, [r0] - movs r2, 0x9D - lsls r2, 1 - adds r1, r4, r2 - strb r0, [r1] - b _08023BB2 - .pool -_08023ADC: - ldr r7, =gUnknown_082F326C - movs r0, 0x9C - lsls r0, 1 - adds r6, r4, r0 - ldr r1, =0x00000139 - adds r5, r4, r1 - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - ldrb r2, [r6] - adds r0, r2 - adds r0, r7 - movs r1, 0 - ldrsb r1, [r0, r1] - strh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x12 - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1A - bl SetGpuReg - ldrh r1, [r4, 0x2C] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x1E - bl SetGpuReg - ldrb r0, [r6] - adds r0, 0x1 - strb r0, [r6] - movs r1, 0x9D - lsls r1, 1 - adds r2, r4, r1 - lsls r0, 24 - lsrs r0, 24 - ldrb r1, [r2] - cmp r0, r1 - bcc _08023BB8 - ldrb r0, [r5] - cmp r0, 0 - beq _08023BB2 - subs r0, 0x1 - strb r0, [r5] - ldrb r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - adds r0, r7 - ldrb r0, [r0] - strb r0, [r2] - movs r0, 0 - strb r0, [r6] - b _08023BB8 - .pool -_08023B5C: - movs r0, 0 - strh r0, [r4, 0x2C] - movs r0, 0x12 - movs r1, 0 - bl SetGpuReg - movs r0, 0x1A - movs r1, 0 - bl SetGpuReg - movs r0, 0x1E - movs r1, 0 - bl SetGpuReg - b _08023BB2 -_08023B7A: - movs r2, 0x9C - lsls r2, 1 - adds r1, r4, r2 - adds r0, r4, 0 - bl sub_80218D4 - cmp r0, 0 - beq _08023BB8 - bl sub_8010434 - movs r0, 0 - strh r0, [r4, 0x10] - b _08023BB2 -_08023B94: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08023BB8 - movs r0, 0x11 - movs r1, 0x1 - movs r2, 0 - bl sub_8022BEC - movs r1, 0 - movs r0, 0 - strh r0, [r4, 0x10] - strb r1, [r4, 0xC] - b _08023BBA -_08023BB2: - ldrb r0, [r4, 0xC] - adds r0, 0x1 - strb r0, [r4, 0xC] -_08023BB8: - movs r0, 0 -_08023BBA: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_8023A30 - thumb_func_start sub_8023BC0 sub_8023BC0: @ 8023BC0 push {r4-r6,lr} diff --git a/src/berry_crush.c b/src/berry_crush.c index 8a88a2a92..fb1e5c7a0 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -18,6 +18,7 @@ #include "menu.h" #include "overworld.h" #include "palette.h" +#include "pokemon_jump.h" #include "rom_8034C54.h" #include "scanline_effect.h" #include "script.h" @@ -37,8 +38,12 @@ struct BerryCrushGame_Player { u16 unk0; - u8 filler2[2]; - u8 unk4[16]; + u16 unk2; + union + { + u8 as_bytes[16]; + u16 as_hwords[8]; + } unk4; u8 unk14[12]; }; @@ -54,6 +59,51 @@ typedef union BerryCrushGame_Players struct BerryCrushGame_PlayersSeparate separate; } BerryCrushGame_Players; +struct __attribute__((packed, aligned(2))) BerryCrushGame_4E +{ + u8 filler0[0x4]; + u8 unk4_0:1; + u8 unk4_1:1; + s8 unk5; + u16 unk6; + u16 unk8; + u16 unkA; + u16 unkC; +}; + +struct __attribute__((packed)) BerryCrushGame_40 +{ + u8 unk0[2]; + u16 unk2[6]; + struct BerryCrushGame_4E unkE; +}; + +struct __attribute__((packed, aligned(2))) BerryCrushGame_5C +{ + u16 unk00; + u8 unk02_0:1; + u8 unk02_1:1; + u8 unk02_2:1; + u8 unk02_3:5; + u8 unk03; + u16 unk04; + u16 unk06; + u16 unk08; + u16 unk0A; +}; + +struct BerryCrushGame_68 +{ + int unk00; + u16 unk04; + u8 filler06[2]; + u16 unk08; + u16 unk0A; + u16 unk0C[8]; // TODO: Resolve the type of the field. + BerryCrushGame_Players unk1C; + u8 fillerBC[20]; +}; + struct BerryCrushGame_138_C { u8 unk0; @@ -68,7 +118,10 @@ struct BerryCrushGame_138_C struct BerryCrushGame_138 { - u8 filler0[0x4]; + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; s16 unk4; s16 unk6; s16 unk8; @@ -84,33 +137,6 @@ struct BerryCrushGame_138 u8 unk83[5]; }; -struct BerryCrushGame_4E -{ - u8 filler0[0x4]; - u8 unk4; - u8 filler5[0x5]; - u16 unkA; - u16 unkC; -}; - -struct __attribute__((packed)) BerryCrushGame_40 -{ - u8 filler0[0xE]; - struct BerryCrushGame_4E unkE; -}; - -struct BerryCrushGame_68 -{ - int unk00; - u16 unk04; - u8 filler06[2]; - u16 unk08; - u16 unk0A; - u16 unk0C[8]; // TODO: Resolve the type of the field. - BerryCrushGame_Players unk1C; - u8 fillerBC[20]; -}; - struct BerryCrushGame { MainCallback unk0; @@ -123,24 +149,32 @@ struct BerryCrushGame u8 fillerD[0x1]; u8 unkE; u8 unkF; - u8 filler10[0x2]; + u16 unk10; u16 unk12; u8 filler14[0x2]; u16 unk16; - u8 filler18[0x4]; + s16 unk18; + s16 unk1A; int unk1C; - u8 filler20[0x5]; + s32 unk20; + u8 unk24; u8 unk25_0:1; u8 unk25_1:1; u8 unk25_2:1; - u8 filler26[0x2]; + u8 unk25_3:1; + u8 unk25_4:1; + u8 unk25_5:3; + u16 unk26; u16 unk28; - u16 unk2A; + s16 unk2A; s16 unk2C; - u8 filler2E[0x8]; + s16 unk2E; + u16 unk30; + u16 unk32; + s16 unk34; u8 unk36[0xA]; struct BerryCrushGame_40 unk40; - u8 filler60[0x8]; + struct BerryCrushGame_5C unk5C; struct BerryCrushGame_68 unk68; struct BerryCrushGame_138 unk138; u8 unk1C0[0x1000]; @@ -219,6 +253,13 @@ extern const struct SpriteTemplate gUnknown_082F4354; extern const struct UnkStruct3 gUnknown_082F4384[]; extern u32 (*const gUnknown_082F43CC[])(struct BerryCrushGame *, u8 *); extern const u8 *const gUnknown_082F32A4[]; +extern const u8 gUnknown_082F4448[]; +extern const s8 gUnknown_082F326C[][7]; +extern const u8 gUnknown_082F325C[]; +extern const u8 gUnknown_082F3264[]; +extern const u8 gUnknown_082F3290[][4]; +extern const u8 gUnknown_082F4434[][4]; +extern const u8 gUnknown_082F4444[]; struct BerryCrushGame *sub_8020C00(void) { @@ -686,7 +727,7 @@ void sub_8021608(struct Sprite *sprite) } } -void sub_80216A8(struct BerryCrushGame *arg0) +void sub_80216A8(struct BerryCrushGame *arg0, __attribute__((unused)) struct BerryCrushGame_138 *arg1) { u8 i; for (i = 0; i < arg0->unk9; i++) @@ -741,7 +782,7 @@ void sub_80216E0(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) arg1->unk4C[i]->pos1.y = gUnknown_082F41D2[i][1] + 136 - (var * 4); arg1->unk4C[i]->pos2.x = gUnknown_082F41D2[i][0] + (gUnknown_082F41D2[i][0] / (var2 * 4)); arg1->unk4C[i]->pos2.y = gUnknown_082F41D2[i][1]; - if (var4E->unk4 & 0x2) + if (var4E->unk4_1) StartSpriteAnim(arg1->unk4C[i], 1); else StartSpriteAnim(arg1->unk4C[i], 0); @@ -850,7 +891,7 @@ void sub_8021A28(struct BerryCrushGame *sp0C, u8 sp10, u8 sp14, u8 r3) ++i; break; case 0: - sp18 = sp20->unk1C.separate.player.unk4[i]; + sp18 = sp20->unk1C.separate.player.unk4.as_bytes[i]; if (i != 0 && sp20->unk0C[i] != sp20->unk0C[i - 1]) sp1C = i; ConvertIntToDecimalStringN( @@ -868,7 +909,7 @@ void sub_8021A28(struct BerryCrushGame *sp0C, u8 sp10, u8 sp14, u8 r3) ++i; break; case 1: - sp18 = sp20->unk1C.separate.player.unk4[i + 8]; + sp18 = sp20->unk1C.separate.player.unk4.as_bytes[i + 8]; if (i != 0 && sp20->unk0C[i + 5] != sp20->unk0C[i + 4]) // damn, access to unk0C is weird again sp1C = i; ConvertIntToDecimalStringN( @@ -1386,7 +1427,7 @@ bool32 sub_8022070(struct BerryCrushGame *r4, struct BerryCrushGame_138 *r6) r6->unk80 = 5; return FALSE; case 12: - sub_80219C8(r6->unk82, 20, 4, gUnknown_082F43B4[r4->unk68.unk1C.separate.player.unk4[7] + 3]); + sub_80219C8(r6->unk82, 20, 4, gUnknown_082F43B4[r4->unk68.unk1C.separate.player.unk4.as_bytes[7] + 3]); sub_8021A28(r4, 1, 0xA0, 8 * gUnknown_082F3344[0][r5]); r6->unk80 = 5; return FALSE; @@ -1420,7 +1461,7 @@ void sub_8022250(u8 r4) u8 r9 = 0, r2, r7, r10; u32 sp0C = 0; s16 *r6 = gTasks[r4].data; - const u8 *r10_; // r5/sl register swap + const u8 *r10_; // turn r5/sl register swap into r8/sl switch (r6[0]) { @@ -1433,9 +1474,9 @@ void sub_8022250(u8 r4) break; case 1: r10_ = gText_BerryCrush2; - ++r10_; --r10_; + ++r10_; --r10_; // swap r9/sl #ifndef NONMATCHING - asm("":::"r8"); + asm("":::"r8"); // turn r8/sl register swap into sb/sl #endif r7 = 96 - GetStringWidth(1, r10_, -1) / 2u; AddTextPrinterParameterized3( @@ -1990,3 +2031,566 @@ u32 sub_8022F04(struct BerryCrushGame *r0, __attribute__((unused)) u8 *r1) SetMainCallback2(sub_8020E1C); return 0; } + +u32 sub_8022F1C(struct BerryCrushGame *r5, u8 *r2) +{ + u8 r3; + + switch (r5->unkC) + { + case 0: + sub_8024644(r2, 1, 0, 0, 1); + r5->unkE = 9; + sub_8022BEC(3, 1, NULL); + return 0; + case 1: + sub_8010434(); + break; + case 2: + if (!IsLinkTaskFinished()) + return 0; + memset(r5->unk40.unk2, 0, sizeof(r5->unk40.unk2)); + r5->unk40.unk2[0] = r5->unk68.unk1C.separate.others[r5->unk8].unk0; + SendBlock(0, r5->unk40.unk2, 2); + break; + case 3: + if (!IsLinkTaskFinished()) + return 0; + r5->unk10 = 0; + break; + case 4: + if (GetBlockReceivedStatus() != gUnknown_082F4448[r5->unk9 - 2]) + return 0; + for (r3 = 0; r3 < r5->unk9; ++r3) + { + r5->unk68.unk1C.separate.others[r3].unk0 = gBlockRecvBuffer[r3][0]; + if (r5->unk68.unk1C.separate.others[r3].unk0 > 0xB0) + r5->unk68.unk1C.separate.others[r3].unk0 = 0; + r5->unk18 += gUnknown_0858AB24[r5->unk68.unk1C.separate.others[r3].unk0].unk0; + r5->unk1C += gUnknown_0858AB24[r5->unk68.unk1C.separate.others[r3].unk0].unk1; + } + r5->unk10 = 0; + ResetBlockReceivedFlags(); + r5->unk20 = sub_81515FC(r5->unk18 << 8, 0x2000); + break; + case 5: + ClearDialogWindowAndFrame(0, 1); + sub_8022BEC(10, 1, NULL); + r5->unk12 = 4; + r5->unkC = 0; + return 0; + } + ++r5->unkC; + return 0; +} + +u32 sub_8023070(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + switch (r4->unkC) + { + case 0: + sub_80214A8(r4, &r4->unk138); + sub_8010434(); + break; + case 1: + if (!IsLinkTaskFinished()) + return 0; + r4->unk138.unk0 = 0; + r4->unk138.unk1 = 0; + r4->unk138.unk2 = 0; + r4->unk138.unk3 = 0; + break; + case 2: + r4->unk138.unk38[r4->unk138.unk0]->callback = sub_8021608; + r4->unk138.unk38[r4->unk138.unk0]->affineAnimPaused = FALSE; + PlaySE(SE_NAGERU); + break; + case 3: + if (r4->unk138.unk38[r4->unk138.unk0]->callback == sub_8021608) + return 0; + r4->unk138.unk38[r4->unk138.unk0] = NULL; + ++r4->unk138.unk0; + sub_8010434(); + break; + case 4: + if (!IsLinkTaskFinished()) + return 0; + if (r4->unk138.unk0 < r4->unk9) + { + r4->unkC = 2; + return 0; + } + r4->unk138.unk0 = 0; + break; + case 5: + sub_80216A8(r4, &r4->unk138); + sub_8010434(); + break; + case 6: + if (!IsLinkTaskFinished()) + return 0; + PlaySE(SE_RU_HYUU); + sub_8022BEC(11, 1, NULL); + r4->unk12 = 5; + r4->unkC = 0; + return 0; + } + ++r4->unkC; + return 0; +} + +u32 sub_80231B8(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + switch (r4->unkC) + { + case 0: + r4->unk2A += 4; + if (r4->unk2A < 0) + return 0; + r4->unk2A = 0; + r4->unk138.unk1 = 4; + r4->unk138.unk0 = 0; + r4->unk138.unk2 = gUnknown_082F326C[r4->unk138.unk1][0]; + PlaySE(SE_W070); + break; + case 1: + r4->unk2C = gUnknown_082F326C[r4->unk138.unk1][r4->unk138.unk0]; + SetGpuReg(REG_OFFSET_BG0VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG2VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG3VOFS, -r4->unk2C); + ++r4->unk138.unk0; + if (r4->unk138.unk0 < r4->unk138.unk2) + return 0; + if (r4->unk138.unk1 == 0) + break; + --r4->unk138.unk1; + r4->unk138.unk2 = gUnknown_082F326C[r4->unk138.unk1][0]; + r4->unk138.unk0 = 0; + return 0; + case 2: + r4->unk2C = 0; + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + sub_8010434(); + break; + case 3: + if (!IsLinkTaskFinished()) + return 0; + sub_8022BEC(12, 1, NULL); + r4->unk12 = 6; + r4->unkC = 0; + return 0; + } + ++r4->unkC; + return 0; +} + +u32 sub_80232EC(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + switch (r4-> unkC) + { + case 1: + if (!IsLinkTaskFinished()) + return 0; + sub_802EB24(0x1000, 0x1000, 120, 80, 0); + break; + case 2: + if (sub_802EB84()) + return 0; + // fallthrough + case 0: + sub_8010434(); + break; + case 3: + if (!IsLinkTaskFinished()) + return 0; + r4->unk138.unk0 = 0; + r4->unk138.unk1 = 0; + r4->unk138.unk2 = 0; + r4->unk138.unk3 = 0; + r4->unk10 = 0; + if (r4->unk8 == 0) + sub_8022BEC(13, 1, NULL); + else + sub_8022BEC(14, 1, NULL); + r4->unk12 = 7; + r4->unkC = 0; + return 0; + } + ++r4->unkC; + return 0; +} + +void sub_802339C(struct BerryCrushGame *r4) +{ + u8 r8 = 0; + u16 r3; + u16 *r2; + u8 r7 = 0; + s32 r2_ = 0; + s32 r0; + + for (r7 = 0; r7 < r4->unk9; ++r7) + { + r2 = gRecvCmds[r7]; + if ((r2[0] & 0xFF00) == 0x2F00 + && r2[1] == 2) + { + if ((u8)r2[2] & 4) + { + r4->unk5C.unk02_3 |= gUnknown_082F325C[r7]; + r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[13] = 1; + ++r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[3]; + ++r8; + r3 = r4->unk28 - r4->unk68.unk1C.separate.others[r7].unk2; + if (r3 >= r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[1] - 1 + && r3 <= r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[1] + 1) + { + ++r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[0]; + r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[1] = r3; + if (r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[0] > r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[2]) + r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[2] = r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[0]; + } + else + { + r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[0] = 0; + r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[1] = r3; + } + r4->unk68.unk1C.separate.others[r7].unk2 = r4->unk28; + if (++r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[12] > 2) + r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[12] = 0; + } + else + { + r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[13] = 0; + } + } + } + if (r8 > 1) + { + for (r7 = 0; r7 < r4->unk9; ++r7) + { + if (r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[13] != 0) + { + r4->unk68.unk1C.separate.others[r7].unk4.as_bytes[13] |= 2; + ++r4->unk68.unk1C.separate.others[r7].unk4.as_hwords[4]; + } + } + } + if (r8 != 0) + { + r4->unk2E += r8; + r8 += gUnknown_082F3264[r8 - 1]; + r4->unk34 += r8; + r4->unk1A += r8; + r0 = r4->unk18; + r2_ = r4->unk1A; + if (r0 - r2_ > 0) + { + r2_ <<= 8; + r2_ = sub_81515FC(r2_, r4->unk20); + r2_ >>= 8; + r4->unk24 = r2_; + } + else + { + r4->unk24 = 32; + r4->unk5C.unk02_0 = 1; + } + } +} + +void sub_8023558(struct BerryCrushGame *r3) +{ + u8 r6 = 0; + u16 r1 = 0; + u8 r4 = 0; + + for (r4 = 0; r4 < r3->unk9; ++r4) + { + if (r3->unk68.unk1C.separate.others[r4].unk4.as_bytes[13] != 0) + { + ++r6; + r1 = r3->unk68.unk1C.separate.others[r4].unk4.as_bytes[12] + 1; + if (r3->unk68.unk1C.separate.others[r4].unk4.as_bytes[13] & 2) + r1 |= 4; + r1 <<= 3 * r4; + r3->unk5C.unk08 |= r1; + } + } + r3->unk5C.unk04 = r3->unk24; + if (r6 == 0) + { + if (r3->unk138.unk3 != 0) + ++r3->unk138.unk0; + else + goto SET_UNK5F_0; + } + else + { + if (r3->unk138.unk3 != 0) + { + if (r6 != r3->unk138.unk1) + { + r3->unk138.unk1 = r6 - 1; + r3->unk138.unk2 = gUnknown_082F3290[r6 - 1][0]; + } + else + { + ++r3->unk138.unk0; + } + } + else + { + r3->unk138.unk0 = 0; + r3->unk138.unk1 = r6 - 1; + r3->unk138.unk2 = gUnknown_082F3290[r6 - 1][0]; + r3->unk138.unk3 = 1; + } + } + if (r3->unk138.unk3 != 0) + { + if (r3->unk138.unk0 >= r3->unk138.unk2) + { + r3->unk138.unk0 = 0; + r3->unk138.unk1 = 0; + r3->unk138.unk2 = 0; + r3->unk138.unk3 = 0; + r1 = 0; + } + else + { + r1 = gUnknown_082F3290[r3->unk138.unk1][r3->unk138.unk0 + 1]; + } + r3->unk5C.unk03 = r1; + } + else + { + SET_UNK5F_0: + r3->unk5C.unk03 = 0; + } + r3->unk5C.unk06 = r3->unk26; +} + +void sub_80236B8(struct BerryCrushGame *r5) +{ + if (gMain.newKeys & A_BUTTON) + r5->unk5C.unk02_2 = 1; + if (gMain.heldKeys & A_BUTTON) + { + if (r5->unk68.unk1C.separate.others[r5->unk8].unk4.as_hwords[5] < r5->unk28) + ++r5->unk68.unk1C.separate.others[r5->unk8].unk4.as_hwords[5]; + } + if (r5->unk8 != 0 && r5->unk5C.unk02_2 == 0) + return; + r5->unk5C.unk00 = 2; + if (r5->unk28 % 30 == 0) + { + if (r5->unk2E > gUnknown_082F4444[r5->unk9 - 2]) + { + ++r5->unk30; + r5->unk25_4 = 1; + } + else + { + r5->unk25_4 = 0; + } + r5->unk2E = 0; + ++r5->unk32; + } + if (r5->unk28 % 15 == 0) + { + if (r5->unk34 < gUnknown_082F4434[r5->unk9 - 2][0]) + r5->unk25_5 = 0; + else if (r5->unk34 < gUnknown_082F4434[r5->unk9 - 2][1]) + r5->unk25_5 = 1; + else if (r5->unk34 < gUnknown_082F4434[r5->unk9 - 2][2]) + r5->unk34 = 2; // typo since r5->unk34 will be reset? + else if (r5->unk34 < gUnknown_082F4434[r5->unk9 - 2][3]) + r5->unk34 = 3; // typo since r5->unk34 will be reset? + else + r5->unk25_5 = 4; + r5->unk34 = 0; + } + else + { + ++r5->unk10; + if (r5->unk10 > 60) + { + if (r5->unk10 > 70) + { + sub_8011AC8(); + r5->unk10 = 0; + } + else if (r5->unk5C.unk02_3 == 0) + { + sub_8011AC8(); + r5->unk10 = 0; + } + } + + } + if (r5->unk28 >= 36000) + r5->unk5C.unk02_0 = 1; + r5->unk5C.unk02_1 = r5->unk25_4; + r5->unk5C.unk0A = r5->unk25_5; + memcpy(r5->unk40.unk2, &r5->unk5C, sizeof(r5->unk40.unk2)); + sub_800FE50(r5->unk40.unk2); +} + +void sub_802385C(struct BerryCrushGame *r5) +{ + struct BerryCrushGame_4E *r4_; +#ifndef NONMATCHING + register u32 r4 asm("r4"); + register u32 r0 asm("r0"); + + for (r4 = 0; r4 < r5->unk9; r4 = (u8)r0) + { + r5->unk68.unk1C.separate.others[r4].unk4.as_bytes[13] = 0; + r0 = r4 + 1; + } +#else + u8 r4; + + for (r4 = 0; r4 < r5->unk9; ++r4) + r5->unk68.unk1C.separate.others[r4].unk4.as_bytes[13] = 0; +#endif + if ((gRecvCmds[0][0] & 0xFF00) != 0x2F00 + || gRecvCmds[0][1] != 2) + { + r5->unk25_2 = 0; + } + else + { + r4_ = &r5->unk40.unkE; + memcpy(r4_, gRecvCmds, sizeof(struct BerryCrushGame_4E)); + r5->unk2A = r4_->unk6; + r5->unk2C = r4_->unk5; + r5->unk28 = r4_->unk8; + sub_80216E0(r5, &r5->unk138); + if (r4_->unk4_0) + r5->unk25_3 = 1; + } +} + +u32 sub_80238F0(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + memset(&r4->unk5C, 0, sizeof(r4->unk5C)); + memset(&r4->unk40.unkE, 0, sizeof(r4->unk40.unkE)); + sub_802385C(r4); + SetGpuReg(REG_OFFSET_BG0VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG2VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG3VOFS, -r4->unk2C); + if (r4->unk25_3) + { + if (r4->unk28 >= 36000) + { + r4->unk28 = 36000; + sub_8022BEC(16, 1, NULL); + } + else + { + sub_8022BEC(15, 1, NULL); + } + r4->unk10 = 0; + r4->unkC = 0; + return 0; + } + else + { + ++r4->unk26; + sub_802339C(r4); + sub_8023558(r4); + sub_80236B8(r4); + return 0; + } +} + +u32 sub_8023998(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + memset(&r4->unk5C, 0, sizeof(r4->unk5C)); + memset(&r4->unk40.unkE, 0, sizeof(r4->unk40.unkE)); + sub_802385C(r4); + SetGpuReg(REG_OFFSET_BG0VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG2VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG3VOFS, -r4->unk2C); + if (r4->unk25_3) + { + if (r4->unk28 >= 36000) + { + r4->unk28 = 36000; + sub_8022BEC(16, 1, NULL); + } + else + { + sub_8022BEC(15, 1, NULL); + } + r4->unk10 = 0; + r4->unkC = 0; + return 0; + } + else + { + sub_80236B8(r4); + return 0; + } +} + +u32 sub_8023A30(struct BerryCrushGame *r4, __attribute__((unused)) u8 *r1) +{ + switch (r4->unkC) + { + case 0: + r4->unk12 = 8; + PlaySE(SE_W070); + BlendPalettes(0xFFFFFFFF, 8, RGB(31, 31, 0)); + r4->unk138.unk0 = 2; + break; + case 1: + if (--r4->unk138.unk0 != 255) + return 0; + BlendPalettes(0xFFFFFFFF, 0, RGB(31, 31, 0)); + r4->unk138.unk1 = 4; + r4->unk138.unk0 = 0; + r4->unk138.unk2 = gUnknown_082F326C[r4->unk138.unk1][0]; + break; + case 2: + r4->unk2C = gUnknown_082F326C[r4->unk138.unk1][r4->unk138.unk0]; + SetGpuReg(REG_OFFSET_BG0VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG2VOFS, -r4->unk2C); + SetGpuReg(REG_OFFSET_BG3VOFS, -r4->unk2C); + if (++r4->unk138.unk0 < r4->unk138.unk2) + return 0; + if (r4->unk138.unk1 != 0) + { + --r4->unk138.unk1; + r4->unk138.unk2 = gUnknown_082F326C[r4->unk138.unk1][0]; + r4->unk138.unk0 = 0; + return 0; + } + break; + case 3: + r4->unk2C = 0; + SetGpuReg(REG_OFFSET_BG0VOFS, 0); + SetGpuReg(REG_OFFSET_BG2VOFS, 0); + SetGpuReg(REG_OFFSET_BG3VOFS, 0); + break; + case 4: + if (!sub_80218D4(r4, &r4->unk138)) + return 0; + sub_8010434(); + r4->unk10 = 0; + break; + case 5: + if (!IsLinkTaskFinished()) + return 0; + sub_8022BEC(17, 1, NULL); + r4->unk10 = 0; + r4->unkC = 0; + return 0; + } + ++r4->unkC; + return 0; +}