diff --git a/asm/berry_crush.s b/asm/berry_crush.s index 9286a9b4f..00bff2b56 100755 --- a/asm/berry_crush.s +++ b/asm/berry_crush.s @@ -5,1291 +5,6 @@ .text - thumb_func_start sub_8020C00 -sub_8020C00: @ 8020C00 - ldr r0, =gUnknown_02022C90 - ldr r0, [r0] - bx lr - .pool - thumb_func_end sub_8020C00 - - thumb_func_start sub_8020C0C -sub_8020C0C: @ 8020C0C - push {r4,r5,lr} - adds r4, r0, 0 - ldr r5, =gUnknown_02022C90 - ldr r0, [r5] - cmp r0, 0 - bne _08020C20 - movs r0, 0x2 - b _08020C5C - .pool -_08020C20: - cmp r4, 0 - bne _08020C26 - ldr r4, [r0] -_08020C26: - ldrb r0, [r0, 0xA] - bl DestroyTask - ldr r0, [r5] - bl Free - movs r0, 0 - str r0, [r5] - adds r0, r4, 0 - bl SetMainCallback2 - ldr r0, =CB2_ReturnToField - cmp r4, r0 - bne _08020C5A - ldr r2, =gTextFlags - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] - movs r0, 0xC8 - lsls r0, 1 - bl PlayNewMapMusic - ldr r0, =CB1_Overworld - bl SetMainCallback1 -_08020C5A: - movs r0, 0 -_08020C5C: - pop {r4,r5} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8020C0C - - thumb_func_start sub_8020C70 -sub_8020C70: @ 8020C70 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0xC - adds r4, r0, 0 - movs r0, 0 - mov r8, r0 - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - beq _08020C8E - ldr r0, =gWirelessCommType - ldrb r0, [r0] - cmp r0, 0 - bne _08020CAC -_08020C8E: - adds r0, r4, 0 - bl SetMainCallback2 - ldr r0, =gUnknown_03005000 - mov r1, r8 - strh r1, [r0, 0x10] - strh r1, [r0, 0x12] - b _08020CF8 - .pool -_08020CAC: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - bl GetMultiplayerId - lsls r0, 24 - lsrs r7, r0, 24 - mov r0, r8 - cmp r0, 0x1 - bls _08020CC8 - cmp r7, r8 - bcc _08020CDC -_08020CC8: - adds r0, r4, 0 - bl SetMainCallback2 - ldr r0, =gUnknown_03005000 - movs r1, 0 - strh r1, [r0, 0x10] - strh r1, [r0, 0x12] - b _08020CF8 - .pool -_08020CDC: - ldr r6, =gUnknown_02022C90 - ldr r0, =0x000041c0 - bl AllocZeroed - adds r5, r0, 0 - str r5, [r6] - cmp r5, 0 - bne _08020D10 - adds r0, r4, 0 - bl SetMainCallback2 - ldr r0, =gUnknown_03005000 - strh r5, [r0, 0x10] - strh r5, [r0, 0x12] -_08020CF8: - adds r0, 0xEE - ldrb r1, [r0] - movs r1, 0x1 - strb r1, [r0] - b _08020D74 - .pool -_08020D10: - str r4, [r5] - movs r4, 0 - strb r7, [r5, 0x8] - ldr r0, [r6] - mov r1, r8 - strb r1, [r0, 0x9] - ldr r0, [r6] - bl sub_8020FC4 - ldr r1, [r6] - movs r2, 0x1 - movs r0, 0x1 - strh r0, [r1, 0x12] - strb r2, [r1, 0xE] - ldr r1, [r6] - movs r0, 0x6 - strb r0, [r1, 0xF] - ldr r0, [r6] - adds r0, 0x36 - movs r2, 0x1 - negs r2, r2 - movs r1, 0x10 - str r1, [sp] - str r4, [sp, 0x4] - str r4, [sp, 0x8] - movs r1, 0x1 - movs r3, 0 - bl sub_8024604 - ldr r2, [r6] - adds r2, 0x36 - movs r0, 0x4 - movs r1, 0x1 - bl sub_8022BEC - ldr r0, =sub_8020F88 - bl SetMainCallback2 - ldr r0, =sub_8020FA0 - movs r1, 0x8 - bl CreateTask - ldr r1, [r6] - strb r0, [r1, 0xA] - ldr r2, =gTextFlags - ldrb r1, [r2] - movs r0, 0x5 - negs r0, r0 - ands r0, r1 - strb r0, [r2] -_08020D74: - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020C70 - - thumb_func_start sub_8020D8C -sub_8020D8C: @ 8020D8C - push {r4,lr} - sub sp, 0xC - ldr r1, =gSpecialVar_ItemId - ldrh r0, [r1] - subs r0, 0x85 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x2B - bls _08020DA8 - movs r0, 0x85 - strh r0, [r1] - b _08020DB0 - .pool -_08020DA8: - ldrh r0, [r1] - movs r1, 0x1 - bl RemoveBagItem -_08020DB0: - ldr r4, =gUnknown_02022C90 - ldr r2, [r4] - ldrb r0, [r2, 0x8] - lsls r0, 5 - adds r0, r2, r0 - ldr r1, =gSpecialVar_ItemId - ldrh r1, [r1] - subs r1, 0x85 - adds r0, 0xA4 - movs r3, 0 - strh r1, [r0] - movs r0, 0x1 - strb r0, [r2, 0xE] - ldr r1, [r4] - movs r0, 0x9 - strb r0, [r1, 0xF] - ldr r0, [r4] - adds r0, 0x36 - movs r2, 0x1 - negs r2, r2 - movs r1, 0x10 - str r1, [sp] - str r3, [sp, 0x4] - str r3, [sp, 0x8] - movs r1, 0 - bl sub_8024604 - ldr r2, [r4] - adds r2, 0x36 - movs r0, 0x4 - movs r1, 0x1 - bl sub_8022BEC - ldr r0, =sub_8020FA0 - movs r1, 0x8 - bl CreateTask - ldr r1, [r4] - strb r0, [r1, 0xA] - ldr r0, =sub_8020F88 - bl SetMainCallback2 - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020D8C - - thumb_func_start sub_8020E1C -sub_8020E1C: @ 8020E1C - push {lr} - ldr r0, =gUnknown_02022C90 - ldr r0, [r0] - ldrb r0, [r0, 0xA] - bl DestroyTask - ldr r0, =sub_8020D8C - bl sub_81AABF0 - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020E1C - - thumb_func_start sub_8020E3C -sub_8020E3C: @ 8020E3C - push {lr} - ldr r0, =sub_8020F74 - bl SetVBlankCallback - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020E3C - - thumb_func_start sub_8020E4C -sub_8020E4C: @ 8020E4C - push {lr} - movs r0, 0 - bl SetVBlankCallback - pop {r0} - bx r0 - thumb_func_end sub_8020E4C - - thumb_func_start sub_8020E58 -sub_8020E58: @ 8020E58 - push {r4-r6,lr} - ldr r4, =gUnknown_02022C90 - ldr r0, [r4] - adds r0, 0x6C - ldrh r2, [r0] - lsls r2, 8 - movs r1, 0xF0 - lsls r1, 6 - adds r0, r2, 0 - bl sub_81515FC - adds r2, r0, 0 - ldr r0, [r4] - adds r0, 0x72 - ldrh r3, [r0] - lsls r3, 8 - adds r0, r3, 0 - adds r1, r2, 0 - bl sub_81515FC - adds r3, r0, 0 - ldr r0, =0x0000ffff - ands r3, r0 - ldr r2, [r4] - strh r3, [r2, 0x16] - ldrb r0, [r2, 0x9] - cmp r0, 0x3 - beq _08020EDC - cmp r0, 0x3 - bgt _08020EA4 - cmp r0, 0x2 - beq _08020EAE - b _08020F48 - .pool -_08020EA4: - cmp r0, 0x4 - beq _08020EEC - cmp r0, 0x5 - beq _08020F20 - b _08020F48 -_08020EAE: - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - movs r0, 0xF6 - lsls r0, 1 - adds r1, r0 - lsls r0, r3, 16 - lsrs r0, 16 - ldrh r1, [r1] - cmp r0, r1 - bls _08020F48 - adds r2, 0x25 - ldrb r0, [r2] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r2] - ldr r0, [r5] - ldr r1, [r4] - ldrh r1, [r1, 0x16] - movs r2, 0xF6 - lsls r2, 1 - b _08020F14 - .pool -_08020EDC: - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - movs r6, 0xF7 - lsls r6, 1 - b _08020F28 - .pool -_08020EEC: - ldr r5, =gSaveBlock2Ptr - ldr r1, [r5] - movs r0, 0xF8 - lsls r0, 1 - adds r1, r0 - lsls r0, r3, 16 - lsrs r0, 16 - ldrh r1, [r1] - cmp r0, r1 - bls _08020F48 - adds r2, 0x25 - ldrb r0, [r2] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r2] - ldr r0, [r5] - ldr r1, [r4] - ldrh r1, [r1, 0x16] - movs r2, 0xF8 - lsls r2, 1 -_08020F14: - adds r0, r2 - strh r1, [r0] - b _08020F48 - .pool -_08020F20: - ldr r5, =gSaveBlock2Ptr - ldr r0, [r5] - movs r6, 0xF9 - lsls r6, 1 -_08020F28: - adds r1, r0, r6 - lsls r0, r3, 16 - lsrs r0, 16 - ldrh r1, [r1] - cmp r0, r1 - bls _08020F48 - adds r2, 0x25 - ldrb r0, [r2] - movs r1, 0x2 - orrs r0, r1 - strb r0, [r2] - ldr r1, [r5] - ldr r0, [r4] - ldrh r0, [r0, 0x16] - adds r1, r6 - strh r0, [r1] -_08020F48: - ldr r4, =gUnknown_02022C90 - ldr r1, [r4] - ldr r0, [r1, 0x68] - str r0, [r1, 0x1C] - bl GiveBerryPowder - lsls r0, 24 - cmp r0, 0 - bne _08020F66 - ldr r0, [r4] - adds r0, 0x25 - ldrb r1, [r0] - movs r2, 0x1 - orrs r1, r2 - strb r1, [r0] -_08020F66: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020E58 - - thumb_func_start sub_8020F74 -sub_8020F74: @ 8020F74 - push {lr} - bl TransferPlttBuffer - bl LoadOam - bl ProcessSpriteCopyRequests - pop {r0} - bx r0 - thumb_func_end sub_8020F74 - - thumb_func_start sub_8020F88 -sub_8020F88: @ 8020F88 - push {lr} - bl RunTasks - bl RunTextPrinters - bl AnimateSprites - bl BuildOamBuffer - pop {r0} - bx r0 - thumb_func_end sub_8020F88 - - thumb_func_start sub_8020FA0 -sub_8020FA0: @ 8020FA0 - push {r4,lr} - ldr r4, =gUnknown_02022C90 - ldr r0, [r4] - ldr r2, [r0, 0x4] - cmp r2, 0 - beq _08020FB4 - adds r1, r0, 0 - adds r1, 0x36 - bl _call_via_r2 -_08020FB4: - ldr r0, [r4] - bl sub_8021450 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8020FA0 - - thumb_func_start sub_8020FC4 -sub_8020FC4: @ 8020FC4 - push {r4-r6,lr} - adds r6, r0, 0 - movs r5, 0 - b _08020FE6 -_08020FCC: - lsls r0, r5, 5 - adds r0, 0x98 - adds r0, r6, r0 - lsls r1, r5, 3 - subs r1, r5 - lsls r1, 2 - ldr r2, =gLinkPlayers + 8 - adds r1, r2 - bl StringCopy - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 -_08020FE6: - ldrb r0, [r6, 0x9] - cmp r5, r0 - bcc _08020FCC - cmp r5, 0x4 - bhi _08021012 -_08020FF0: - lsls r4, r5, 5 - adds r0, r4, 0 - adds r0, 0x98 - adds r0, r6, r0 - movs r1, 0x1 - movs r2, 0x7 - bl memset - adds r4, r6, r4 - adds r4, 0x9F - movs r0, 0xFF - strb r0, [r4] - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x4 - bls _08020FF0 -_08021012: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r0, [r0, 0x14] - lsls r0, 29 - lsrs r0, 29 - cmp r0, 0x1 - beq _0802103E - cmp r0, 0x1 - bgt _08021034 - cmp r0, 0 - beq _0802103A - b _08021046 - .pool -_08021034: - cmp r0, 0x2 - beq _08021042 - b _08021046 -_0802103A: - movs r0, 0x8 - b _08021044 -_0802103E: - movs r0, 0x4 - b _08021044 -_08021042: - movs r0, 0x1 -_08021044: - strb r0, [r6, 0xB] -_08021046: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8020FC4 - - thumb_func_start sub_802104C -sub_802104C: @ 802104C - push {r4,r5,lr} - sub sp, 0xC - bl sub_8020C00 - adds r5, r0, 0 - cmp r5, 0 - bne _08021060 - movs r0, 0x1 - negs r0, r0 - b _08021304 -_08021060: - ldrb r0, [r5, 0xC] - cmp r0, 0x9 - bls _08021068 - b _080212FC -_08021068: - lsls r0, 2 - ldr r1, =_08021078 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08021078: - .4byte _080210A0 - .4byte _080210BE - .4byte _080210E4 - .4byte _080210F2 - .4byte _08021178 - .4byte _080211BE - .4byte _080211EC - .4byte _0802121C - .4byte _08021278 - .4byte _080212B4 -_080210A0: - movs r0, 0 - bl SetVBlankCallback - movs r0, 0 - bl SetHBlankCallback - movs r0, 0 - movs r1, 0 - bl SetGpuReg - bl ScanlineEffect_Stop - bl reset_temp_tile_data_buffers - b _080212FC -_080210BE: - add r0, sp, 0x8 - movs r4, 0 - strh r4, [r0] - movs r1, 0xE0 - lsls r1, 19 - ldr r2, =0x01000200 - bl CpuSet - ldr r0, =gReservedSpritePaletteCount - strb r4, [r0] - movs r0, 0x3 - bl sub_8034C54 - b _080212FC - .pool -_080210E4: - bl ResetPaletteFade - bl ResetSpriteData - bl FreeAllSpritePalettes - b _080212FC -_080210F2: - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_082F32C8 - movs r0, 0 - movs r2, 0x4 - bl InitBgsFromTemplates - movs r0, 0xE0 - lsls r0, 1 - adds r1, r5, r0 - movs r0, 0x1 - bl SetBgTilemapBuffer - movs r0, 0x87 - lsls r0, 6 - adds r1, r5, r0 - movs r0, 0x2 - bl SetBgTilemapBuffer - movs r0, 0xC7 - lsls r0, 6 - adds r1, r5, r0 - movs r0, 0x3 - bl SetBgTilemapBuffer - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - movs r0, 0x50 - movs r1, 0 - bl SetGpuReg - movs r0, 0x52 - movs r1, 0 - bl SetGpuReg - b _080212FC - .pool -_08021178: - movs r4, 0x20 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - movs r0, 0x40 - str r0, [sp, 0x4] - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - b _080212FC -_080211BE: - movs r0, 0 - bl CopyBgTilemapBufferToVram - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - movs r0, 0x3 - bl CopyBgTilemapBufferToVram - ldr r1, =gUnknown_08DE34B8 - movs r0, 0 - str r0, [sp] - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl decompress_and_copy_tile_data_to_vram - b _080212FC - .pool -_080211EC: - bl free_temp_tile_data_buffers_if_possible - lsls r0, 24 - cmp r0, 0 - beq _080211F8 - b _08021302 -_080211F8: - bl InitStandardTextBoxWindows - bl sub_8197200 - adds r0, r5, 0 - bl sub_8022588 - adds r0, r5, 0 - bl sub_8022600 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x8] - movs r2, 0x80 - orrs r1, r2 - strb r1, [r0, 0x8] - b _080212FC - .pool -_0802121C: - ldr r0, =gUnknown_08DE3398 - movs r2, 0xC0 - lsls r2, 1 - movs r1, 0 - bl LoadPalette - ldr r1, =gBerryCrushGrinderTopTilemap - movs r0, 0x1 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - ldr r1, =gBerryCrushContainerCapTilemap - movs r0, 0x2 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - ldr r1, =gBerryCrushBackgroundTilemap - movs r0, 0x3 - movs r2, 0 - movs r3, 0 - bl CopyToBgTilemapBuffer - adds r0, r5, 0 - bl sub_80226D0 - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - movs r0, 0x3 - bl CopyBgTilemapBufferToVram - b _080212FC - .pool -_08021278: - bl sub_800E0E8 - movs r0, 0 - movs r1, 0 - bl CreateWirelessStatusIndicatorSprite - adds r0, r5, 0 - bl sub_8022730 - ldr r0, =gSpriteCoordOffsetY - ldrh r1, [r0] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x16 - bl SetGpuReg - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgX - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - bl ChangeBgY - b _080212FC - .pool -_080212B4: - ldr r2, =gPaletteFade - ldrb r1, [r2, 0x8] - movs r0, 0x7F - ands r0, r1 - strb r0, [r2, 0x8] - movs r0, 0x1 - negs r0, r0 - movs r1, 0x10 - movs r2, 0 - bl BlendPalettes - movs r0, 0 - bl ShowBg - movs r0, 0x1 - bl ShowBg - movs r0, 0x2 - bl ShowBg - movs r0, 0x3 - bl ShowBg - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl SetGpuRegBits - bl sub_8020E3C - movs r0, 0 - strb r0, [r5, 0xC] - movs r0, 0x1 - b _08021304 - .pool -_080212FC: - ldrb r0, [r5, 0xC] - adds r0, 0x1 - strb r0, [r5, 0xC] -_08021302: - movs r0, 0 -_08021304: - add sp, 0xC - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_802104C - - thumb_func_start sub_802130C -sub_802130C: @ 802130C - push {r4,r5,lr} - sub sp, 0x8 - bl sub_8020C00 - adds r5, r0, 0 - cmp r5, 0 - bne _08021320 - movs r0, 0x1 - negs r0, r0 - b _08021446 -_08021320: - ldrb r0, [r5, 0xC] - cmp r0, 0x7 - bls _08021328 - b _0802143E -_08021328: - lsls r0, 2 - ldr r1, =_08021338 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08021338: - .4byte _08021358 - .4byte _0802135E - .4byte _08021368 - .4byte _0802137E - .4byte _0802138A - .4byte _080213E6 - .4byte _08021426 - .4byte _08021436 -_08021358: - bl sub_8010434 - b _0802143E -_0802135E: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _08021444 -_08021368: - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - bl UpdatePaletteFade - b _0802143E -_0802137E: - bl UpdatePaletteFade - lsls r0, 24 - cmp r0, 0 - beq _0802143E - b _08021444 -_0802138A: - movs r4, 0x20 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0x1 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0x2 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - str r4, [sp] - str r4, [sp, 0x4] - movs r0, 0x3 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect_Palette0 - movs r0, 0 - bl CopyBgTilemapBufferToVram - movs r0, 0x1 - bl CopyBgTilemapBufferToVram - movs r0, 0x2 - bl CopyBgTilemapBufferToVram - movs r0, 0x3 - bl CopyBgTilemapBufferToVram - b _0802143E -_080213E6: - bl FreeAllWindowBuffers - movs r0, 0 - bl HideBg - movs r0, 0 - bl UnsetBgTilemapBuffer - movs r0, 0x1 - bl HideBg - movs r0, 0x1 - bl UnsetBgTilemapBuffer - movs r0, 0x2 - bl HideBg - movs r0, 0x2 - bl UnsetBgTilemapBuffer - movs r0, 0x3 - bl HideBg - movs r0, 0x3 - bl UnsetBgTilemapBuffer - movs r1, 0x82 - lsls r1, 5 - movs r0, 0 - bl ClearGpuRegBits - b _0802143E -_08021426: - bl sub_800E084 - adds r0, r5, 0 - bl sub_8022960 - bl sub_8034CC8 - b _0802143E -_08021436: - movs r0, 0 - strb r0, [r5, 0xC] - movs r0, 0x1 - b _08021446 -_0802143E: - ldrb r0, [r5, 0xC] - adds r0, 0x1 - strb r0, [r5, 0xC] -_08021444: - movs r0, 0 -_08021446: - add sp, 0x8 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_802130C - - thumb_func_start sub_8021450 -sub_8021450: @ 8021450 - push {r4,lr} - adds r4, r0, 0 - ldr r0, =gSpriteCoordOffsetY - ldrh r1, [r4, 0x2C] - ldrh r2, [r4, 0x2A] - adds r1, r2 - strh r1, [r0] - negs r1, r1 - lsls r1, 16 - lsrs r1, 16 - movs r0, 0x16 - bl SetGpuReg - ldrh r0, [r4, 0x12] - cmp r0, 0x7 - bne _0802147C - movs r1, 0x9C - lsls r1, 1 - adds r0, r4, r1 - ldrh r1, [r4, 0x28] - bl sub_8022524 -_0802147C: - movs r0, 0 - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8021450 - - thumb_func_start sub_8021488 -sub_8021488: @ 8021488 - movs r1, 0 - ldr r2, =0x0000ff98 - strh r2, [r0, 0x2A] - strh r1, [r0, 0x2C] - ldr r0, =gSpriteCoordOffsetX - strh r1, [r0] - ldr r0, =gSpriteCoordOffsetY - strh r2, [r0] - bx lr - .pool - thumb_func_end sub_8021488 - - thumb_func_start sub_80214A8 -sub_80214A8: @ 80214A8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - mov r10, r0 - str r1, [sp] - movs r0, 0 - mov r9, r0 - mov r1, r10 - ldrb r1, [r1, 0x9] - cmp r9, r1 - bcc _080214C6 - b _080215E4 -_080214C6: - ldr r1, =gUnknown_082F41E8 - mov r2, r9 - lsls r0, r2, 1 - adds r0, r1 - ldrh r2, [r0] - mov r1, r9 - lsls r0, r1, 5 - add r0, r10 - adds r0, 0xA4 - ldrh r3, [r0] - adds r3, 0x85 - lsls r3, 16 - lsrs r3, 16 - ldr r0, =gUnknown_082F436C - adds r1, r2, 0 - bl AddCustomItemIconSprite - lsls r0, 24 - lsrs r0, 24 - mov r2, r9 - lsls r3, r2, 2 - ldr r1, [sp] - adds r1, 0x38 - adds r6, r1, r3 - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - ldr r0, =gSprites - adds r1, r0 - str r1, [r6] - ldrb r0, [r1, 0x5] - movs r2, 0xC - orrs r0, r2 - strb r0, [r1, 0x5] - ldr r2, [r6] - adds r2, 0x2C - ldrb r0, [r2] - movs r1, 0x80 - orrs r0, r1 - strb r0, [r2] - ldr r1, [r6] - ldr r0, [sp] - adds r0, 0xC - adds r0, r3 - mov r8, r0 - ldr r0, [r0] - ldrh r0, [r0, 0x8] - adds r0, 0x78 - strh r0, [r1, 0x20] - ldr r1, [r6] - ldr r0, =0x0000fff0 - strh r0, [r1, 0x22] - ldr r3, [r6] - adds r5, r3, 0 - adds r5, 0x2E - movs r0, 0x80 - lsls r0, 2 - strh r0, [r5, 0x2] - movs r0, 0x20 - strh r0, [r5, 0x4] - movs r0, 0x70 - strh r0, [r5, 0xE] - mov r2, r8 - ldr r1, [r2] - ldrh r0, [r1, 0xA] - ldrh r1, [r1, 0x8] - subs r0, r1 - lsls r0, 16 - asrs r1, r0, 16 - adds r0, r1, 0 - cmp r1, 0 - bge _08021558 - adds r0, r1, 0x3 -_08021558: - asrs r0, 2 - strh r0, [r5, 0xC] - lsls r0, r1, 23 - lsrs r7, r0, 16 - movs r2, 0x80 - lsls r2, 2 - adds r2, 0x20 - lsrs r2, 1 - movs r0, 0x7 - movs r1, 0xFE - lsls r1, 6 - str r3, [sp, 0x4] - bl sub_81515D4 - adds r4, r0, 0 - ldr r0, [r6] - ldrh r0, [r0, 0x20] - lsls r0, 7 - ldr r3, [sp, 0x4] - strh r0, [r3, 0x2E] - lsls r1, r7, 16 - asrs r1, 16 - lsls r4, 16 - asrs r4, 16 - movs r0, 0x7 - adds r2, r4, 0 - bl sub_81515D4 - strh r0, [r5, 0x6] - movs r0, 0x7 - adds r1, r4, 0 - movs r2, 0x55 - bl sub_8151550 - adds r2, r0, 0 - movs r0, 0 - strh r0, [r5, 0x8] - lsls r2, 16 - asrs r2, 16 - movs r0, 0x7 - movs r1, 0xFE - lsls r1, 6 - bl sub_81515D4 - strh r0, [r5, 0xA] - ldrh r0, [r5, 0xE] - ldr r2, =0xffff8000 - adds r1, r2, 0 - orrs r0, r1 - strh r0, [r5, 0xE] - mov r1, r8 - ldr r0, [r1] - movs r2, 0x8 - ldrsh r0, [r0, r2] - cmp r0, 0 - bge _080215D0 - ldr r0, [r6] - movs r1, 0x1 - bl StartSpriteAffineAnim -_080215D0: - mov r0, r9 - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - mov r0, r10 - ldrb r0, [r0, 0x9] - cmp r9, r0 - bcs _080215E4 - b _080214C6 -_080215E4: - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80214A8 - - thumb_func_start sub_8021608 -sub_8021608: @ 8021608 - push {r4-r6,lr} - adds r5, r0, 0 - adds r4, r5, 0 - adds r4, 0x2E - ldrh r0, [r4, 0x4] - ldrh r1, [r4, 0x2] - adds r0, r1 - strh r0, [r4, 0x2] - lsls r0, 16 - asrs r0, 24 - ldrh r2, [r5, 0x26] - adds r0, r2 - strh r0, [r5, 0x26] - movs r1, 0xE - ldrsh r0, [r4, r1] - movs r6, 0x80 - lsls r6, 8 - ands r0, r6 - cmp r0, 0 - beq _0802166E - ldrh r0, [r4, 0x6] - ldrh r2, [r5, 0x2E] - adds r0, r2 - strh r0, [r5, 0x2E] - ldrh r0, [r4, 0xA] - ldrh r1, [r4, 0x8] - adds r0, r1 - strh r0, [r4, 0x8] - lsls r0, 16 - asrs r0, 23 - movs r2, 0xC - ldrsh r1, [r4, r2] - bl Sin - strh r0, [r5, 0x24] - movs r1, 0xE - ldrsh r0, [r4, r1] - ands r0, r6 - cmp r0, 0 - beq _0802166E - ldrh r0, [r4, 0x8] - lsls r0, 16 - asrs r0, 23 - cmp r0, 0x7E - ble _0802166E - movs r0, 0 - strh r0, [r5, 0x24] - ldrh r1, [r4, 0xE] - ldr r0, =0x00007fff - ands r0, r1 - strh r0, [r4, 0xE] -_0802166E: - ldrh r0, [r4] - lsls r0, 16 - asrs r0, 23 - strh r0, [r5, 0x20] - movs r2, 0x22 - ldrsh r1, [r5, r2] - movs r2, 0x26 - ldrsh r0, [r5, r2] - adds r1, r0 - ldrh r2, [r4, 0xE] - ldr r0, =0x00007fff - ands r0, r2 - cmp r1, r0 - blt _0802169A - ldr r0, =SpriteCallbackDummy - str r0, [r5, 0x1C] - adds r0, r5, 0 - bl FreeSpriteOamMatrix - adds r0, r5, 0 - bl DestroySprite -_0802169A: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8021608 - - thumb_func_start sub_80216A8 -sub_80216A8: @ 80216A8 - push {r4-r7,lr} - adds r6, r0, 0 - movs r5, 0 - ldrb r0, [r6, 0x9] - cmp r5, r0 - bcs _080216D4 - ldr r7, =gUnknown_082F41E8 -_080216B6: - lsls r0, r5, 1 - adds r0, r7 - ldrh r4, [r0] - adds r0, r4, 0 - bl FreeSpritePaletteByTag - adds r0, r4, 0 - bl FreeSpriteTilesByTag - adds r0, r5, 0x1 - lsls r0, 24 - lsrs r5, r0, 24 - ldrb r0, [r6, 0x9] - cmp r5, r0 - bcc _080216B6 -_080216D4: - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80216A8 - thumb_func_start sub_80216E0 sub_80216E0: @ 80216E0 push {r4-r7,lr} diff --git a/data/berry_crush.s b/data/berry_crush.s index 4e3c77292..6535cd558 100755 --- a/data/berry_crush.s +++ b/data/berry_crush.s @@ -151,10 +151,22 @@ gUnknown_082F4190:: @ 82F4190 .align 2 gUnknown_082F41CC:: @ 82F41CC - .byte 0x00, 0x00, 0xff, 0x00, 0x01, 0x01, 0x00, 0x00 - .byte 0xf0, 0xfc, 0x10, 0xfc, 0xf8, 0xfe, 0x08, 0xfe - .byte 0xe8, 0xf8, 0x18, 0xf8, 0xe0, 0xf4, 0x20, 0xf4 - .byte 0xd8, 0xf0, 0x28, 0xf0 + .byte 0x00, 0x00 + .byte 0xff, 0x00 + .byte 0x01, 0x01 + +gUnknown_082F41D2:: + .byte 0x00, 0x00 + .byte 0xf0, 0xfc + .byte 0x10, 0xfc + .byte 0xf8, 0xfe + .byte 0x08, 0xfe + .byte 0xe8, 0xf8 + .byte 0x18, 0xf8 + .byte 0xe0, 0xf4 + .byte 0x20, 0xf4 + .byte 0xd8, 0xf0 + .byte 0x28, 0xf0 .align 2 gUnknown_082F41E8:: @ 82F41E8 diff --git a/include/berry_crush.h b/include/berry_crush.h new file mode 100755 index 000000000..101450a33 --- /dev/null +++ b/include/berry_crush.h @@ -0,0 +1,6 @@ +#ifndef GUARD_BERRY_CRUSH_H +#define GUARD_BERRY_CRUSH_H + +void sub_8020C70(MainCallback callback); + +#endif // GUARD_BERRY_CRUSH_H diff --git a/include/graphics.h b/include/graphics.h index 7833d4f7d..e6d6ae350 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -4917,8 +4917,12 @@ extern const u16 gLinkMiscMenu_Pal[]; extern const u32 gLinkMiscMenu_Gfx[]; extern const u32 gLinkMiscMenu_Tilemap[]; -// Pokeblock +// Use Pokeblock extern const u8 gPokenavConditionCancel_Gfx[]; extern const u16 gPokenavConditionCancel_Pal[]; +// Berry Crush +extern const u32 gUnknown_08DE34B8[]; +extern const u16 gUnknown_08DE3398[]; + #endif //GUARD_GRAPHICS_H diff --git a/include/item_icon.h b/include/item_icon.h index b702b2045..af03473fb 100644 --- a/include/item_icon.h +++ b/include/item_icon.h @@ -10,7 +10,7 @@ bool8 AllocItemIconTemporaryBuffers(void); void FreeItemIconTemporaryBuffers(void); void CopyItemIconPicTo4x4Buffer(const void *src, void *dest); u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId); -u8 AddCustomItemIconSprite(struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId); +u8 AddCustomItemIconSprite(const struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId); const void *GetItemIconPicOrPalette(u16 itemId, u8 which); #endif //GUARD_ITEM_ICON_H diff --git a/ld_script.txt b/ld_script.txt index f1ed87a04..97eb046b9 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -63,6 +63,7 @@ SECTIONS { asm/mevent_server_helpers.o(.text); src/mevent_news.o(.text); src/union_room_chat.o(.text); + src/berry_crush.o(.text); asm/berry_crush.o(.text); src/berry_powder.o(.text); asm/dodrio_berry_picking.o(.text); diff --git a/src/berry_crush.c b/src/berry_crush.c new file mode 100755 index 000000000..dc4c546b0 --- /dev/null +++ b/src/berry_crush.c @@ -0,0 +1,775 @@ +#include "global.h" +#include "alloc.h" +#include "berry_powder.h" +#include "bg.h" +#include "event_data.h" +#include "gpu_regs.h" +#include "graphics.h" +#include "item_icon.h" +#include "item_menu.h" +#include "link.h" +#include "link_rfu.h" +#include "main.h" +#include "math_util.h" +#include "menu.h" +#include "overworld.h" +#include "palette.h" +#include "rom_8034C54.h" +#include "scanline_effect.h" +#include "sound.h" +#include "sprite.h" +#include "string_util.h" +#include "task.h" +#include "text.h" +#include "trig.h" +#include "window.h" +#include "constants/items.h" +#include "constants/rgb.h" +#include "constants/songs.h" + +struct BerryCrushGame_Player +{ + u16 unk0; + u8 filler2[0x12]; + u8 unk14[0xC]; +}; + +struct BerryCrushGame_PlayersSeparate +{ + struct BerryCrushGame_Player player; + struct BerryCrushGame_Player others[4]; +}; + +typedef union BerryCrushGame_Players +{ + struct BerryCrushGame_Player players[5]; + struct BerryCrushGame_PlayersSeparate separate; +} BerryCrushGame_Players; + +struct BerryCrushGame_138_C +{ + u8 filler0[0x8]; + s16 unk8; + u16 unkA; +}; + +struct BerryCrushGame_138 +{ + u8 filler0[0xC]; + struct BerryCrushGame_138_C *unkC[5]; + u8 filler1C[0x4]; + struct Sprite *unk24[5]; + struct Sprite *unk38[5]; + struct Sprite *unk4C[5]; + struct Sprite *unk60[5]; + struct Sprite *unk74[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 +{ + MainCallback unk0; + void (* unk4)(struct BerryCrushGame *, u8 *); + u8 unk8; + u8 unk9; + u8 unkA; + u8 unkB; + u8 unkC; + u8 fillerD[0x1]; + u8 unkE; + u8 unkF; + u8 filler10[0x2]; + u16 unk12; + u8 filler14[0x2]; + u16 unk16; + u8 filler18[0x4]; + int unk1C; + u8 filler20[0x5]; + u8 unk25_0:1; + u8 unk25_1:1; + u8 unk25_2:1; + u8 filler26[0x2]; + u16 unk28; + u16 unk2A; + u16 unk2C; + u8 filler2E[0x8]; + u8 unk36[0xA]; + struct BerryCrushGame_40 unk40; + u8 filler60[0x8]; + int unk68; + u16 unk6C; + u8 filler6E[0x4]; + u16 unk72; + u8 filler74[0x10]; + BerryCrushGame_Players unk84; + u8 filler124[0x14]; + struct BerryCrushGame_138 unk138; + u8 unk1C0[0x1000]; + u8 unk11C0[0x1000]; + u8 unk21C0[0x1000]; + u8 unk31C0[0x1000]; +}; + +static void sub_8020F74(void); +static void sub_8020F88(void); +static void sub_8020FA0(u8); +void sub_8020FC4(struct BerryCrushGame *); +void sub_8022BEC(u16, u8, u8 *); +void sub_8024604(u8 *, u8, s8, u8, u8, u8, u8); +static int sub_8021450(struct BerryCrushGame *); +void sub_8022588(struct BerryCrushGame *); +void sub_8022600(struct BerryCrushGame *); +void sub_80226D0(struct BerryCrushGame *); +void sub_8022730(struct BerryCrushGame *); +void sub_8022960(struct BerryCrushGame *); +void sub_8022524(struct BerryCrushGame_138 *, u16); +void sub_8022B28(struct Sprite *); + +extern struct BerryCrushGame *gUnknown_02022C90; + +extern const struct BgTemplate gUnknown_082F32C8[4]; +extern const u8 gBerryCrushGrinderTopTilemap[]; +extern const u8 gBerryCrushContainerCapTilemap[]; +extern const u8 gBerryCrushBackgroundTilemap[]; +extern const struct SpriteTemplate gUnknown_082F436C; +extern const u16 gUnknown_082F41E8[]; +extern const s8 gUnknown_082F41CC[][2]; +extern const s8 gUnknown_082F41D2[][2]; + +struct BerryCrushGame *sub_8020C00(void) +{ + return gUnknown_02022C90; +} + +int sub_8020C0C(MainCallback callback) +{ + if (!gUnknown_02022C90) + return 2; + + if (!callback) + callback = gUnknown_02022C90->unk0; + + DestroyTask(gUnknown_02022C90->unkA); + FREE_AND_SET_NULL(gUnknown_02022C90); + SetMainCallback2(callback); + if (callback == CB2_ReturnToField) + { + gTextFlags.autoScroll = 1; + PlayNewMapMusic(MUS_POKECEN); + SetMainCallback1(CB1_Overworld); + } + + return 0; +} + +void sub_8020C70(MainCallback callback) +{ + u8 playerCount = 0; + u8 multiplayerId; + + if (!gReceivedRemoteLinkPlayers || gWirelessCommType == 0) + { + SetMainCallback2(callback); + gUnknown_03005000.unk_10 = 0; + gUnknown_03005000.unk_12 = 0; + gUnknown_03005000.unk_ee = 1; + return; + } + + playerCount = GetLinkPlayerCount(); + multiplayerId = GetMultiplayerId(); + if (playerCount < 2 || multiplayerId >= playerCount) + { + SetMainCallback2(callback); + gUnknown_03005000.unk_10 = 0; + gUnknown_03005000.unk_12 = 0; + gUnknown_03005000.unk_ee = 1; + return; + } + + gUnknown_02022C90 = AllocZeroed(sizeof(*gUnknown_02022C90)); + if (!gUnknown_02022C90) + { + SetMainCallback2(callback); + gUnknown_03005000.unk_10 = 0; + gUnknown_03005000.unk_12 = 0; + gUnknown_03005000.unk_ee = 1; + return; + } + + gUnknown_02022C90->unk0 = callback; + gUnknown_02022C90->unk8 = multiplayerId; + gUnknown_02022C90->unk9 = playerCount; + sub_8020FC4(gUnknown_02022C90); + gUnknown_02022C90->unk12 = 1; + gUnknown_02022C90->unkE = 1; + gUnknown_02022C90->unkF = 6; + sub_8024604(gUnknown_02022C90->unk36, 1, -1, 0, 16, 0, 0); + sub_8022BEC(4, 1, gUnknown_02022C90->unk36); + SetMainCallback2(sub_8020F88); + gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); + gTextFlags.autoScroll = 0; +} + +static void sub_8020D8C(void) +{ + if (gSpecialVar_ItemId < FIRST_BERRY_INDEX || gSpecialVar_ItemId > LAST_BERRY_INDEX + 1) + gSpecialVar_ItemId = ITEM_CHERI_BERRY; + else + RemoveBagItem(gSpecialVar_ItemId, 1); + + gUnknown_02022C90->unk84.separate.others[gUnknown_02022C90->unk8].unk0 = gSpecialVar_ItemId - FIRST_BERRY_INDEX; + gUnknown_02022C90->unkE = 1; + gUnknown_02022C90->unkF = 9; + sub_8024604(gUnknown_02022C90->unk36, 0, -1, 0, 16, 0, 0); + sub_8022BEC(4, 1, gUnknown_02022C90->unk36); + gUnknown_02022C90->unkA = CreateTask(sub_8020FA0, 8); + SetMainCallback2(sub_8020F88); +} + +void sub_8020E1C(void) +{ + DestroyTask(gUnknown_02022C90->unkA); + sub_81AABF0(sub_8020D8C); +} + +static void sub_8020E3C(void) +{ + SetVBlankCallback(sub_8020F74); +} + +void sub_8020E4C(void) +{ + SetVBlankCallback(NULL); +} + +void sub_8020E58(void) +{ + u32 var0, var1; + + var0 = gUnknown_02022C90->unk6C; + var0 <<= 8; + var0 = sub_81515FC(var0, 60 << 8); + var1 = gUnknown_02022C90->unk72; + var1 <<= 8; + var1 = sub_81515FC(var1, var0) & 0xFFFF; + gUnknown_02022C90->unk16 = var1; + switch (gUnknown_02022C90->unk9) + { + case 2: + if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[0]) + { + gUnknown_02022C90->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[0] = gUnknown_02022C90->unk16; + } + break; + case 3: + if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[1]) + { + gUnknown_02022C90->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[1] = gUnknown_02022C90->unk16; + } + break; + case 4: + if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[2]) + { + gUnknown_02022C90->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[2] = gUnknown_02022C90->unk16; + } + break; + case 5: + if (gUnknown_02022C90->unk16 > gSaveBlock2Ptr->berryCrush.berryCrushResults[3]) + { + gUnknown_02022C90->unk25_1 = 1; + gSaveBlock2Ptr->berryCrush.berryCrushResults[3] = gUnknown_02022C90->unk16; + } + break; + } + + gUnknown_02022C90->unk1C = gUnknown_02022C90->unk68; + if (GiveBerryPowder(gUnknown_02022C90->unk1C)) + return; + + gUnknown_02022C90->unk25_0 = 1; +} + +static void sub_8020F74(void) +{ + TransferPlttBuffer(); + LoadOam(); + ProcessSpriteCopyRequests(); +} + +static void sub_8020F88(void) +{ + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); +} + +static void sub_8020FA0(u8 taskId) +{ + if (gUnknown_02022C90->unk4) + gUnknown_02022C90->unk4(gUnknown_02022C90, gUnknown_02022C90->unk36); + + sub_8021450(gUnknown_02022C90); +} + +#ifdef NONMATCHING +void sub_8020FC4(struct BerryCrushGame *arg0) +{ + u8 i; + + for (i = 0; i < arg0->unk9; i++) + StringCopy(arg0->unk84.players[i].unk14, gLinkPlayers[i].name); + + for (; i < 5; i++) + { + memset(arg0->unk84.players[i].unk14, 1, PLAYER_NAME_LENGTH); + arg0->unk84.players[i].unk14[PLAYER_NAME_LENGTH] = EOS; + } + + switch (gSaveBlock2Ptr->optionsTextSpeed) + { + case OPTIONS_TEXT_SPEED_SLOW: + arg0->unkB = 8; + break; + case OPTIONS_TEXT_SPEED_MID: + arg0->unkB = 4; + break; + case OPTIONS_TEXT_SPEED_FAST: + arg0->unkB = 1; + break; + } +} +#else +NAKED +void sub_8020FC4(struct BerryCrushGame *arg0) +{ + asm_unified("\n\ + push {r4-r6,lr}\n\ + adds r6, r0, 0\n\ + movs r5, 0\n\ + b _08020FE6\n\ +LOOP_1:\n\ + lsls r0, r5, 5\n\ + adds r0, 0x98\n\ + adds r0, r6, r0\n\ + lsls r1, r5, 3\n\ + subs r1, r5\n\ + lsls r1, 2\n\ + ldr r2, =gLinkPlayers + 8\n\ + adds r1, r2\n\ + bl StringCopy\n\ + adds r0, r5, 0x1\n\ + lsls r0, 24\n\ + lsrs r5, r0, 24\n\ +_08020FE6:\n\ + ldrb r0, [r6, 0x9]\n\ + cmp r5, r0\n\ + bcc LOOP_1\n\ + cmp r5, 0x4\n\ + bhi _08021012\n\ +_08020FF0:\n\ + lsls r4, r5, 5\n\ + adds r0, r4, 0\n\ + adds r0, 0x98\n\ + adds r0, r6, r0\n\ + movs r1, 0x1\n\ + movs r2, 0x7\n\ + bl memset\n\ + adds r4, r6, r4\n\ + adds r4, 0x9F\n\ + movs r0, 0xFF\n\ + strb r0, [r4]\n\ + adds r0, r5, 0x1\n\ + lsls r0, 24\n\ + lsrs r5, r0, 24\n\ + cmp r5, 0x4\n\ + bls _08020FF0\n\ +_08021012:\n\ + ldr r0, =gSaveBlock2Ptr\n\ + ldr r0, [r0]\n\ + ldrb r0, [r0, 0x14]\n\ + lsls r0, 29\n\ + lsrs r0, 29\n\ + cmp r0, 0x1\n\ + beq _0802103E\n\ + cmp r0, 0x1\n\ + bgt _08021034\n\ + cmp r0, 0\n\ + beq _0802103A\n\ + b _08021046\n\ + .pool\n\ +_08021034:\n\ + cmp r0, 0x2\n\ + beq _08021042\n\ + b _08021046\n\ +_0802103A:\n\ + movs r0, 0x8\n\ + b _08021044\n\ +_0802103E:\n\ + movs r0, 0x4\n\ + b _08021044\n\ +_08021042:\n\ + movs r0, 0x1\n\ +_08021044:\n\ + strb r0, [r6, 0xB]\n\ +_08021046:\n\ + pop {r4-r6}\n\ + pop {r0}\n\ + bx r0"); +} +#endif // NONMATCHING + +int sub_802104C(void) +{ + struct BerryCrushGame *var0 = sub_8020C00(); + if (!var0) + return -1; + + switch (var0->unkC) + { + case 0: + SetVBlankCallback(NULL); + SetHBlankCallback(NULL); + SetGpuReg(REG_OFFSET_DISPCNT, 0); + ScanlineEffect_Stop(); + reset_temp_tile_data_buffers(); + break; + case 1: + CpuFill16(0, (void *)OAM, OAM_SIZE); + gReservedSpritePaletteCount = 0; + sub_8034C54(3); + break; + case 2: + ResetPaletteFade(); + ResetSpriteData(); + FreeAllSpritePalettes(); + break; + case 3: + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_082F32C8, ARRAY_COUNT(gUnknown_082F32C8)); + SetBgTilemapBuffer(1, var0->unk1C0); + SetBgTilemapBuffer(2, var0->unk21C0); + SetBgTilemapBuffer(3, var0->unk31C0); + ChangeBgX(0, 0, 0); + ChangeBgY(0, 0, 0); + ChangeBgX(2, 0, 0); + ChangeBgY(2, 0, 0); + ChangeBgX(3, 0, 0); + ChangeBgY(3, 0, 0); + SetGpuReg(REG_OFFSET_BLDCNT, 0); + SetGpuReg(REG_OFFSET_BLDALPHA, 0); + break; + case 4: + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); + FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 32, 64); + FillBgTilemapBufferRect_Palette0(2, 0, 0, 0, 32, 32); + FillBgTilemapBufferRect_Palette0(3, 0, 0, 0, 32, 32); + break; + case 5: + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(3); + decompress_and_copy_tile_data_to_vram(1, gUnknown_08DE34B8, 0, 0, 0); + break; + case 6: + if (free_temp_tile_data_buffers_if_possible()) + return 0; + + InitStandardTextBoxWindows(); + sub_8197200(); + sub_8022588(var0); + sub_8022600(var0); + gPaletteFade.bufferTransferDisabled = 1; + break; + case 7: + LoadPalette(gUnknown_08DE3398, 0, 0x180); + CopyToBgTilemapBuffer(1, gBerryCrushGrinderTopTilemap, 0, 0); + CopyToBgTilemapBuffer(2, gBerryCrushContainerCapTilemap, 0, 0); + CopyToBgTilemapBuffer(3, gBerryCrushBackgroundTilemap, 0, 0); + sub_80226D0(var0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(3); + break; + case 8: + sub_800E0E8(); + CreateWirelessStatusIndicatorSprite(0, 0); + sub_8022730(var0); + SetGpuReg(REG_OFFSET_BG1VOFS, -gSpriteCoordOffsetY); + ChangeBgX(1, 0, 0); + ChangeBgY(1, 0, 0); + break; + case 9: + gPaletteFade.bufferTransferDisabled = 0; + BlendPalettes(0xFFFFFFFF, 16, RGB_BLACK); + ShowBg(0); + ShowBg(1); + ShowBg(2); + ShowBg(3); + SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + sub_8020E3C(); + var0->unkC = 0; + return 1; + } + + var0->unkC++; + return 0; +} + +int sub_802130C(void) +{ + struct BerryCrushGame *var0 = sub_8020C00(); + if (!var0) + return -1; + + switch (var0->unkC) + { + case 0: + sub_8010434(); + break; + case 1: + if (!IsLinkTaskFinished()) + return 0; + // fall through. The original author forgot to use "break" here + // because this will call BeginNormalPaletteFade() twice. + case 2: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); + UpdatePaletteFade(); + break; + case 3: + if (UpdatePaletteFade()) + return 0; + break; + case 4: + FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, 32, 32); + FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 32, 32); + FillBgTilemapBufferRect_Palette0(2, 0, 0, 0, 32, 32); + FillBgTilemapBufferRect_Palette0(3, 0, 0, 0, 32, 32); + CopyBgTilemapBufferToVram(0); + CopyBgTilemapBufferToVram(1); + CopyBgTilemapBufferToVram(2); + CopyBgTilemapBufferToVram(3); + break; + case 5: + FreeAllWindowBuffers(); + HideBg(0); + UnsetBgTilemapBuffer(0); + HideBg(1); + UnsetBgTilemapBuffer(1); + HideBg(2); + UnsetBgTilemapBuffer(2); + HideBg(3); + UnsetBgTilemapBuffer(3); + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP); + break; + case 6: + sub_800E084(); + sub_8022960(var0); + sub_8034CC8(); + break; + case 7: + var0->unkC = 0; + return 1; + } + + var0->unkC++; + return 0; +} + +static int sub_8021450(struct BerryCrushGame *arg0) +{ + gSpriteCoordOffsetY = arg0->unk2A + arg0->unk2C; + SetGpuReg(REG_OFFSET_BG1VOFS, -gSpriteCoordOffsetY); + if (arg0->unk12 == 7) + { + sub_8022524(&arg0->unk138, arg0->unk28); + } + + return 0; +} + +void sub_8021488(struct BerryCrushGame *arg0) +{ + arg0->unk2A = -104; + arg0->unk2C = 0; + gSpriteCoordOffsetX = 0; + gSpriteCoordOffsetY = -104; +} + +void sub_80214A8(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) +{ + u8 i; + u8 spriteId; + s16 var0, var1; + s16 *data; + int var3; + s16 var5; + u32 var6; + + for (i = 0; i < arg0->unk9; i++) + { + spriteId = AddCustomItemIconSprite( + &gUnknown_082F436C, + gUnknown_082F41E8[i], + gUnknown_082F41E8[i], + arg0->unk84.separate.others[i].unk0 + 133); + arg1->unk38[i] = &gSprites[spriteId]; + arg1->unk38[i]->oam.priority = 3; + arg1->unk38[i]->affineAnimPaused = 1; + arg1->unk38[i]->pos1.x = arg1->unkC[i]->unk8 + 120; + arg1->unk38[i]->pos1.y = -16; + data = arg1->unk38[i]->data; + var5 = 512; + data[1] = var5; + data[2] = 32; + data[7] = 112; + var0 = arg1->unkC[i]->unkA - arg1->unkC[i]->unk8; + var3 = var0; + if (var0 < 0) + var3 += 3; + + data[6] = var3 >> 2; + var0 *= 128; + var6 = var5 + 32; + var6 = var6 / 2; + var1 = sub_81515D4(7, 0x3F80, var6); + data[0] = (u16)arg1->unk38[i]->pos1.x * 128; + data[3] = sub_81515D4(7, var0, var1); + var1 = sub_8151550(7, var1, 85); + data[4] = 0; + data[5] = sub_81515D4(7, 0x3F80, var1); + data[7] |= 0x8000; + if (arg1->unkC[i]->unk8 < 0) + StartSpriteAffineAnim(arg1->unk38[i], 1); + } +} + +void sub_8021608(struct Sprite *sprite) +{ + s16 *data = sprite->data; + + data[1] += data[2]; + sprite->pos2.y += data[1] >> 8; + if (data[7] & 0x8000) + { + sprite->data[0] += data[3]; + data[4] += data[5]; + sprite->pos2.x = Sin(data[4] >> 7, data[6]); + if ((data[7] & 0x8000) && (data[4] >> 7) > 126) + { + sprite->pos2.x = 0; + data[7] &= 0x7FFF; + } + } + + sprite->pos1.x = data[0] >> 7; + if (sprite->pos1.y + sprite->pos2.y >= (data[7] & 0x7FFF)) + { + sprite->callback = SpriteCallbackDummy; + FreeSpriteOamMatrix(sprite); + DestroySprite(sprite); + } +} + +void sub_80216A8(struct BerryCrushGame *arg0) +{ + u8 i; + for (i = 0; i < arg0->unk9; i++) + { + FreeSpritePaletteByTag(gUnknown_082F41E8[i]); + FreeSpriteTilesByTag(gUnknown_082F41E8[i]); + } +} + +// void sub_80216E0(struct BerryCrushGame *arg0, struct BerryCrushGame_138 *arg1) +// { +// u8 sp4; +// struct BerryCrushGame_4E *var4E; +// u8 i; +// u16 var0; + +// sp4 = 0; +// var4E = &arg0->unk40.unkE; +// for (i = 0; i < arg0->unk9; i++) +// { +// var0 = var4E->unkA >> (i * 3); +// var0 &= 7; +// if (var0) +// { +// int offset; +// sp4++; +// if (var0 & 0x4) +// StartSpriteAnim(arg1->unk24[i], 1); +// else +// StartSpriteAnim(arg1->unk24[i], 0); + +// arg1->unk24[i]->invisible = 0; +// arg1->unk24[i]->animPaused = 0; +// offset = (var0 % 4) - 1; +// arg1->unk24[i]->pos2.x = gUnknown_082F41CC[offset][0]; +// arg1->unk24[i]->pos2.y = gUnknown_082F41CC[offset][1]; +// } +// } + +// if (sp4 == 0) +// { +// arg0->unk25_2 = 0; +// } +// else +// { +// u8 var3 = arg0->unk28 % 3; +// u16 var2 = var3; +// for (i = 0; i < var4E->unkC * 2 + 3; i++) +// { +// if (arg1->unk4C[i]->invisible) +// { +// arg1->unk4C[i]->callback = sub_8022B28; +// arg1->unk4C[i]->pos1.x = gUnknown_082F41D2[i][0] + 120; +// arg1->unk4C[i]->pos1.y = gUnknown_082F41D2[i][1] + (136 - var2 * 4); +// arg1->unk4C[i]->pos2.x = gUnknown_082F41D2[i][0] / (var3 * 4); +// arg1->unk4C[i]->pos2.y = gUnknown_082F41D2[i][1]; +// if (var4E->unk4 & 0x2) +// StartSpriteAnim(arg1->unk4C[i], 1); +// else +// StartSpriteAnim(arg1->unk4C[i], 0); + +// var2++; +// if (var2 > 3) +// var2 = 0; +// } +// } + +// if (arg0->unk25_2) +// { +// arg0->unk25_2 = 0; +// } +// else +// { +// if (sp4 == 1) +// PlaySE(SE_TOY_DANGO); +// else +// PlaySE(SE_TOY_KABE); + +// arg0->unk25_2 = 1; +// } +// } +// } diff --git a/src/item_icon.c b/src/item_icon.c index 7bf1a29ca..91c32951a 100644 --- a/src/item_icon.c +++ b/src/item_icon.c @@ -122,7 +122,7 @@ u8 AddItemIconSprite(u16 tilesTag, u16 paletteTag, u16 itemId) } } -u8 AddCustomItemIconSprite(struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId) +u8 AddCustomItemIconSprite(const struct SpriteTemplate *customSpriteTemplate, u16 tilesTag, u16 paletteTag, u16 itemId) { if (!AllocItemIconTemporaryBuffers()) { diff --git a/src/union_room.c b/src/union_room.c index 338063ef1..5050b04f1 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -44,6 +44,7 @@ #include "easy_chat.h" #include "event_obj_lock.h" #include "union_room_chat.h" +#include "berry_crush.h" EWRAM_DATA u8 gUnknown_02022C20[12] = {}; EWRAM_DATA u8 gUnknown_02022C2C = 0; @@ -98,7 +99,6 @@ void sub_801807C(struct TradeUnkStruct *arg0); void sub_801AC54(void); void sub_802A9A8(u8 monId, MainCallback callback); void sub_802493C(u8 monId, MainCallback callback); -void sub_8020C70(MainCallback callback); void sub_80149D8(void); u16 sub_8019930(void); void sub_8018784(u8 windowId);