From d413187fa82e19ceea5ff1b2437891329781a814 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 1 Aug 2017 11:07:23 +0200 Subject: [PATCH 1/4] start decompiling egg hatch --- asm/egg_hatch.s | 1319 ------------------------------------------ include/decompress.h | 2 +- include/pokemon.h | 2 +- include/sprite.h | 16 +- src/egg_hatch.c | 571 +++++++++++++++++- 5 files changed, 580 insertions(+), 1330 deletions(-) diff --git a/asm/egg_hatch.s b/asm/egg_hatch.s index 7365f4da6..51e688998 100644 --- a/asm/egg_hatch.s +++ b/asm/egg_hatch.s @@ -6,1326 +6,7 @@ .text - thumb_func_start AddHatchedMonToParty -AddHatchedMonToParty: @ 80429EC - push {r4-r6,lr} - sub sp, 0x14 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x64 - adds r5, r0, 0 - muls r5, r1 - ldr r0, _08042A9C @ =gPlayerParty - adds r5, r0 - ldr r1, _08042AA0 @ =gEnemyParty - adds r0, r5, 0 - bl CreatedHatchedMon - add r2, sp, 0xC - movs r6, 0 - strb r6, [r2] - adds r0, r5, 0 - movs r1, 0x2D - bl SetMonData - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - mov r0, sp - adds r1, r4, 0 - bl GetSpeciesName - adds r0, r5, 0 - movs r1, 0x2 - mov r2, sp - bl SetMonData - adds r0, r4, 0 - bl SpeciesToNationalPokedexNum - adds r4, r0, 0 - lsls r4, 16 - lsrs r4, 16 - adds r0, r4, 0 - movs r1, 0x2 - bl GetNationalPokedexFlag - adds r0, r4, 0 - movs r1, 0x3 - bl GetNationalPokedexFlag - ldr r1, _08042AA4 @ =gStringVar1 - adds r0, r5, 0 - bl GetMonNick - mov r2, sp - adds r2, 0xE - movs r0, 0x4 - strh r0, [r2] - adds r0, r5, 0 - movs r1, 0x26 - bl SetMonData - add r2, sp, 0x10 - strh r6, [r2] - adds r0, r5, 0 - movs r1, 0x24 - bl SetMonData - bl sav1_map_get_name - mov r2, sp - adds r2, 0x12 - strb r0, [r2] - adds r0, r5, 0 - movs r1, 0x23 - bl SetMonData - adds r0, r5, 0 - bl MonRestorePP - adds r0, r5, 0 - bl CalculateMonStats - add sp, 0x14 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_08042A9C: .4byte gPlayerParty -_08042AA0: .4byte gEnemyParty -_08042AA4: .4byte gStringVar1 - thumb_func_end AddHatchedMonToParty - thumb_func_start ScriptHatchMon -ScriptHatchMon: @ 8042AA8 - push {lr} - ldr r0, _08042AB8 @ =gSpecialVar_0x8004 - ldrb r0, [r0] - bl AddHatchedMonToParty - pop {r0} - bx r0 - .align 2, 0 -_08042AB8: .4byte gSpecialVar_0x8004 - thumb_func_end ScriptHatchMon - - thumb_func_start sub_8042ABC -sub_8042ABC: @ 8042ABC - push {r4-r6,lr} - sub sp, 0x20 - adds r5, r0, 0 - lsls r4, r1, 24 - lsrs r4, 24 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 4 - adds r0, r5, r0 - mov r1, sp - bl GetBoxMonNick - lsls r0, r4, 3 - subs r0, r4 - lsls r1, r0, 3 - adds r0, r5, r1 - adds r0, 0xC0 - ldrh r0, [r0] - cmp r0, 0 - beq _08042B40 - adds r0, r1, 0 - adds r0, 0xA0 - adds r5, r0 - adds r6, r5, 0 - adds r6, 0x2C - mov r0, sp - adds r1, r6, 0 - bl StringCompareWithoutExtCtrlCodes - cmp r0, 0 - bne _08042B08 - ldr r0, _08042B30 @ =gSaveBlock2 - adds r1, r5, 0 - adds r1, 0x24 - bl StringCompareWithoutExtCtrlCodes - cmp r0, 0 - beq _08042B40 -_08042B08: - ldr r0, _08042B34 @ =gStringVar1 - mov r1, sp - bl StringCopy - ldr r4, _08042B38 @ =gStringVar2 - adds r1, r5, 0 - adds r1, 0x24 - adds r0, r4, 0 - bl StringCopy - ldr r0, _08042B3C @ =gStringVar3 - adds r1, r6, 0 - bl StringCopy - adds r0, r4, 0 - bl SanitizeNameString - movs r0, 0x1 - b _08042B42 - .align 2, 0 -_08042B30: .4byte gSaveBlock2 -_08042B34: .4byte gStringVar1 -_08042B38: .4byte gStringVar2 -_08042B3C: .4byte gStringVar3 -_08042B40: - movs r0, 0 -_08042B42: - add sp, 0x20 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_8042ABC - - thumb_func_start sub_8042B4C -sub_8042B4C: @ 8042B4C - push {lr} - ldr r0, _08042B60 @ =gSaveBlock1 + 0x2F9C - ldr r1, _08042B64 @ =gSpecialVar_0x8004 - ldrb r1, [r1] - bl sub_8042ABC - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .align 2, 0 -_08042B60: .4byte gSaveBlock1 + 0x2F9C -_08042B64: .4byte gSpecialVar_0x8004 - thumb_func_end sub_8042B4C - - thumb_func_start EggHatchCreateMonSprite -EggHatchCreateMonSprite: @ 8042B68 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0xC - lsls r0, 24 - lsrs r3, r0, 24 - adds r4, r3, 0 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r1, r2, 24 - adds r2, r1, 0 - movs r5, 0 - mov r9, r5 - movs r7, 0 - cmp r3, 0 - bne _08042B96 - movs r0, 0x64 - muls r1, r0 - ldr r0, _08042BB0 @ =gPlayerParty - adds r7, r1, r0 - movs r5, 0x1 -_08042B96: - cmp r3, 0x1 - bne _08042BA6 - movs r0, 0x64 - adds r1, r2, 0 - muls r1, r0 - ldr r0, _08042BB0 @ =gPlayerParty - adds r7, r1, r0 - movs r5, 0x3 -_08042BA6: - cmp r6, 0 - beq _08042BB4 - cmp r6, 0x1 - beq _08042C14 - b _08042C50 - .align 2, 0 -_08042BB0: .4byte gPlayerParty -_08042BB4: - adds r0, r7, 0 - movs r1, 0xB - bl GetMonData - adds r5, r0, 0 - lsls r5, 16 - lsrs r5, 16 - adds r0, r7, 0 - movs r1, 0 - bl GetMonData - mov r8, r0 - lsls r0, r5, 3 - ldr r1, _08042C04 @ =gMonFrontPicTable - adds r0, r1 - ldr r1, _08042C08 @ =gMonFrontPicCoords - lsls r2, r5, 2 - adds r2, r1 - ldrb r1, [r2] - ldrb r2, [r2, 0x1] - ldr r3, _08042C0C @ =0x02000000 - ldr r6, _08042C10 @ =gUnknown_081FAF4C - lsls r4, 1 - adds r4, 0x1 - lsls r4, 2 - adds r4, r6 - ldr r4, [r4] - str r4, [sp] - str r5, [sp, 0x4] - mov r4, r8 - str r4, [sp, 0x8] - bl HandleLoadSpecialPokePic - adds r0, r7, 0 - bl sub_8040990 - bl LoadCompressedObjectPalette - b _08042C50 - .align 2, 0 -_08042C04: .4byte gMonFrontPicTable -_08042C08: .4byte gMonFrontPicCoords -_08042C0C: .4byte 0x02000000 -_08042C10: .4byte gUnknown_081FAF4C -_08042C14: - adds r0, r7, 0 - bl sub_8040990 - ldrh r0, [r0, 0x4] - adds r1, r5, 0 - bl GetMonSpriteTemplate_803C56C - ldr r0, _08042C60 @ =gUnknown_02024E8C - movs r1, 0x78 - movs r2, 0x46 - movs r3, 0x6 - bl CreateSprite - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - ldr r4, _08042C64 @ =gSprites - lsls r1, r0, 4 - add r1, r9 - lsls r1, 2 - adds r2, r1, r4 - adds r2, 0x3E - ldrb r0, [r2] - movs r3, 0x4 - orrs r0, r3 - strb r0, [r2] - adds r4, 0x1C - adds r1, r4 - ldr r0, _08042C68 @ =SpriteCallbackDummy - str r0, [r1] -_08042C50: - mov r0, r9 - add sp, 0xC - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - .align 2, 0 -_08042C60: .4byte gUnknown_02024E8C -_08042C64: .4byte gSprites -_08042C68: .4byte SpriteCallbackDummy - thumb_func_end EggHatchCreateMonSprite - - thumb_func_start VBlankCB_EggHatch -VBlankCB_EggHatch: @ 8042C6C - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end VBlankCB_EggHatch - - thumb_func_start EggHatch -EggHatch: @ 8042C80 - push {lr} - sub sp, 0x4 - bl ScriptContext2_Enable - ldr r0, _08042CA8 @ =Task_EggHatch - movs r1, 0xA - bl CreateTask - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - add sp, 0x4 - pop {r0} - bx r0 - .align 2, 0 -_08042CA8: .4byte Task_EggHatch - thumb_func_end EggHatch - - thumb_func_start Task_EggHatch -Task_EggHatch: @ 8042CAC - push {r4,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r0, _08042CD8 @ =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _08042CD0 - ldr r0, _08042CDC @ =CB2_EggHatch_0 - bl SetMainCallback2 - ldr r1, _08042CE0 @ =gFieldCallback - ldr r0, _08042CE4 @ =sub_8080990 - str r0, [r1] - adds r0, r4, 0 - bl DestroyTask -_08042CD0: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_08042CD8: .4byte gPaletteFade -_08042CDC: .4byte CB2_EggHatch_0 -_08042CE0: .4byte gFieldCallback -_08042CE4: .4byte sub_8080990 - thumb_func_end Task_EggHatch - - thumb_func_start CB2_EggHatch_0 -CB2_EggHatch_0: @ 8042CE8 - push {r4-r7,lr} - ldr r0, _08042D04 @ =gMain - ldr r1, _08042D08 @ =0x0000043c - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x8 - bls _08042CF8 - b _08042F6E -_08042CF8: - lsls r0, 2 - ldr r1, _08042D0C @ =_08042D10 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08042D04: .4byte gMain -_08042D08: .4byte 0x0000043c -_08042D0C: .4byte _08042D10 - .align 2, 0 -_08042D10: - .4byte _08042D34 - .4byte _08042D90 - .4byte _08042DC4 - .4byte _08042E20 - .4byte _08042E40 - .4byte _08042E74 - .4byte _08042E88 - .4byte _08042EB0 - .4byte _08042F40 -_08042D34: - movs r0, 0x80 - lsls r0, 19 - movs r2, 0 - strh r2, [r0] - ldr r1, _08042D74 @ =gUnknown_0300481C - ldr r0, _08042D78 @ =0x02018000 - str r0, [r1] - ldr r1, _08042D7C @ =gSpecialVar_0x8004 - ldrh r1, [r1] - strb r1, [r0, 0x4] - adds r0, 0x3A - strb r2, [r0] - bl ResetTasks - bl ResetSpriteData - bl FreeAllSpritePalettes - ldr r0, _08042D80 @ =VBlankCB_EggHatch - bl SetVBlankCallback - ldr r1, _08042D84 @ =gMain - ldr r2, _08042D88 @ =0x0000043c - adds r1, r2 - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - bl GetCurrentMapMusic - ldr r1, _08042D8C @ =gSpecialVar_0x8005 - strh r0, [r1] - b _08042F6E - .align 2, 0 -_08042D74: .4byte gUnknown_0300481C -_08042D78: .4byte 0x02018000 -_08042D7C: .4byte gSpecialVar_0x8004 -_08042D80: .4byte VBlankCB_EggHatch -_08042D84: .4byte gMain -_08042D88: .4byte 0x0000043c -_08042D8C: .4byte gSpecialVar_0x8005 -_08042D90: - ldr r5, _08042DBC @ =gWindowConfig_81E6F84 - adds r0, r5, 0 - bl SetUpWindowConfig - ldr r4, _08042DC0 @ =gUnknown_0300481C - ldr r0, [r4] - adds r0, 0x8 - adds r1, r5, 0 - bl InitWindowFromConfig - movs r0, 0x14 - bl SetTextWindowBaseTileNum - ldr r1, [r4] - adds r1, 0x38 - strb r0, [r1] - ldr r0, [r4] - adds r0, 0x8 - bl LoadTextWindowGraphics - b _08042F04 - .align 2, 0 -_08042DBC: .4byte gWindowConfig_81E6F84 -_08042DC0: .4byte gUnknown_0300481C -_08042DC4: - ldr r0, _08042DFC @ =gUnknown_08D00000 - movs r1, 0xC0 - lsls r1, 19 - bl LZDecompressVram - ldr r0, _08042E00 @ =gUnknown_08D00524 - ldr r4, _08042E04 @ =0x02000000 - movs r2, 0x80 - lsls r2, 4 - adds r1, r4, 0 - bl CpuSet - ldr r1, _08042E08 @ =0x040000d4 - str r4, [r1] - ldr r0, _08042E0C @ =0x06002800 - str r0, [r1, 0x4] - ldr r0, _08042E10 @ =0x80000280 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - ldr r0, _08042E14 @ =gUnknown_08D004E0 - movs r1, 0 - movs r2, 0x20 - bl LoadCompressedPalette - ldr r1, _08042E18 @ =gMain - ldr r2, _08042E1C @ =0x0000043c - adds r1, r2 - b _08042F0A - .align 2, 0 -_08042DFC: .4byte gUnknown_08D00000 -_08042E00: .4byte gUnknown_08D00524 -_08042E04: .4byte 0x02000000 -_08042E08: .4byte 0x040000d4 -_08042E0C: .4byte 0x06002800 -_08042E10: .4byte 0x80000280 -_08042E14: .4byte gUnknown_08D004E0 -_08042E18: .4byte gMain -_08042E1C: .4byte 0x0000043c -_08042E20: - ldr r0, _08042E34 @ =gUnknown_0820A3B0 - bl LoadSpriteSheet - ldr r0, _08042E38 @ =gUnknown_0820A3B8 - bl LoadSpriteSheet - ldr r0, _08042E3C @ =gUnknown_0820A3C0 - bl LoadSpritePalette - b _08042F04 - .align 2, 0 -_08042E34: .4byte gUnknown_0820A3B0 -_08042E38: .4byte gUnknown_0820A3B8 -_08042E3C: .4byte gUnknown_0820A3C0 -_08042E40: - ldr r0, _08042E64 @ =gSpriteTemplate_820A3C8 - movs r1, 0x78 - movs r2, 0x4B - movs r3, 0x5 - bl CreateSprite - ldr r2, _08042E68 @ =gUnknown_0300481C - ldr r1, [r2] - strb r0, [r1] - ldr r0, [r2] - ldrb r0, [r0, 0x4] - bl AddHatchedMonToParty - ldr r1, _08042E6C @ =gMain - ldr r2, _08042E70 @ =0x0000043c - adds r1, r2 - b _08042F0A - .align 2, 0 -_08042E64: .4byte gSpriteTemplate_820A3C8 -_08042E68: .4byte gUnknown_0300481C -_08042E6C: .4byte gMain -_08042E70: .4byte 0x0000043c -_08042E74: - ldr r0, _08042E84 @ =gUnknown_0300481C - ldr r0, [r0] - ldrb r2, [r0, 0x4] - movs r0, 0 - movs r1, 0 - bl EggHatchCreateMonSprite - b _08042F04 - .align 2, 0 -_08042E84: .4byte gUnknown_0300481C -_08042E88: - ldr r4, _08042EA4 @ =gUnknown_0300481C - ldr r0, [r4] - ldrb r2, [r0, 0x4] - movs r0, 0 - movs r1, 0x1 - bl EggHatchCreateMonSprite - ldr r1, [r4] - strb r0, [r1, 0x1] - ldr r1, _08042EA8 @ =gMain - ldr r2, _08042EAC @ =0x0000043c - adds r1, r2 - b _08042F0A - .align 2, 0 -_08042EA4: .4byte gUnknown_0300481C -_08042EA8: .4byte gMain -_08042EAC: .4byte 0x0000043c -_08042EB0: - ldr r0, _08042F14 @ =REG_BG2CNT - ldr r2, _08042F18 @ =0x00004c06 - adds r1, r2, 0 - strh r1, [r0] - ldr r0, _08042F1C @ =gUnknown_0820C9F8 - movs r1, 0x10 - movs r2, 0xA0 - bl LoadPalette - ldr r3, _08042F20 @ =gUnknown_0820CA98 - ldr r4, _08042F24 @ =0x06004000 - movs r5, 0x98 - lsls r5, 5 - ldr r1, _08042F28 @ =0x040000d4 - ldr r6, _08042F2C @ =0x80000800 - movs r2, 0x80 - lsls r2, 5 - movs r7, 0x80 - lsls r7, 24 -_08042ED6: - str r3, [r1] - str r4, [r1, 0x4] - str r6, [r1, 0x8] - ldr r0, [r1, 0x8] - adds r3, r2 - adds r4, r2 - subs r5, r2 - cmp r5, r2 - bhi _08042ED6 - str r3, [r1] - str r4, [r1, 0x4] - lsrs r0, r5, 1 - orrs r0, r7 - str r0, [r1, 0x8] - ldr r0, [r1, 0x8] - ldr r1, _08042F30 @ =gUnknown_0820F798 - ldr r2, _08042F34 @ =0x06006000 - ldr r0, _08042F28 @ =0x040000d4 - str r1, [r0] - str r2, [r0, 0x4] - ldr r1, _08042F2C @ =0x80000800 - str r1, [r0, 0x8] - ldr r0, [r0, 0x8] -_08042F04: - ldr r1, _08042F38 @ =gMain - ldr r0, _08042F3C @ =0x0000043c - adds r1, r0 -_08042F0A: - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - b _08042F6E - .align 2, 0 -_08042F14: .4byte REG_BG2CNT -_08042F18: .4byte 0x00004c06 -_08042F1C: .4byte gUnknown_0820C9F8 -_08042F20: .4byte gUnknown_0820CA98 -_08042F24: .4byte 0x06004000 -_08042F28: .4byte 0x040000d4 -_08042F2C: .4byte 0x80000800 -_08042F30: .4byte gUnknown_0820F798 -_08042F34: .4byte 0x06006000 -_08042F38: .4byte gMain -_08042F3C: .4byte 0x0000043c -_08042F40: - ldr r1, _08042F74 @ =REG_BG1CNT - ldr r2, _08042F78 @ =0x00000501 - adds r0, r2, 0 - strh r0, [r1] - ldr r0, _08042F7C @ =REG_BG0HOFS - movs r4, 0 - strh r4, [r0] - adds r0, 0x2 - strh r4, [r0] - adds r0, 0x2 - strh r4, [r0] - adds r0, 0x2 - strh r4, [r0] - adds r0, 0x2 - strh r4, [r0] - adds r0, 0x2 - strh r4, [r0] - ldr r0, _08042F80 @ =CB2_EggHatch_1 - bl SetMainCallback2 - ldr r0, _08042F84 @ =gUnknown_0300481C - ldr r0, [r0] - strb r4, [r0, 0x2] -_08042F6E: - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08042F74: .4byte REG_BG1CNT -_08042F78: .4byte 0x00000501 -_08042F7C: .4byte REG_BG0HOFS -_08042F80: .4byte CB2_EggHatch_1 -_08042F84: .4byte gUnknown_0300481C - thumb_func_end CB2_EggHatch_0 - - thumb_func_start EggHatchSetMonNickname -EggHatchSetMonNickname: @ 8042F88 - push {lr} - ldr r0, _08042FA8 @ =gSpecialVar_0x8004 - ldrh r1, [r0] - movs r0, 0x64 - muls r0, r1 - ldr r1, _08042FAC @ =gPlayerParty - adds r0, r1 - ldr r2, _08042FB0 @ =gStringVar3 - movs r1, 0x2 - bl SetMonData - ldr r0, _08042FB4 @ =c2_exit_to_overworld_2_switch - bl SetMainCallback2 - pop {r0} - bx r0 - .align 2, 0 -_08042FA8: .4byte gSpecialVar_0x8004 -_08042FAC: .4byte gPlayerParty -_08042FB0: .4byte gStringVar3 -_08042FB4: .4byte c2_exit_to_overworld_2_switch - thumb_func_end EggHatchSetMonNickname - - thumb_func_start Task_EggHatchPlayBGM -Task_EggHatchPlayBGM: @ 8042FB8 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r1, _08043004 @ =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r4, r0, r1 - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0 - bne _08042FD4 - bl StopMapMusic -_08042FD4: - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0x1 - bne _08042FE4 - movs r0, 0xBC - lsls r0, 1 - bl PlayBGM -_08042FE4: - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0x3C - ble _08042FF8 - ldr r0, _08043008 @ =0x00000179 - bl PlayBGM - adds r0, r5, 0 - bl DestroyTask -_08042FF8: - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_08043004: .4byte gTasks -_08043008: .4byte 0x00000179 - thumb_func_end Task_EggHatchPlayBGM - - thumb_func_start CB2_EggHatch_1 -CB2_EggHatch_1: @ 804300C - push {r4-r6,lr} - mov r6, r10 - mov r5, r9 - mov r4, r8 - push {r4-r6} - sub sp, 0x8 - ldr r1, _08043030 @ =gUnknown_0300481C - ldr r0, [r1] - ldrb r0, [r0, 0x2] - adds r5, r1, 0 - cmp r0, 0xB - bls _08043026 - b _080432BA -_08043026: - lsls r0, 2 - ldr r1, _08043034 @ =_08043038 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_08043030: .4byte gUnknown_0300481C -_08043034: .4byte _08043038 - .align 2, 0 -_08043038: - .4byte _08043068 - .4byte _080430A0 - .4byte _080430C0 - .4byte _080430F8 - .4byte _08043124 - .4byte _08043164 - .4byte _08043172 - .4byte _08043180 - .4byte _080431B8 - .4byte _080431DA - .4byte _08043288 - .4byte _080432A8 -_08043068: - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - movs r1, 0x80 - lsls r1, 19 - movs r2, 0xBA - lsls r2, 5 - adds r0, r2, 0 - strh r0, [r1] - ldr r0, _08043098 @ =gUnknown_0300481C - ldr r1, [r0] - ldrb r0, [r1, 0x2] - adds r0, 0x1 - strb r0, [r1, 0x2] - ldr r0, _0804309C @ =Task_EggHatchPlayBGM - movs r1, 0x5 - bl CreateTask - b _080432BA - .align 2, 0 -_08043098: .4byte gUnknown_0300481C -_0804309C: .4byte Task_EggHatchPlayBGM -_080430A0: - ldr r0, _080430BC @ =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r1, r0, 24 - cmp r1, 0 - beq _080430B2 - b _080432BA -_080430B2: - ldr r0, [r5] - strb r1, [r0, 0x3] - ldr r1, [r5] - b _0804329C - .align 2, 0 -_080430BC: .4byte gPaletteFade -_080430C0: - ldr r1, [r5] - ldrb r0, [r1, 0x3] - adds r0, 0x1 - strb r0, [r1, 0x3] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1E - bhi _080430D2 - b _080432BA -_080430D2: - ldr r1, [r5] - ldrb r0, [r1, 0x2] - adds r0, 0x1 - strb r0, [r1, 0x2] - ldr r2, _080430F0 @ =gSprites - ldr r0, [r5] - ldrb r1, [r0] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, 0x1C - adds r0, r2 - ldr r1, _080430F4 @ =SpriteCB_Egg_0 - str r1, [r0] - b _080432BA - .align 2, 0 -_080430F0: .4byte gSprites -_080430F4: .4byte SpriteCB_Egg_0 -_080430F8: - ldr r2, _0804311C @ =gSprites - ldr r3, [r5] - ldrb r1, [r3] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r2, 0x1C - adds r0, r2 - ldr r1, [r0] - ldr r0, _08043120 @ =SpriteCallbackDummy - cmp r1, r0 - beq _08043112 - b _080432BA -_08043112: - ldrb r0, [r3, 0x2] - adds r0, 0x1 - strb r0, [r3, 0x2] - b _080432BA - .align 2, 0 -_0804311C: .4byte gSprites -_08043120: .4byte SpriteCallbackDummy -_08043124: - ldr r0, [r5] - ldrb r1, [r0, 0x4] - movs r0, 0x64 - muls r0, r1 - ldr r1, _08043150 @ =gPlayerParty - adds r0, r1 - ldr r1, _08043154 @ =gStringVar1 - bl GetMonNick - ldr r4, _08043158 @ =gStringVar4 - ldr r1, _0804315C @ =gOtherText_HatchedFromEgg - adds r0, r4, 0 - bl StringExpandPlaceholders - adds r0, r4, 0 - bl EggHatchPrintMessage2 - ldr r0, _08043160 @ =0x00000173 - bl PlayFanfare - ldr r1, [r5] - b _0804329C - .align 2, 0 -_08043150: .4byte gPlayerParty -_08043154: .4byte gStringVar1 -_08043158: .4byte gStringVar4 -_0804315C: .4byte gOtherText_HatchedFromEgg -_08043160: .4byte 0x00000173 -_08043164: - bl IsFanfareTaskInactive - lsls r0, 24 - cmp r0, 0 - bne _08043170 - b _080432BA -_08043170: - b _08043298 -_08043172: - bl IsFanfareTaskInactive - lsls r0, 24 - cmp r0, 0 - bne _0804317E - b _080432BA -_0804317E: - b _08043298 -_08043180: - ldr r0, [r5] - ldrb r1, [r0, 0x4] - movs r0, 0x64 - muls r0, r1 - ldr r1, _080431A8 @ =gPlayerParty - adds r0, r1 - ldr r1, _080431AC @ =gStringVar1 - bl GetMonNick - ldr r4, _080431B0 @ =gStringVar4 - ldr r1, _080431B4 @ =gOtherText_NickHatchPrompt - adds r0, r4, 0 - bl StringExpandPlaceholders - adds r0, r4, 0 - bl EggHatchPrintMessage1 - ldr r1, [r5] - b _0804329C - .align 2, 0 -_080431A8: .4byte gPlayerParty -_080431AC: .4byte gStringVar1 -_080431B0: .4byte gStringVar4 -_080431B4: .4byte gOtherText_NickHatchPrompt -_080431B8: - bl EggHatchUpdateWindowText - lsls r0, 24 - cmp r0, 0 - beq _080432BA - movs r0, 0x16 - movs r1, 0x8 - movs r2, 0x1B - movs r3, 0xD - bl MenuDrawTextWindow - movs r0, 0x16 - movs r1, 0x8 - movs r2, 0x4 - bl InitYesNoMenu - b _08043298 -_080431DA: - bl ProcessMenuInputNoWrap_ - lsls r0, 24 - lsrs r2, r0, 24 - asrs r0, 24 - movs r1, 0x2 - negs r1, r1 - cmp r0, r1 - beq _080432BA - lsls r0, r2, 24 - asrs r1, r0, 24 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - beq _08043298 - cmp r1, 0x1 - beq _08043298 - ldr r0, _08043278 @ =gUnknown_0300481C - mov r9, r0 - ldr r0, [r0] - ldrb r0, [r0, 0x4] - movs r1, 0x64 - mov r8, r1 - mov r2, r8 - muls r2, r0 - adds r0, r2, 0 - ldr r6, _0804327C @ =gPlayerParty - adds r0, r6 - ldr r1, _08043280 @ =gStringVar3 - mov r10, r1 - bl GetMonNick - mov r2, r9 - ldr r0, [r2] - ldrb r0, [r0, 0x4] - mov r1, r8 - muls r1, r0 - adds r0, r1, 0 - adds r0, r6 - movs r1, 0xB - bl GetMonData - adds r5, r0, 0 - lsls r5, 16 - lsrs r5, 16 - mov r2, r9 - ldr r0, [r2] - ldrb r0, [r0, 0x4] - mov r1, r8 - muls r1, r0 - adds r0, r1, 0 - adds r0, r6 - bl GetMonGender - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - mov r2, r9 - ldr r0, [r2] - ldrb r0, [r0, 0x4] - mov r1, r8 - muls r1, r0 - adds r0, r1, 0 - adds r0, r6 - movs r1, 0 - movs r2, 0 - bl GetMonData - str r0, [sp] - ldr r0, _08043284 @ =EggHatchSetMonNickname - str r0, [sp, 0x4] - movs r0, 0x3 - mov r1, r10 - adds r2, r5, 0 - adds r3, r4, 0 - bl DoNamingScreen - b _080432BA - .align 2, 0 -_08043278: .4byte gUnknown_0300481C -_0804327C: .4byte gPlayerParty -_08043280: .4byte gStringVar3 -_08043284: .4byte EggHatchSetMonNickname -_08043288: - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade -_08043298: - ldr r0, _080432A4 @ =gUnknown_0300481C - ldr r1, [r0] -_0804329C: - ldrb r0, [r1, 0x2] - adds r0, 0x1 - strb r0, [r1, 0x2] - b _080432BA - .align 2, 0 -_080432A4: .4byte gUnknown_0300481C -_080432A8: - ldr r0, _080432DC @ =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - cmp r0, 0 - bne _080432BA - ldr r0, _080432E0 @ =c2_exit_to_overworld_2_switch - bl SetMainCallback2 -_080432BA: - bl RunTasks - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080432DC: .4byte gPaletteFade -_080432E0: .4byte c2_exit_to_overworld_2_switch - thumb_func_end CB2_EggHatch_1 - - thumb_func_start SpriteCB_Egg_0 -SpriteCB_Egg_0: @ 80432E4 - push {r4,lr} - adds r4, r0, 0 - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - ble _08043304 - ldr r0, _08043300 @ =SpriteCB_Egg_1 - str r0, [r4, 0x1C] - movs r0, 0 - strh r0, [r4, 0x2E] - b _08043334 - .align 2, 0 -_08043300: .4byte SpriteCB_Egg_1 -_08043304: - ldrh r0, [r4, 0x30] - adds r0, 0x14 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x30] - movs r1, 0x30 - ldrsh r0, [r4, r1] - movs r1, 0x1 - bl Sin - strh r0, [r4, 0x24] - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0xF - bne _08043334 - movs r0, 0x17 - bl PlaySE - adds r0, r4, 0 - movs r1, 0x1 - bl StartSpriteAnim - bl CreateRandomEggShardSprite -_08043334: - pop {r4} - pop {r0} - bx r0 - thumb_func_end SpriteCB_Egg_0 - - thumb_func_start SpriteCB_Egg_1 -SpriteCB_Egg_1: @ 804333C - push {r4,lr} - adds r4, r0, 0 - ldrh r0, [r4, 0x32] - adds r0, 0x1 - movs r1, 0 - strh r0, [r4, 0x32] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x1E - ble _08043398 - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - ble _0804336C - ldr r0, _08043368 @ =SpriteCB_Egg_2 - str r0, [r4, 0x1C] - strh r1, [r4, 0x2E] - strh r1, [r4, 0x32] - b _08043398 - .align 2, 0 -_08043368: .4byte SpriteCB_Egg_2 -_0804336C: - ldrh r0, [r4, 0x30] - adds r0, 0x14 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x30] - movs r1, 0x30 - ldrsh r0, [r4, r1] - movs r1, 0x2 - bl Sin - strh r0, [r4, 0x24] - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0xF - bne _08043398 - movs r0, 0x17 - bl PlaySE - adds r0, r4, 0 - movs r1, 0x2 - bl StartSpriteAnim -_08043398: - pop {r4} - pop {r0} - bx r0 - thumb_func_end SpriteCB_Egg_1 - - thumb_func_start SpriteCB_Egg_2 -SpriteCB_Egg_2: @ 80433A0 - push {r4-r6,lr} - adds r4, r0, 0 - ldrh r0, [r4, 0x32] - adds r0, 0x1 - movs r6, 0 - strh r0, [r4, 0x32] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x1E - ble _0804345A - ldrh r0, [r4, 0x2E] - adds r0, 0x1 - strh r0, [r4, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x26 - ble _08043418 - ldr r0, _08043404 @ =SpriteCB_Egg_3 - str r0, [r4, 0x1C] - strh r6, [r4, 0x2E] - ldr r5, _08043408 @ =gUnknown_0300481C - ldr r0, [r5] - ldrb r1, [r0, 0x4] - movs r0, 0x64 - muls r0, r1 - ldr r1, _0804340C @ =gPlayerParty - adds r0, r1 - movs r1, 0xB - bl GetMonData - lsls r0, 16 - ldr r4, _08043410 @ =gSprites - ldr r3, [r5] - ldrb r2, [r3, 0x1] - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - adds r1, r4 - strh r6, [r1, 0x24] - ldrb r2, [r3, 0x1] - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - adds r1, r4 - ldr r2, _08043414 @ =gMonFrontPicCoords - lsrs r0, 14 - adds r0, r2 - ldrb r0, [r0, 0x1] - strh r0, [r1, 0x26] - b _0804345A - .align 2, 0 -_08043404: .4byte SpriteCB_Egg_3 -_08043408: .4byte gUnknown_0300481C -_0804340C: .4byte gPlayerParty -_08043410: .4byte gSprites -_08043414: .4byte gMonFrontPicCoords -_08043418: - ldrh r0, [r4, 0x30] - adds r0, 0x14 - movs r1, 0xFF - ands r0, r1 - strh r0, [r4, 0x30] - movs r1, 0x30 - ldrsh r0, [r4, r1] - movs r1, 0x2 - bl Sin - strh r0, [r4, 0x24] - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0xF - bne _0804344C - movs r0, 0x17 - bl PlaySE - adds r0, r4, 0 - movs r1, 0x2 - bl StartSpriteAnim - bl CreateRandomEggShardSprite - bl CreateRandomEggShardSprite -_0804344C: - movs r1, 0x2E - ldrsh r0, [r4, r1] - cmp r0, 0x1E - bne _0804345A - movs r0, 0x17 - bl PlaySE -_0804345A: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end SpriteCB_Egg_2 - - thumb_func_start SpriteCB_Egg_3 -SpriteCB_Egg_3: @ 8043460 - push {lr} - adds r1, r0, 0 - ldrh r0, [r1, 0x2E] - adds r0, 0x1 - strh r0, [r1, 0x2E] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x32 - ble _0804347A - ldr r0, _08043480 @ =SpriteCB_Egg_4 - str r0, [r1, 0x1C] - movs r0, 0 - strh r0, [r1, 0x2E] -_0804347A: - pop {r0} - bx r0 - .align 2, 0 -_08043480: .4byte SpriteCB_Egg_4 - thumb_func_end SpriteCB_Egg_3 - - thumb_func_start SpriteCB_Egg_4 -SpriteCB_Egg_4: @ 8043484 - push {r4,r5,lr} - sub sp, 0x4 - adds r5, r0, 0 - movs r1, 0x2E - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _080434A4 - movs r1, 0x1 - negs r1, r1 - ldr r0, _080434F8 @ =0x0000ffff - str r0, [sp] - adds r0, r1, 0 - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade -_080434A4: - ldrh r0, [r5, 0x2E] - cmp r0, 0x3 - bhi _080434C0 - movs r4, 0 -_080434AC: - bl CreateRandomEggShardSprite - lsls r0, r4, 16 - movs r1, 0x80 - lsls r1, 9 - adds r0, r1 - lsrs r4, r0, 16 - asrs r0, 16 - cmp r0, 0x3 - ble _080434AC -_080434C0: - ldrh r0, [r5, 0x2E] - adds r0, 0x1 - strh r0, [r5, 0x2E] - ldr r0, _080434FC @ =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - bne _080434EE - movs r0, 0x71 - bl PlaySE - adds r2, r5, 0 - adds r2, 0x3E - ldrb r0, [r2] - movs r1, 0x4 - orrs r0, r1 - strb r0, [r2] - ldr r0, _08043500 @ =SpriteCB_Egg_5 - str r0, [r5, 0x1C] - strh r4, [r5, 0x2E] -_080434EE: - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_080434F8: .4byte 0x0000ffff -_080434FC: .4byte gPaletteFade -_08043500: .4byte SpriteCB_Egg_5 - thumb_func_end SpriteCB_Egg_4 thumb_func_start SpriteCB_Egg_5 SpriteCB_Egg_5: @ 8043504 diff --git a/include/decompress.h b/include/decompress.h index 07d69301f..84c1f29c0 100644 --- a/include/decompress.h +++ b/include/decompress.h @@ -10,7 +10,7 @@ void LoadCompressedObjectPicOverrideBuffer(const struct CompressedSpriteSheet *a void LoadCompressedObjectPalette(const struct CompressedSpritePalette *a); void LoadCompressedObjectPaletteOverrideBuffer(const struct CompressedSpritePalette *a, void *buffer); void DecompressPicFromTable_2(const struct CompressedSpriteSheet *a, u8 b, u8 c, void *d, void *e, s32 f); -void HandleLoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 g); +void HandleLoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 pid); void LoadSpecialPokePic(const struct CompressedSpriteSheet *spriteSheet, u32 b, u32 c, u32 d, void *dest, s32 species, u32 g, u32 h); void Unused_LZDecompressWramIndirect(const void **src, void *dest); diff --git a/include/pokemon.h b/include/pokemon.h index 21173d503..2cc8e9ac4 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -542,7 +542,7 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u32 GetMonData(); u32 GetBoxMonData(); -void SetMonData(struct Pokemon *mon, s32 field, const u8 *data); +void SetMonData(struct Pokemon *mon, s32 field, const void *data); void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const u8 *data); void CopyMon(void *dest, void *src, size_t size); u8 GiveMonToPlayer(struct Pokemon *mon); diff --git a/include/sprite.h b/include/sprite.h index 733231eb5..5682a7c1d 100644 --- a/include/sprite.h +++ b/include/sprite.h @@ -204,14 +204,14 @@ struct Sprite /*0x3A*/ s16 data6; /*0x3C*/ s16 data7; - /*0x3E*/ u16 inUse:1; - u16 coordOffsetEnabled:1; - u16 invisible:1; - u16 flags_3:1; - u16 flags_4:1; - u16 flags_5:1; - u16 flags_6:1; - u16 flags_7:1; + /*0x3E*/ u16 inUse:1; //1 + u16 coordOffsetEnabled:1; //2 + u16 invisible:1; //4 + u16 flags_3:1; //8 + u16 flags_4:1; //0x10 + u16 flags_5:1; //0x20 + u16 flags_6:1; //0x40 + u16 flags_7:1; //0x80 /*0x3F*/ u16 hFlip:1; u16 vFlip:1; u16 animBeginning:1; diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 32fbe1547..70d206a06 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -1,7 +1,38 @@ #include "global.h" #include "pokemon.h" +#include "items.h" +#include "decompress.h" +#include "data2.h" +#include "task.h" +#include "script.h" +#include "palette.h" +#include "rom4.h" +#include "main.h" +#include "event_data.h" +#include "sound.h" +#include "text.h" +#include "text_window.h" +#include "string_util.h" +#include "strings2.h" +#include "menu.h" +#include "naming_screen.h" +#include "trig.h" -void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) { +extern u8 gStringVar1[]; +extern u8 ewram[]; +extern struct SpriteTemplate gUnknown_02024E8C; + +bool8 GetNationalPokedexFlag(u16 nationalNum, u8 caseID); +u8* GetMonNick(struct Pokemon* mon, u8* dst); +u8 sav1_map_get_name(void); +const struct CompressedSpritePalette* sub_8040990(struct Pokemon* mon); //gets pokemon palette address +void sub_8080990(void); + +void Task_EggHatch(u8 taskID); +void CB2_EggHatch_0(void); + +void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) +{ u16 species; u32 personality, pokerus; u8 i, friendship, language, gameMet, markings; @@ -50,3 +81,541 @@ void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) { *egg = *temp; } + +void AddHatchedMonToParty(u8 id) +{ + u8 isEgg; + u16 pokeNum; + u8 name[12]; + u16 ball; + u16 caughtLvl; + u8 mapNameID; + struct Pokemon* mon = &gPlayerParty[id]; + + CreatedHatchedMon(mon, &gEnemyParty[0]); + isEgg = 0; + SetMonData(mon, MON_DATA_IS_EGG, &isEgg); + + pokeNum = GetMonData(mon, MON_DATA_SPECIES); + GetSpeciesName(name, pokeNum); + SetMonData(mon, MON_DATA_NICKNAME, name); + + pokeNum = SpeciesToNationalPokedexNum(pokeNum); + GetNationalPokedexFlag(pokeNum, 2); + GetNationalPokedexFlag(pokeNum, 3); + + GetMonNick(mon, gStringVar1); + + ball = ITEM_POKE_BALL; + SetMonData(mon, MON_DATA_POKEBALL, &ball); + + caughtLvl = 0; + SetMonData(mon, MON_DATA_MET_LEVEL, &caughtLvl); + + mapNameID = sav1_map_get_name(); + SetMonData(mon, MON_DATA_MET_LOCATION, &mapNameID); + + MonRestorePP(mon); + CalculateMonStats(mon); +} + +void ScriptHatchMon(void) +{ + AddHatchedMonToParty(gSpecialVar_0x8004); +} + +__attribute__((naked)) +bool8 sub_8042ABC(void* a, u8 b) +{ + asm(".syntax unified\n\ + push {r4-r6,lr}\n\ + sub sp, 0x20\n\ + adds r5, r0, 0\n\ + lsls r4, r1, 24\n\ + lsrs r4, 24\n\ + lsls r0, r4, 2\n\ + adds r0, r4\n\ + lsls r0, 4\n\ + adds r0, r5, r0\n\ + mov r1, sp\n\ + bl GetBoxMonNick\n\ + lsls r0, r4, 3\n\ + subs r0, r4\n\ + lsls r1, r0, 3\n\ + adds r0, r5, r1\n\ + adds r0, 0xC0\n\ + ldrh r0, [r0]\n\ + cmp r0, 0\n\ + beq _08042B40\n\ + adds r0, r1, 0\n\ + adds r0, 0xA0\n\ + adds r5, r0\n\ + adds r6, r5, 0\n\ + adds r6, 0x2C\n\ + mov r0, sp\n\ + adds r1, r6, 0\n\ + bl StringCompareWithoutExtCtrlCodes\n\ + cmp r0, 0\n\ + bne _08042B08\n\ + ldr r0, _08042B30 @ =gSaveBlock2\n\ + adds r1, r5, 0\n\ + adds r1, 0x24\n\ + bl StringCompareWithoutExtCtrlCodes\n\ + cmp r0, 0\n\ + beq _08042B40\n\ +_08042B08:\n\ + ldr r0, _08042B34 @ =gStringVar1\n\ + mov r1, sp\n\ + bl StringCopy\n\ + ldr r4, _08042B38 @ =gStringVar2\n\ + adds r1, r5, 0\n\ + adds r1, 0x24\n\ + adds r0, r4, 0\n\ + bl StringCopy\n\ + ldr r0, _08042B3C @ =gStringVar3\n\ + adds r1, r6, 0\n\ + bl StringCopy\n\ + adds r0, r4, 0\n\ + bl SanitizeNameString\n\ + movs r0, 0x1\n\ + b _08042B42\n\ + .align 2, 0\n\ +_08042B30: .4byte gSaveBlock2\n\ +_08042B34: .4byte gStringVar1\n\ +_08042B38: .4byte gStringVar2\n\ +_08042B3C: .4byte gStringVar3\n\ +_08042B40:\n\ + movs r0, 0\n\ +_08042B42:\n\ + add sp, 0x20\n\ + pop {r4-r6}\n\ + pop {r1}\n\ + bx r1\n\ + .syntax divided"); +} + +bool8 sub_8042B4C(void) +{ + return sub_8042ABC(&gSaveBlock1.daycareData, gSpecialVar_0x8004); +} + +u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID) +{ + u8 r5 = 0; + u8 spriteID = 0; + struct Pokemon* mon = NULL; + + if (a0 == 0) + { + mon = &gPlayerParty[pokeID]; + r5 = 1; + } + if (a0 == 1) + { + mon = &gPlayerParty[pokeID]; + r5 = 3; + } + switch (switchID) + { + case 0: + { + u16 species = GetMonData(mon, MON_DATA_SPECIES); + u32 pid = GetMonData(mon, MON_DATA_PERSONALITY); + HandleLoadSpecialPokePic(&gMonFrontPicTable[species], gMonFrontPicCoords[species].coords, gMonFrontPicCoords[species].y_offset,(u32)(&ewram[0]), gUnknown_081FAF4C[2 * a0 + 1], species, pid); + LoadCompressedObjectPalette(sub_8040990(mon)); + } + break; + case 1: + GetMonSpriteTemplate_803C56C(sub_8040990(mon)->tag, r5); + spriteID = CreateSprite(&gUnknown_02024E8C, 120, 70, 6); + gSprites[spriteID].invisible = 1; + gSprites[spriteID].callback = SpriteCallbackDummy; + break; + } + return spriteID; +} + +void VBlankCB_EggHatch(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void EggHatch(void) +{ + ScriptContext2_Enable(); + CreateTask(Task_EggHatch, 10); + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); +} + +void Task_EggHatch(u8 taskID) +{ + if (!gPaletteFade.active) + { + SetMainCallback2(CB2_EggHatch_0); + gFieldCallback = sub_8080990; + DestroyTask(taskID); + } +} + +void CB2_EggHatch_1(void); + +struct Struct_2018000 +{ + u8 eggSpriteID; + u8 pokeSpriteID; + u8 field_2; + u8 field_3; + u8 eggPartyID; + u8 field_5; + u8 field_6; + u8 field_7; + struct Window window; + u8 field_38; + u8 field_39; + u8 field_3A; +}; + +extern struct Struct_2018000* gUnknown_0300481C; +extern const u32 gUnknown_08D00000[]; +extern const u32 gUnknown_08D00524[]; +extern const u32 gUnknown_0820CA98[]; +extern const u32 gUnknown_0820F798[]; +extern const u16 gUnknown_08D004E0[]; //palette + +extern const u16 gUnknown_0820C9F8[]; //palette + +extern const struct SpriteSheet gUnknown_0820A3B0; +extern const struct SpriteSheet gUnknown_0820A3B8; +extern const struct SpritePalette gUnknown_0820A3C0; + +extern const struct SpriteTemplate gSpriteTemplate_820A3C8; + +void CB2_EggHatch_0(void) +{ + switch (gMain.state) + { + case 0: + REG_DISPCNT = 0; + gUnknown_0300481C = (struct Struct_2018000*)(&ewram[0x18000]); + gUnknown_0300481C->eggPartyID = gSpecialVar_0x8004; + gUnknown_0300481C->field_3A = 0; + ResetTasks(); + ResetSpriteData(); + FreeAllSpritePalettes(); + SetVBlankCallback(VBlankCB_EggHatch); + gMain.state++; + gSpecialVar_0x8005 = GetCurrentMapMusic(); + break; + case 1: + SetUpWindowConfig(&gWindowConfig_81E6F84); + InitWindowFromConfig(&gUnknown_0300481C->window, &gWindowConfig_81E6F84); + gUnknown_0300481C->field_38 = SetTextWindowBaseTileNum(20); + LoadTextWindowGraphics(&gUnknown_0300481C->window); + gMain.state++; + break; + case 2: + LZDecompressVram(&gUnknown_08D00000, (void*)(VRAM)); + CpuSet(&gUnknown_08D00524, &ewram[0], 0x800); + DmaCopy16(3, &ewram[0], (void*)(VRAM + 0x2800), 0x500); + LoadCompressedPalette(&gUnknown_08D004E0, 0, 0x20); + gMain.state++; + break; + case 3: + LoadSpriteSheet(&gUnknown_0820A3B0); + LoadSpriteSheet(&gUnknown_0820A3B8); + LoadSpritePalette(&gUnknown_0820A3C0); + gMain.state++; + break; + case 4: + gUnknown_0300481C->eggSpriteID = CreateSprite(&gSpriteTemplate_820A3C8, 0x78, 0x4B, 5); + AddHatchedMonToParty(gUnknown_0300481C->eggPartyID); + gMain.state++; + break; + case 5: + EggHatchCreateMonSprite(0, 0, gUnknown_0300481C->eggPartyID); + gMain.state++; + break; + case 6: + gUnknown_0300481C->pokeSpriteID = EggHatchCreateMonSprite(0, 1, gUnknown_0300481C->eggPartyID); + gMain.state++; + break; + case 7: + { + u32 offsetRead, offsetWrite; + u32 offsetRead2, offsetWrite2; + u32 size; + + REG_BG2CNT = 0x4C06; + LoadPalette(&gUnknown_0820C9F8, 0x10, 0xA0); + + offsetRead = (u32)(&gUnknown_0820CA98); + offsetWrite = (VRAM + 0x4000); + size = 0x1300; + while (TRUE) + { + DmaCopy16(3, offsetRead, (void *) (offsetWrite), 0x1000); + offsetRead += 0x1000; + offsetWrite += 0x1000; + size -= 0x1000; + if (size <= 0x1000) + { + DmaCopy16(3, offsetRead, (void *) (offsetWrite), size); + break; + } + } + + offsetRead2 = (u32)(&gUnknown_0820F798); + offsetWrite2 = (u32)(VRAM + 0x6000); + DmaCopy16(3, offsetRead2, (void*)(offsetWrite2), 0x1000); + gMain.state++; + } + break; + case 8: + REG_BG1CNT = 0x501; + + REG_BG0HOFS = 0; + REG_BG0VOFS = 0; + + REG_BG1HOFS = 0; + REG_BG1VOFS = 0; + + REG_BG2HOFS = 0; + REG_BG2VOFS = 0; + + SetMainCallback2(CB2_EggHatch_1); + gUnknown_0300481C->field_2 = 0; + break; + } +} + +void EggHatchSetMonNickname(void) +{ + SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar3); + SetMainCallback2(c2_exit_to_overworld_2_switch); +} + +void Task_EggHatchPlayBGM(u8 taskID) +{ + if (gTasks[taskID].data[0] == 0) + StopMapMusic(); + if (gTasks[taskID].data[0] == 1) + PlayBGM(376); + if (gTasks[taskID].data[0] > 60) + { + PlayBGM(377); + DestroyTask(taskID); + //return; task is destroyed, yet you increment the value? + } + gTasks[taskID].data[0]++; +} + +void SpriteCB_Egg_0(struct Sprite* sprite); +void SpriteCB_Egg_1(struct Sprite* sprite); +void SpriteCB_Egg_2(struct Sprite* sprite); +void SpriteCB_Egg_3(struct Sprite* sprite); +void SpriteCB_Egg_4(struct Sprite* sprite); +void SpriteCB_Egg_5(struct Sprite* sprite); + +void EggHatchPrintMessage2(u8* src); +void EggHatchPrintMessage1(u8* src); +bool8 EggHatchUpdateWindowText(void); +void CreateRandomEggShardSprite(void); + +void CB2_EggHatch_1(void) +{ + switch (gUnknown_0300481C->field_2) + { + case 0: + BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); + REG_DISPCNT = 0x1740; + gUnknown_0300481C->field_2++; + CreateTask(Task_EggHatchPlayBGM, 5); + break; + case 1: + if (!gPaletteFade.active) + { + gUnknown_0300481C->field_3 = 0; + gUnknown_0300481C->field_2++; + } + break; + case 2: + if (++gUnknown_0300481C->field_3 > 30) + { + gUnknown_0300481C->field_2++; + gSprites[gUnknown_0300481C->eggSpriteID].callback = SpriteCB_Egg_0; + } + break; + case 3: + if (gSprites[gUnknown_0300481C->eggSpriteID].callback == SpriteCallbackDummy) + gUnknown_0300481C->field_2++; + break; + case 4: + GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar1); + StringExpandPlaceholders(gStringVar4, gOtherText_HatchedFromEgg); + EggHatchPrintMessage2(gStringVar4); + PlayFanfare(371); + gUnknown_0300481C->field_2++; + break; + case 5: + if (IsFanfareTaskInactive()) + gUnknown_0300481C->field_2++; + break; + case 6: + if (IsFanfareTaskInactive()) + gUnknown_0300481C->field_2++; + break; + case 7: + GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar1); + StringExpandPlaceholders(gStringVar4, gOtherText_NickHatchPrompt); + EggHatchPrintMessage1(gStringVar4); + gUnknown_0300481C->field_2++; + break; + case 8: + if (EggHatchUpdateWindowText()) + { + MenuDrawTextWindow(22, 8, 27, 13); + InitYesNoMenu(22, 8, 4); + gUnknown_0300481C->field_2++; + } + break; + case 9: + { + s8 menuInput; + if ((menuInput = ProcessMenuInputNoWrap_()) != -2) + { + if (menuInput != -1 && menuInput != 1) + { + u16 species; + u8 gender; + u32 personality; + + GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar3); + species = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_SPECIES); + gender = GetMonGender(&gPlayerParty[gUnknown_0300481C->eggPartyID]); + personality = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_PERSONALITY, 0); + DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname); + } + else + gUnknown_0300481C->field_2++; + } + } + break; + case 10: + BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); + gUnknown_0300481C->field_2++; + break; + case 11: + if (!gPaletteFade.active) + SetMainCallback2(c2_exit_to_overworld_2_switch); + break; + } + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); +} + +void SpriteCB_Egg_0(struct Sprite* sprite) +{ + if (++sprite->data0 > 20) + { + sprite->callback = SpriteCB_Egg_1; + sprite->data0 = 0; + } + else + { + sprite->data1 = (sprite->data1 + 20) & 0xFF; + sprite->pos2.x = Sin(sprite->data1, 1); + if (sprite->data0 == 15) + { + PlaySE(23); + StartSpriteAnim(sprite, 1); + CreateRandomEggShardSprite(); + } + } +} + +void SpriteCB_Egg_1(struct Sprite* sprite) +{ + if (++sprite->data2 > 30) + { + if (++sprite->data0 > 20) + { + sprite->callback = SpriteCB_Egg_2; + sprite->data0 = 0; + sprite->data2 = 0; + } + else + { + sprite->data1 = (sprite->data1 + 20) & 0xFF; + sprite->pos2.x = Sin(sprite->data1, 2); + if (sprite->data0 == 15) + { + PlaySE(23); + StartSpriteAnim(sprite, 2); + } + } + } +} + +void SpriteCB_Egg_2(struct Sprite* sprite) +{ + if (++sprite->data2 > 30) + { + if (++sprite->data0 > 38) + { + u16 species; + + sprite->callback = SpriteCB_Egg_3; + sprite->data0 = 0; + species = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_SPECIES); + gSprites[gUnknown_0300481C->pokeSpriteID].pos2.x = 0; + gSprites[gUnknown_0300481C->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset; + } + else + { + sprite->data1 = (sprite->data1 + 20) & 0xFF; + sprite->pos2.x = Sin(sprite->data1, 2); + if (sprite->data0 == 15) + { + PlaySE(23); + StartSpriteAnim(sprite, 2); + CreateRandomEggShardSprite(); + CreateRandomEggShardSprite(); + } + if (sprite->data0 == 30) + PlaySE(23); + } + } +} + +void SpriteCB_Egg_3(struct Sprite* sprite) +{ + if (++sprite->data0 > 50) + { + sprite->callback = SpriteCB_Egg_4; + sprite->data0 = 0; + } +} + +void SpriteCB_Egg_4(struct Sprite* sprite) +{ + s16 i; + if (sprite->data0 == 0) + BeginNormalPaletteFade(-1, -1, 0, 0x10, 0xFFFF); + if (sprite->data0 < 4u) + { + for (i = 0; i <= 3; i++) + CreateRandomEggShardSprite(); + } + sprite->data0++; + if (!gPaletteFade.active) + { + PlaySE(113); + sprite->invisible = 1; + sprite->callback = SpriteCB_Egg_5; + sprite->data0 = 0; + } +} From f246b05d996dba1249393e9219f0c32337feac02 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 1 Aug 2017 12:47:03 +0200 Subject: [PATCH 2/4] finish up egg hatch, make it compile --- asm/egg_hatch.s | 300 ---------------------------------------------- include/pokemon.h | 2 +- src/egg_hatch.c | 263 +++++++++++++++++++++++++--------------- sym_common.txt | 2 +- 4 files changed, 168 insertions(+), 399 deletions(-) diff --git a/asm/egg_hatch.s b/asm/egg_hatch.s index 51e688998..1e7bffa77 100644 --- a/asm/egg_hatch.s +++ b/asm/egg_hatch.s @@ -8,304 +8,4 @@ - thumb_func_start SpriteCB_Egg_5 -SpriteCB_Egg_5: @ 8043504 - push {r4,r5,lr} - sub sp, 0x4 - adds r5, r0, 0 - movs r1, 0x2E - ldrsh r0, [r5, r1] - cmp r0, 0 - bne _08043540 - ldr r4, _08043594 @ =gSprites - ldr r3, _08043598 @ =gUnknown_0300481C - ldr r0, [r3] - ldrb r1, [r0, 0x1] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r4 - adds r0, 0x3E - ldrb r2, [r0] - movs r1, 0x5 - negs r1, r1 - ands r1, r2 - strb r1, [r0] - ldr r0, [r3] - ldrb r1, [r0, 0x1] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r4 - movs r1, 0x1 - bl StartSpriteAffineAnim -_08043540: - movs r2, 0x2E - ldrsh r0, [r5, r2] - cmp r0, 0x8 - bne _0804355A - movs r1, 0x1 - negs r1, r1 - ldr r0, _0804359C @ =0x0000ffff - str r0, [sp] - adds r0, r1, 0 - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade -_0804355A: - movs r1, 0x2E - ldrsh r0, [r5, r1] - cmp r0, 0x9 - bgt _08043578 - ldr r2, _08043594 @ =gSprites - ldr r0, _08043598 @ =gUnknown_0300481C - ldr r0, [r0] - ldrb r1, [r0, 0x1] - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - ldrh r1, [r0, 0x22] - subs r1, 0x1 - strh r1, [r0, 0x22] -_08043578: - ldrh r1, [r5, 0x2E] - movs r2, 0x2E - ldrsh r0, [r5, r2] - cmp r0, 0x28 - ble _08043586 - ldr r0, _080435A0 @ =SpriteCallbackDummy - str r0, [r5, 0x1C] -_08043586: - adds r0, r1, 0x1 - strh r0, [r5, 0x2E] - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_08043594: .4byte gSprites -_08043598: .4byte gUnknown_0300481C -_0804359C: .4byte 0x0000ffff -_080435A0: .4byte SpriteCallbackDummy - thumb_func_end SpriteCB_Egg_5 - - thumb_func_start SpriteCB_EggShard -SpriteCB_EggShard: @ 80435A4 - push {r4,lr} - adds r2, r0, 0 - ldrh r0, [r2, 0x30] - ldrh r1, [r2, 0x36] - adds r0, r1 - strh r0, [r2, 0x36] - ldrh r1, [r2, 0x32] - ldrh r3, [r2, 0x38] - adds r0, r1, r3 - strh r0, [r2, 0x38] - movs r4, 0x36 - ldrsh r0, [r2, r4] - cmp r0, 0 - bge _080435C2 - adds r0, 0xFF -_080435C2: - asrs r0, 8 - strh r0, [r2, 0x24] - movs r3, 0x38 - ldrsh r0, [r2, r3] - cmp r0, 0 - bge _080435D0 - adds r0, 0xFF -_080435D0: - asrs r0, 8 - strh r0, [r2, 0x26] - ldrh r0, [r2, 0x34] - adds r3, r1, r0 - strh r3, [r2, 0x32] - movs r4, 0x22 - ldrsh r1, [r2, r4] - movs r4, 0x26 - ldrsh r0, [r2, r4] - adds r0, r1, r0 - adds r1, 0x14 - cmp r0, r1 - ble _080435F6 - lsls r0, r3, 16 - cmp r0, 0 - ble _080435F6 - adds r0, r2, 0 - bl DestroySprite -_080435F6: - pop {r4} - pop {r0} - bx r0 - thumb_func_end SpriteCB_EggShard - - thumb_func_start CreateRandomEggShardSprite -CreateRandomEggShardSprite: @ 80435FC - push {r4-r6,lr} - sub sp, 0x8 - ldr r3, _0804364C @ =gEggShardVelocities - ldr r0, _08043650 @ =gUnknown_0300481C - ldr r4, [r0] - adds r4, 0x3A - ldrb r2, [r4] - lsls r0, r2, 2 - adds r1, r0, r3 - ldrh r6, [r1] - adds r3, 0x2 - adds r0, r3 - ldrh r5, [r0] - adds r2, 0x1 - strb r2, [r4] - bl Random - lsls r0, 16 - movs r1, 0xC0 - lsls r1, 10 - ands r1, r0 - lsls r6, 16 - asrs r6, 16 - lsls r5, 16 - asrs r5, 16 - movs r0, 0x64 - str r0, [sp] - lsrs r1, 16 - str r1, [sp, 0x4] - movs r0, 0x78 - movs r1, 0x3C - adds r2, r6, 0 - adds r3, r5, 0 - bl CreateEggShardSprite - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804364C: .4byte gEggShardVelocities -_08043650: .4byte gUnknown_0300481C - thumb_func_end CreateRandomEggShardSprite - - thumb_func_start CreateEggShardSprite -CreateEggShardSprite: @ 8043654 - push {r4-r6,lr} - mov r6, r10 - mov r5, r9 - mov r4, r8 - push {r4-r6} - adds r4, r0, 0 - adds r5, r1, 0 - adds r6, r2, 0 - mov r8, r3 - ldr r0, [sp, 0x1C] - mov r9, r0 - ldr r1, [sp, 0x20] - mov r10, r1 - lsls r4, 24 - lsrs r4, 24 - lsls r5, 24 - lsrs r5, 24 - lsls r6, 16 - lsrs r6, 16 - mov r0, r8 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - mov r1, r9 - lsls r1, 16 - lsrs r1, 16 - mov r9, r1 - mov r0, r10 - lsls r0, 24 - lsrs r0, 24 - mov r10, r0 - ldr r0, _080436CC @ =gSpriteTemplate_820A418 - adds r1, r4, 0 - adds r2, r5, 0 - movs r3, 0x4 - bl CreateSprite - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - ldr r2, _080436D0 @ =gSprites - lsls r0, r1, 4 - adds r0, r1 - lsls r0, 2 - adds r0, r2 - strh r6, [r0, 0x30] - mov r1, r8 - strh r1, [r0, 0x32] - mov r1, r9 - strh r1, [r0, 0x34] - mov r1, r10 - bl StartSpriteAnim - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_080436CC: .4byte gSpriteTemplate_820A418 -_080436D0: .4byte gSprites - thumb_func_end CreateEggShardSprite - - thumb_func_start EggHatchPrintMessage1 -EggHatchPrintMessage1: @ 80436D4 - push {lr} - sub sp, 0x4 - adds r1, r0, 0 - ldr r0, _080436F8 @ =gUnknown_0300481C - ldr r2, [r0] - adds r0, r2, 0 - adds r0, 0x8 - adds r2, 0x38 - ldrb r2, [r2] - movs r3, 0xF - str r3, [sp] - movs r3, 0x3 - bl sub_8002EB0 - add sp, 0x4 - pop {r0} - bx r0 - .align 2, 0 -_080436F8: .4byte gUnknown_0300481C - thumb_func_end EggHatchPrintMessage1 - - thumb_func_start EggHatchPrintMessage2 -EggHatchPrintMessage2: @ 80436FC - push {lr} - sub sp, 0x4 - adds r1, r0, 0 - ldr r0, _08043720 @ =gUnknown_0300481C - ldr r2, [r0] - adds r0, r2, 0 - adds r0, 0x8 - adds r2, 0x38 - ldrb r2, [r2] - movs r3, 0xF - str r3, [sp] - movs r3, 0x3 - bl sub_8003460 - add sp, 0x4 - pop {r0} - bx r0 - .align 2, 0 -_08043720: .4byte gUnknown_0300481C - thumb_func_end EggHatchPrintMessage2 - - thumb_func_start EggHatchUpdateWindowText -EggHatchUpdateWindowText: @ 8043724 - push {lr} - ldr r0, _08043738 @ =gUnknown_0300481C - ldr r0, [r0] - adds r0, 0x8 - bl sub_80035AC - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - .align 2, 0 -_08043738: .4byte gUnknown_0300481C - thumb_func_end EggHatchUpdateWindowText - .align 2, 0 @ Don't pad with nop. diff --git a/include/pokemon.h b/include/pokemon.h index 2cc8e9ac4..21173d503 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -542,7 +542,7 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u32 GetMonData(); u32 GetBoxMonData(); -void SetMonData(struct Pokemon *mon, s32 field, const void *data); +void SetMonData(struct Pokemon *mon, s32 field, const u8 *data); void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const u8 *data); void CopyMon(void *dest, void *src, size_t size); u8 GiveMonToPlayer(struct Pokemon *mon); diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 70d206a06..f518fdb84 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -17,21 +17,61 @@ #include "menu.h" #include "naming_screen.h" #include "trig.h" +#include "rng.h" -extern u8 gStringVar1[]; extern u8 ewram[]; extern struct SpriteTemplate gUnknown_02024E8C; +struct EggHatchData +{ + u8 eggSpriteID; + u8 pokeSpriteID; + u8 CB2_state; + u8 CB2_PalCounter; + u8 eggPartyID; + struct Window window; + u8 tileDataStartOffset; + u8 unused_39; + u8 eggShardVelocityID; +}; + +extern struct EggHatchData* sEggHatchData; + +extern const u32 gUnknown_08D00000[]; +extern const u32 gUnknown_08D00524[]; +extern const u32 gUnknown_0820CA98[]; +extern const u32 gUnknown_0820F798[]; +extern const u16 gUnknown_08D004E0[]; //palette +extern const u16 gUnknown_0820C9F8[]; //palette +extern const struct SpriteSheet gUnknown_0820A3B0; +extern const struct SpriteSheet gUnknown_0820A3B8; +extern const struct SpritePalette gUnknown_0820A3C0; +extern const struct SpriteTemplate gSpriteTemplate_820A3C8; +extern const struct SpriteTemplate gSpriteTemplate_820A418; +extern const s16 gEggShardVelocities[][2]; + bool8 GetNationalPokedexFlag(u16 nationalNum, u8 caseID); u8* GetMonNick(struct Pokemon* mon, u8* dst); u8 sav1_map_get_name(void); const struct CompressedSpritePalette* sub_8040990(struct Pokemon* mon); //gets pokemon palette address void sub_8080990(void); -void Task_EggHatch(u8 taskID); -void CB2_EggHatch_0(void); +static void Task_EggHatch(u8 taskID); +static void CB2_EggHatch_0(void); +static void CB2_EggHatch_1(void); +static void SpriteCB_Egg_0(struct Sprite* sprite); +static void SpriteCB_Egg_1(struct Sprite* sprite); +static void SpriteCB_Egg_2(struct Sprite* sprite); +static void SpriteCB_Egg_3(struct Sprite* sprite); +static void SpriteCB_Egg_4(struct Sprite* sprite); +static void SpriteCB_Egg_5(struct Sprite* sprite); +static void EggHatchPrintMessage2(u8* src); +static void EggHatchPrintMessage1(u8* src); +static bool8 EggHatchUpdateWindowText(void); +static void CreateRandomEggShardSprite(void); +static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex); -void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) +static void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) { u16 species; u32 personality, pokerus; @@ -82,7 +122,7 @@ void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) *egg = *temp; } -void AddHatchedMonToParty(u8 id) +static void AddHatchedMonToParty(u8 id) { u8 isEgg; u16 pokeNum; @@ -107,10 +147,10 @@ void AddHatchedMonToParty(u8 id) GetMonNick(mon, gStringVar1); ball = ITEM_POKE_BALL; - SetMonData(mon, MON_DATA_POKEBALL, &ball); + SetMonData(mon, MON_DATA_POKEBALL, (const u8*) &ball); caughtLvl = 0; - SetMonData(mon, MON_DATA_MET_LEVEL, &caughtLvl); + SetMonData(mon, MON_DATA_MET_LEVEL, (const u8*) &caughtLvl); mapNameID = sav1_map_get_name(); SetMonData(mon, MON_DATA_MET_LOCATION, &mapNameID); @@ -124,8 +164,15 @@ void ScriptHatchMon(void) AddHatchedMonToParty(gSpecialVar_0x8004); } +#ifdef NONMATCHING +static bool8 sub_8042ABC(void* a, u8 b) +{ + +} + +#else __attribute__((naked)) -bool8 sub_8042ABC(void* a, u8 b) +static bool8 sub_8042ABC(void* a, u8 b) { asm(".syntax unified\n\ push {r4-r6,lr}\n\ @@ -194,12 +241,14 @@ _08042B42:\n\ .syntax divided"); } +#endif // NONMATCHING + bool8 sub_8042B4C(void) { return sub_8042ABC(&gSaveBlock1.daycareData, gSpecialVar_0x8004); } -u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID) +static u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID) { u8 r5 = 0; u8 spriteID = 0; @@ -235,7 +284,7 @@ u8 EggHatchCreateMonSprite(u8 a0, u8 switchID, u8 pokeID) return spriteID; } -void VBlankCB_EggHatch(void) +static void VBlankCB_EggHatch(void) { LoadOam(); ProcessSpriteCopyRequests(); @@ -249,7 +298,7 @@ void EggHatch(void) BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); } -void Task_EggHatch(u8 taskID) +static void Task_EggHatch(u8 taskID) { if (!gPaletteFade.active) { @@ -259,48 +308,15 @@ void Task_EggHatch(u8 taskID) } } -void CB2_EggHatch_1(void); - -struct Struct_2018000 -{ - u8 eggSpriteID; - u8 pokeSpriteID; - u8 field_2; - u8 field_3; - u8 eggPartyID; - u8 field_5; - u8 field_6; - u8 field_7; - struct Window window; - u8 field_38; - u8 field_39; - u8 field_3A; -}; - -extern struct Struct_2018000* gUnknown_0300481C; -extern const u32 gUnknown_08D00000[]; -extern const u32 gUnknown_08D00524[]; -extern const u32 gUnknown_0820CA98[]; -extern const u32 gUnknown_0820F798[]; -extern const u16 gUnknown_08D004E0[]; //palette - -extern const u16 gUnknown_0820C9F8[]; //palette - -extern const struct SpriteSheet gUnknown_0820A3B0; -extern const struct SpriteSheet gUnknown_0820A3B8; -extern const struct SpritePalette gUnknown_0820A3C0; - -extern const struct SpriteTemplate gSpriteTemplate_820A3C8; - void CB2_EggHatch_0(void) { switch (gMain.state) { case 0: REG_DISPCNT = 0; - gUnknown_0300481C = (struct Struct_2018000*)(&ewram[0x18000]); - gUnknown_0300481C->eggPartyID = gSpecialVar_0x8004; - gUnknown_0300481C->field_3A = 0; + sEggHatchData = (struct EggHatchData*)(&ewram[0x18000]); + sEggHatchData->eggPartyID = gSpecialVar_0x8004; + sEggHatchData->eggShardVelocityID = 0; ResetTasks(); ResetSpriteData(); FreeAllSpritePalettes(); @@ -310,9 +326,9 @@ void CB2_EggHatch_0(void) break; case 1: SetUpWindowConfig(&gWindowConfig_81E6F84); - InitWindowFromConfig(&gUnknown_0300481C->window, &gWindowConfig_81E6F84); - gUnknown_0300481C->field_38 = SetTextWindowBaseTileNum(20); - LoadTextWindowGraphics(&gUnknown_0300481C->window); + InitWindowFromConfig(&sEggHatchData->window, &gWindowConfig_81E6F84); + sEggHatchData->tileDataStartOffset = SetTextWindowBaseTileNum(20); + LoadTextWindowGraphics(&sEggHatchData->window); gMain.state++; break; case 2: @@ -329,16 +345,16 @@ void CB2_EggHatch_0(void) gMain.state++; break; case 4: - gUnknown_0300481C->eggSpriteID = CreateSprite(&gSpriteTemplate_820A3C8, 0x78, 0x4B, 5); - AddHatchedMonToParty(gUnknown_0300481C->eggPartyID); + sEggHatchData->eggSpriteID = CreateSprite(&gSpriteTemplate_820A3C8, 0x78, 0x4B, 5); + AddHatchedMonToParty(sEggHatchData->eggPartyID); gMain.state++; break; case 5: - EggHatchCreateMonSprite(0, 0, gUnknown_0300481C->eggPartyID); + EggHatchCreateMonSprite(0, 0, sEggHatchData->eggPartyID); gMain.state++; break; case 6: - gUnknown_0300481C->pokeSpriteID = EggHatchCreateMonSprite(0, 1, gUnknown_0300481C->eggPartyID); + sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, sEggHatchData->eggPartyID); gMain.state++; break; case 7: @@ -385,7 +401,7 @@ void CB2_EggHatch_0(void) REG_BG2VOFS = 0; SetMainCallback2(CB2_EggHatch_1); - gUnknown_0300481C->field_2 = 0; + sEggHatchData->CB2_state = 0; break; } } @@ -411,73 +427,61 @@ void Task_EggHatchPlayBGM(u8 taskID) gTasks[taskID].data[0]++; } -void SpriteCB_Egg_0(struct Sprite* sprite); -void SpriteCB_Egg_1(struct Sprite* sprite); -void SpriteCB_Egg_2(struct Sprite* sprite); -void SpriteCB_Egg_3(struct Sprite* sprite); -void SpriteCB_Egg_4(struct Sprite* sprite); -void SpriteCB_Egg_5(struct Sprite* sprite); - -void EggHatchPrintMessage2(u8* src); -void EggHatchPrintMessage1(u8* src); -bool8 EggHatchUpdateWindowText(void); -void CreateRandomEggShardSprite(void); - void CB2_EggHatch_1(void) { - switch (gUnknown_0300481C->field_2) + switch (sEggHatchData->CB2_state) { case 0: BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); REG_DISPCNT = 0x1740; - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; CreateTask(Task_EggHatchPlayBGM, 5); break; case 1: if (!gPaletteFade.active) { - gUnknown_0300481C->field_3 = 0; - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_PalCounter = 0; + sEggHatchData->CB2_state++; } break; case 2: - if (++gUnknown_0300481C->field_3 > 30) + if (++sEggHatchData->CB2_PalCounter > 30) { - gUnknown_0300481C->field_2++; - gSprites[gUnknown_0300481C->eggSpriteID].callback = SpriteCB_Egg_0; + sEggHatchData->CB2_state++; + gSprites[sEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0; } break; case 3: - if (gSprites[gUnknown_0300481C->eggSpriteID].callback == SpriteCallbackDummy) - gUnknown_0300481C->field_2++; + if (gSprites[sEggHatchData->eggSpriteID].callback == SpriteCallbackDummy) + sEggHatchData->CB2_state++; break; case 4: - GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar1); + GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1); StringExpandPlaceholders(gStringVar4, gOtherText_HatchedFromEgg); EggHatchPrintMessage2(gStringVar4); PlayFanfare(371); - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; break; case 5: if (IsFanfareTaskInactive()) - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; break; case 6: if (IsFanfareTaskInactive()) - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; break; case 7: - GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar1); + GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1); StringExpandPlaceholders(gStringVar4, gOtherText_NickHatchPrompt); EggHatchPrintMessage1(gStringVar4); - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; break; case 8: if (EggHatchUpdateWindowText()) { MenuDrawTextWindow(22, 8, 27, 13); InitYesNoMenu(22, 8, 4); - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; } break; case 9: @@ -491,20 +495,20 @@ void CB2_EggHatch_1(void) u8 gender; u32 personality; - GetMonNick(&gPlayerParty[gUnknown_0300481C->eggPartyID], gStringVar3); - species = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_SPECIES); - gender = GetMonGender(&gPlayerParty[gUnknown_0300481C->eggPartyID]); - personality = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_PERSONALITY, 0); + GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar3); + species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES); + gender = GetMonGender(&gPlayerParty[sEggHatchData->eggPartyID]); + personality = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0); DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname); } else - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; } } break; case 10: BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); - gUnknown_0300481C->field_2++; + sEggHatchData->CB2_state++; break; case 11: if (!gPaletteFade.active) @@ -517,7 +521,7 @@ void CB2_EggHatch_1(void) UpdatePaletteFade(); } -void SpriteCB_Egg_0(struct Sprite* sprite) +static void SpriteCB_Egg_0(struct Sprite* sprite) { if (++sprite->data0 > 20) { @@ -537,7 +541,7 @@ void SpriteCB_Egg_0(struct Sprite* sprite) } } -void SpriteCB_Egg_1(struct Sprite* sprite) +static void SpriteCB_Egg_1(struct Sprite* sprite) { if (++sprite->data2 > 30) { @@ -560,7 +564,7 @@ void SpriteCB_Egg_1(struct Sprite* sprite) } } -void SpriteCB_Egg_2(struct Sprite* sprite) +static void SpriteCB_Egg_2(struct Sprite* sprite) { if (++sprite->data2 > 30) { @@ -570,9 +574,9 @@ void SpriteCB_Egg_2(struct Sprite* sprite) sprite->callback = SpriteCB_Egg_3; sprite->data0 = 0; - species = GetMonData(&gPlayerParty[gUnknown_0300481C->eggPartyID], MON_DATA_SPECIES); - gSprites[gUnknown_0300481C->pokeSpriteID].pos2.x = 0; - gSprites[gUnknown_0300481C->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset; + species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES); + gSprites[sEggHatchData->pokeSpriteID].pos2.x = 0; + gSprites[sEggHatchData->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset; } else { @@ -591,7 +595,7 @@ void SpriteCB_Egg_2(struct Sprite* sprite) } } -void SpriteCB_Egg_3(struct Sprite* sprite) +static void SpriteCB_Egg_3(struct Sprite* sprite) { if (++sprite->data0 > 50) { @@ -600,7 +604,7 @@ void SpriteCB_Egg_3(struct Sprite* sprite) } } -void SpriteCB_Egg_4(struct Sprite* sprite) +static void SpriteCB_Egg_4(struct Sprite* sprite) { s16 i; if (sprite->data0 == 0) @@ -619,3 +623,68 @@ void SpriteCB_Egg_4(struct Sprite* sprite) sprite->data0 = 0; } } + +static void SpriteCB_Egg_5(struct Sprite* sprite) +{ + if (sprite->data0 == 0) + { + gSprites[sEggHatchData->pokeSpriteID].invisible = 0; + StartSpriteAffineAnim(&gSprites[sEggHatchData->pokeSpriteID], 1); + } + if (sprite->data0 == 8) + BeginNormalPaletteFade(-1, -1, 0x10, 0, 0xFFFF); + if (sprite->data0 <= 9) + gSprites[sEggHatchData->pokeSpriteID].pos1.y -= 1; + if (sprite->data0 > 40) + sprite->callback = SpriteCallbackDummy; + sprite->data0++; +} + +void SpriteCB_EggShard(struct Sprite* sprite) +{ + sprite->data4 += sprite->data1; + sprite->data5 += sprite->data2; + + sprite->pos2.x = sprite->data4 / 256; + sprite->pos2.y = sprite->data5 / 256; + + sprite->data2 += sprite->data3; + + if (sprite->pos1.y + sprite->pos2.y > sprite->pos1.y + 20 && sprite->data2 > 0) + DestroySprite(sprite); +} + +static void CreateRandomEggShardSprite(void) +{ + u16 spriteAnimIndex; + + s16 velocity1 = gEggShardVelocities[sEggHatchData->eggShardVelocityID][0]; + s16 velocity2 = gEggShardVelocities[sEggHatchData->eggShardVelocityID][1]; + sEggHatchData->eggShardVelocityID++; + spriteAnimIndex = Random() % 4; + CreateEggShardSprite(120, 60, velocity1, velocity2, 100, spriteAnimIndex); +} + +static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex) +{ + u8 spriteID = CreateSprite(&gSpriteTemplate_820A418, x, y, 4); + gSprites[spriteID].data1 = data1; + gSprites[spriteID].data2 = data2; + gSprites[spriteID].data3 = data3; + StartSpriteAnim(&gSprites[spriteID], spriteAnimIndex); +} + +static void EggHatchPrintMessage1(u8* src) +{ + sub_8002EB0(&sEggHatchData->window, src, sEggHatchData->tileDataStartOffset, 3, 15); +} + +static void EggHatchPrintMessage2(u8* src) +{ + sub_8003460(&sEggHatchData->window, src, sEggHatchData->tileDataStartOffset, 3, 15); +} + +static bool8 EggHatchUpdateWindowText(void) +{ + return sub_80035AC(&sEggHatchData->window); +} diff --git a/sym_common.txt b/sym_common.txt index fc729a587..ec482a6d9 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -110,7 +110,7 @@ gUnknown_0300434C: @ 300434C @ egg_hatch .align 2 -gUnknown_0300481C: @ 300481C +sEggHatchData: @ 300481C .space 0x4 .include "load_save.o" From b14554c6ae23dfd1f1a8e1f3d3fc486fc9158a66 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 1 Aug 2017 15:21:54 +0200 Subject: [PATCH 3/4] move data to C --- asm/egg_hatch.s | 11 --- data/egg_hatch.s | 122 --------------------------- ld_script.txt | 3 +- src/egg_hatch.c | 209 +++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 192 insertions(+), 153 deletions(-) delete mode 100644 asm/egg_hatch.s delete mode 100644 data/egg_hatch.s diff --git a/asm/egg_hatch.s b/asm/egg_hatch.s deleted file mode 100644 index 1e7bffa77..000000000 --- a/asm/egg_hatch.s +++ /dev/null @@ -1,11 +0,0 @@ - .include "constants/gba_constants.inc" - .include "constants/species_constants.inc" - .include "asm/macros.inc" - - .syntax unified - - .text - - - - .align 2, 0 @ Don't pad with nop. diff --git a/data/egg_hatch.s b/data/egg_hatch.s deleted file mode 100644 index 1823409dd..000000000 --- a/data/egg_hatch.s +++ /dev/null @@ -1,122 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -EggPalette:: @ 8209AD8 - .incbin "graphics/pokemon/egg/palette.gbapal" - -EggHatchTiles:: @ 8209AF8 - .incbin "graphics/misc/egg_hatch.4bpp" - -EggShardTiles:: @ 820A2F8 - .incbin "graphics/misc/egg_shard.4bpp" - - .align 2 -gOamData_820A378:: @ 820A378 - .2byte 0x0000 - .2byte 0x8000 - .2byte 0x0400 - - .align 2 -gSpriteAnim_820A380:: @ 820A380 - obj_image_anim_frame 0, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A388:: @ 820A388 - obj_image_anim_frame 16, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A390:: @ 820A390 - obj_image_anim_frame 32, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A398:: @ 820A398 - obj_image_anim_frame 48, 5 - obj_image_anim_end - - .align 2 -gSpriteAnimTable_820A3A0:: @ 820A3A0 - .4byte gSpriteAnim_820A380 - .4byte gSpriteAnim_820A388 - .4byte gSpriteAnim_820A390 - .4byte gSpriteAnim_820A398 - - .align 2 -gUnknown_0820A3B0:: @ 820A3B0 - obj_tiles EggHatchTiles, 2048, 12345 - - .align 2 -gUnknown_0820A3B8:: @ 820A3B8 - obj_tiles EggShardTiles, 128, 23456 - - .align 2 -gUnknown_0820A3C0:: @ 820A3C0 - obj_pal EggPalette, 54321 - - .align 2 -gSpriteTemplate_820A3C8:: @ 820A3C8 - spr_template 12345, 54321, gOamData_820A378, gSpriteAnimTable_820A3A0, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy - - .align 2 -gOamData_820A3E0:: @ 820A3E0 - .2byte 0x0000 - .2byte 0x0000 - .2byte 0x0800 - - .align 2 -gSpriteAnim_820A3E8:: @ 820A3E8 - obj_image_anim_frame 0, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A3F0:: @ 820A3F0 - obj_image_anim_frame 1, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A3F8:: @ 820A3F8 - obj_image_anim_frame 2, 5 - obj_image_anim_end - - .align 2 -gSpriteAnim_820A400:: @ 820A400 - obj_image_anim_frame 3, 5 - obj_image_anim_end - - .align 2 -gSpriteAnimTable_820A408:: @ 820A408 - .4byte gSpriteAnim_820A3E8 - .4byte gSpriteAnim_820A3F0 - .4byte gSpriteAnim_820A3F8 - .4byte gSpriteAnim_820A400 - - .align 2 -gSpriteTemplate_820A418:: @ 820A418 - spr_template 23456, 54321, gOamData_820A3E0, gSpriteAnimTable_820A408, NULL, gDummySpriteAffineAnimTable, SpriteCB_EggShard - -@ The values are Q8.8 fixed-point numbers. - .align 1 -gEggShardVelocities:: @ 820A430 - .2byte 0xFE80, 0xFC40 @ (-1.5, -3.75) - .2byte 0xFB00, 0xFD00 @ (-5, -3) - .2byte 0x0380, 0xFD00 @ (3.5, -3) - .2byte 0xFC00, 0xFC40 @ (-4, -3.75) - .2byte 0x0200, 0xFE80 @ (2, -1.5) - .2byte 0xFF80, 0xF940 @ (-0.5, -6.75) - .2byte 0x0500, 0xFDC0 @ (5, -2.25) - .2byte 0xFE80, 0xFC40 @ (-1.5, -3.75) - .2byte 0x0480, 0xFE80 @ (4.5, -1.5) - .2byte 0xFF00, 0xF940 @ (-1, -6.75) - .2byte 0x0400, 0xFDC0 @ (4, -2.25) - .2byte 0xFC80, 0xFC40 @ (-3.5, -3.75) - .2byte 0x0100, 0xFE80 @ (1, -1.5) - .2byte 0xFC7C, 0xF940 @ (-3.515625, -6.75) - .2byte 0x0480, 0xFDC0 @ (4.5, -2.25) - .2byte 0xFF80, 0xF880 @ (-0.5, -7.5) - .2byte 0x0100, 0xFB80 @ (1, -4.5) - .2byte 0xFD80, 0xFDC0 @ (-2.5, -2.25) - .2byte 0x0280, 0xF880 @ (2.5, -7.5) diff --git a/ld_script.txt b/ld_script.txt index a0054668e..d4a5b6eed 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -74,7 +74,6 @@ SECTIONS { src/daycare.o(.text); asm/daycare.o(.text); src/egg_hatch.o(.text); - asm/egg_hatch.o(.text); src/battle_interface.o(.text); src/smokescreen.o(.text); src/pokeball.o(.text); @@ -338,7 +337,7 @@ SECTIONS { src/trig.o(.rodata); src/util.o(.rodata); data/daycare.o(.rodata); - data/egg_hatch.o(.rodata); + src/egg_hatch.o(.rodata); data/battle_interface.o(.rodata); src/pokeball.o(.rodata); data/trade.o(.rodata); diff --git a/src/egg_hatch.c b/src/egg_hatch.c index f518fdb84..45021d3e4 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -43,12 +43,9 @@ extern const u32 gUnknown_0820CA98[]; extern const u32 gUnknown_0820F798[]; extern const u16 gUnknown_08D004E0[]; //palette extern const u16 gUnknown_0820C9F8[]; //palette -extern const struct SpriteSheet gUnknown_0820A3B0; -extern const struct SpriteSheet gUnknown_0820A3B8; -extern const struct SpritePalette gUnknown_0820A3C0; -extern const struct SpriteTemplate gSpriteTemplate_820A3C8; -extern const struct SpriteTemplate gSpriteTemplate_820A418; -extern const s16 gEggShardVelocities[][2]; +extern const struct SpriteSheet sUnknown_0820A3B0; +extern const struct SpriteSheet sUnknown_0820A3B8; +extern const struct SpritePalette sUnknown_0820A3C0; bool8 GetNationalPokedexFlag(u16 nationalNum, u8 caseID); u8* GetMonNick(struct Pokemon* mon, u8* dst); @@ -65,12 +62,162 @@ static void SpriteCB_Egg_2(struct Sprite* sprite); static void SpriteCB_Egg_3(struct Sprite* sprite); static void SpriteCB_Egg_4(struct Sprite* sprite); static void SpriteCB_Egg_5(struct Sprite* sprite); +static void SpriteCB_EggShard(struct Sprite* sprite); static void EggHatchPrintMessage2(u8* src); static void EggHatchPrintMessage1(u8* src); static bool8 EggHatchUpdateWindowText(void); static void CreateRandomEggShardSprite(void); static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex); +// graphics + +static const u16 sEggPalette[] = INCBIN_U16("graphics/pokemon/egg/palette.gbapal"); +static const u8 sEggHatchTiles[] = INCBIN_U8("graphics/misc/egg_hatch.4bpp"); +static const u8 sEggShardTiles[] = INCBIN_U8("graphics/misc/egg_shard.4bpp"); + +static const struct OamData sOamData_820A378 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 2, + .tileNum = 0, + .priority = 1, + .paletteNum = 0, + .affineParam = 0, +}; + +static const union AnimCmd sSpriteAnim_820A380[] = +{ + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A388[] = +{ + ANIMCMD_FRAME(16, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A390[] = +{ + ANIMCMD_FRAME(32, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A398[] = +{ + ANIMCMD_FRAME(48, 5), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_820A3A0[] = +{ + sSpriteAnim_820A380, + sSpriteAnim_820A388, + sSpriteAnim_820A390, + sSpriteAnim_820A398, +}; + +static const struct SpriteSheet sUnknown_0820A3B0 = +{ + .data = sEggHatchTiles, + .size = 2048, + .tag = 12345, +}; + +static const struct SpriteSheet sUnknown_0820A3B8 = +{ + .data = sEggShardTiles, + .size = 128, + .tag = 23456, +}; + +static const struct SpritePalette sUnknown_0820A3C0 = +{ + .data = sEggPalette, + .tag = 54321 +}; + +static const struct SpriteTemplate sSpriteTemplate_820A3C8 = +{ + .tileTag = 12345, + .paletteTag = 54321, + .oam = &sOamData_820A378, + .anims = sSpriteAnimTable_820A3A0, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; + + +static const struct OamData sOamData_820A3E0 = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = 0, + .x = 0, + .matrixNum = 0, + .size = 0, + .tileNum = 0, + .priority = 2, + .paletteNum = 0, + .affineParam = 0, +}; + +static const union AnimCmd sSpriteAnim_820A3E8[] = +{ + ANIMCMD_FRAME(0, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A3F0[] = +{ + ANIMCMD_FRAME(1, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A3F8[] = +{ + ANIMCMD_FRAME(2, 5), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_820A400[] = +{ + ANIMCMD_FRAME(3, 5), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_820A408[] = +{ + sSpriteAnim_820A3E8, + sSpriteAnim_820A3F0, + sSpriteAnim_820A3F8, + sSpriteAnim_820A400, +}; + +static const struct SpriteTemplate sSpriteTemplate_820A418 = +{ + .tileTag = 23456, + .paletteTag = 54321, + .oam = &sOamData_820A3E0, + .anims = sSpriteAnimTable_820A408, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_EggShard +}; + +// actual code + static void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp) { u16 species; @@ -308,7 +455,7 @@ static void Task_EggHatch(u8 taskID) } } -void CB2_EggHatch_0(void) +static void CB2_EggHatch_0(void) { switch (gMain.state) { @@ -339,13 +486,13 @@ void CB2_EggHatch_0(void) gMain.state++; break; case 3: - LoadSpriteSheet(&gUnknown_0820A3B0); - LoadSpriteSheet(&gUnknown_0820A3B8); - LoadSpritePalette(&gUnknown_0820A3C0); + LoadSpriteSheet(&sUnknown_0820A3B0); + LoadSpriteSheet(&sUnknown_0820A3B8); + LoadSpritePalette(&sUnknown_0820A3C0); gMain.state++; break; case 4: - sEggHatchData->eggSpriteID = CreateSprite(&gSpriteTemplate_820A3C8, 0x78, 0x4B, 5); + sEggHatchData->eggSpriteID = CreateSprite(&sSpriteTemplate_820A3C8, 0x78, 0x4B, 5); AddHatchedMonToParty(sEggHatchData->eggPartyID); gMain.state++; break; @@ -406,13 +553,13 @@ void CB2_EggHatch_0(void) } } -void EggHatchSetMonNickname(void) +static void EggHatchSetMonNickname(void) { SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar3); SetMainCallback2(c2_exit_to_overworld_2_switch); } -void Task_EggHatchPlayBGM(u8 taskID) +static void Task_EggHatchPlayBGM(u8 taskID) { if (gTasks[taskID].data[0] == 0) StopMapMusic(); @@ -427,7 +574,7 @@ void Task_EggHatchPlayBGM(u8 taskID) gTasks[taskID].data[0]++; } -void CB2_EggHatch_1(void) +static void CB2_EggHatch_1(void) { switch (sEggHatchData->CB2_state) { @@ -640,7 +787,7 @@ static void SpriteCB_Egg_5(struct Sprite* sprite) sprite->data0++; } -void SpriteCB_EggShard(struct Sprite* sprite) +static void SpriteCB_EggShard(struct Sprite* sprite) { sprite->data4 += sprite->data1; sprite->data5 += sprite->data2; @@ -654,12 +801,38 @@ void SpriteCB_EggShard(struct Sprite* sprite) DestroySprite(sprite); } +// Converts a number to Q8.8 fixed-point format +#define Q_8_8(n) ((s16)((n) * 256)) + +static const s16 sEggShardVelocities[][2] = +{ + {Q_8_8(-1.5), Q_8_8(-3.75)}, + {Q_8_8(-5), Q_8_8(-3)}, + {Q_8_8(3.5), Q_8_8(-3)}, + {Q_8_8(-4), Q_8_8(-3.75)}, + {Q_8_8(2), Q_8_8(-1.5)}, + {Q_8_8(-0.5), Q_8_8(-6.75)}, + {Q_8_8(5), Q_8_8(-2.25)}, + {Q_8_8(-1.5), Q_8_8(-3.75)}, + {Q_8_8(4.5), Q_8_8(-1.5)}, + {Q_8_8(-1), Q_8_8(-6.75)}, + {Q_8_8(4), Q_8_8(-2.25)}, + {Q_8_8(-3.5), Q_8_8(-3.75)}, + {Q_8_8(1), Q_8_8(-1.5)}, + {Q_8_8(-3.515625), Q_8_8(-6.75)}, + {Q_8_8(4.5), Q_8_8(-2.25)}, + {Q_8_8(-0.5), Q_8_8(-7.5)}, + {Q_8_8(1), Q_8_8(-4.5)}, + {Q_8_8(-2.5), Q_8_8(-2.25)}, + {Q_8_8(2.5), Q_8_8(-7.5)}, +}; + static void CreateRandomEggShardSprite(void) { u16 spriteAnimIndex; - s16 velocity1 = gEggShardVelocities[sEggHatchData->eggShardVelocityID][0]; - s16 velocity2 = gEggShardVelocities[sEggHatchData->eggShardVelocityID][1]; + s16 velocity1 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][0]; + s16 velocity2 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][1]; sEggHatchData->eggShardVelocityID++; spriteAnimIndex = Random() % 4; CreateEggShardSprite(120, 60, velocity1, velocity2, 100, spriteAnimIndex); @@ -667,7 +840,7 @@ static void CreateRandomEggShardSprite(void) static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex) { - u8 spriteID = CreateSprite(&gSpriteTemplate_820A418, x, y, 4); + u8 spriteID = CreateSprite(&sSpriteTemplate_820A418, x, y, 4); gSprites[spriteID].data1 = data1; gSprites[spriteID].data2 = data2; gSprites[spriteID].data3 = data3; From acecf4fdb5bac6774c1bd5c77ee41a4269f023ef Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 7 Aug 2017 18:13:20 +0200 Subject: [PATCH 4/4] SE enums and egg hatch common sym --- common_syms/egg_hatch.txt | 1 + src/egg_hatch.c | 103 +++++++++++++++++++------------------- sym_common.txt | 8 +-- 3 files changed, 54 insertions(+), 58 deletions(-) create mode 100644 common_syms/egg_hatch.txt diff --git a/common_syms/egg_hatch.txt b/common_syms/egg_hatch.txt new file mode 100644 index 000000000..f49202045 --- /dev/null +++ b/common_syms/egg_hatch.txt @@ -0,0 +1 @@ +gEggHatchData \ No newline at end of file diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 45021d3e4..2b68d83e8 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -10,6 +10,7 @@ #include "main.h" #include "event_data.h" #include "sound.h" +#include "songs.h" #include "text.h" #include "text_window.h" #include "string_util.h" @@ -35,7 +36,7 @@ struct EggHatchData u8 eggShardVelocityID; }; -extern struct EggHatchData* sEggHatchData; +struct EggHatchData* gEggHatchData; extern const u32 gUnknown_08D00000[]; extern const u32 gUnknown_08D00524[]; @@ -461,9 +462,9 @@ static void CB2_EggHatch_0(void) { case 0: REG_DISPCNT = 0; - sEggHatchData = (struct EggHatchData*)(&ewram[0x18000]); - sEggHatchData->eggPartyID = gSpecialVar_0x8004; - sEggHatchData->eggShardVelocityID = 0; + gEggHatchData = (struct EggHatchData*)(&ewram[0x18000]); + gEggHatchData->eggPartyID = gSpecialVar_0x8004; + gEggHatchData->eggShardVelocityID = 0; ResetTasks(); ResetSpriteData(); FreeAllSpritePalettes(); @@ -473,9 +474,9 @@ static void CB2_EggHatch_0(void) break; case 1: SetUpWindowConfig(&gWindowConfig_81E6F84); - InitWindowFromConfig(&sEggHatchData->window, &gWindowConfig_81E6F84); - sEggHatchData->tileDataStartOffset = SetTextWindowBaseTileNum(20); - LoadTextWindowGraphics(&sEggHatchData->window); + InitWindowFromConfig(&gEggHatchData->window, &gWindowConfig_81E6F84); + gEggHatchData->tileDataStartOffset = SetTextWindowBaseTileNum(20); + LoadTextWindowGraphics(&gEggHatchData->window); gMain.state++; break; case 2: @@ -492,16 +493,16 @@ static void CB2_EggHatch_0(void) gMain.state++; break; case 4: - sEggHatchData->eggSpriteID = CreateSprite(&sSpriteTemplate_820A3C8, 0x78, 0x4B, 5); - AddHatchedMonToParty(sEggHatchData->eggPartyID); + gEggHatchData->eggSpriteID = CreateSprite(&sSpriteTemplate_820A3C8, 0x78, 0x4B, 5); + AddHatchedMonToParty(gEggHatchData->eggPartyID); gMain.state++; break; case 5: - EggHatchCreateMonSprite(0, 0, sEggHatchData->eggPartyID); + EggHatchCreateMonSprite(0, 0, gEggHatchData->eggPartyID); gMain.state++; break; case 6: - sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, sEggHatchData->eggPartyID); + gEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, gEggHatchData->eggPartyID); gMain.state++; break; case 7: @@ -548,7 +549,7 @@ static void CB2_EggHatch_0(void) REG_BG2VOFS = 0; SetMainCallback2(CB2_EggHatch_1); - sEggHatchData->CB2_state = 0; + gEggHatchData->CB2_state = 0; break; } } @@ -576,59 +577,59 @@ static void Task_EggHatchPlayBGM(u8 taskID) static void CB2_EggHatch_1(void) { - switch (sEggHatchData->CB2_state) + switch (gEggHatchData->CB2_state) { case 0: BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); REG_DISPCNT = 0x1740; - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; CreateTask(Task_EggHatchPlayBGM, 5); break; case 1: if (!gPaletteFade.active) { - sEggHatchData->CB2_PalCounter = 0; - sEggHatchData->CB2_state++; + gEggHatchData->CB2_PalCounter = 0; + gEggHatchData->CB2_state++; } break; case 2: - if (++sEggHatchData->CB2_PalCounter > 30) + if (++gEggHatchData->CB2_PalCounter > 30) { - sEggHatchData->CB2_state++; - gSprites[sEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0; + gEggHatchData->CB2_state++; + gSprites[gEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0; } break; case 3: - if (gSprites[sEggHatchData->eggSpriteID].callback == SpriteCallbackDummy) - sEggHatchData->CB2_state++; + if (gSprites[gEggHatchData->eggSpriteID].callback == SpriteCallbackDummy) + gEggHatchData->CB2_state++; break; case 4: - GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1); + GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1); StringExpandPlaceholders(gStringVar4, gOtherText_HatchedFromEgg); EggHatchPrintMessage2(gStringVar4); PlayFanfare(371); - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; break; case 5: if (IsFanfareTaskInactive()) - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; break; case 6: if (IsFanfareTaskInactive()) - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; break; case 7: - GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1); + GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1); StringExpandPlaceholders(gStringVar4, gOtherText_NickHatchPrompt); EggHatchPrintMessage1(gStringVar4); - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; break; case 8: if (EggHatchUpdateWindowText()) { MenuDrawTextWindow(22, 8, 27, 13); InitYesNoMenu(22, 8, 4); - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; } break; case 9: @@ -642,20 +643,20 @@ static void CB2_EggHatch_1(void) u8 gender; u32 personality; - GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar3); - species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES); - gender = GetMonGender(&gPlayerParty[sEggHatchData->eggPartyID]); - personality = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0); + GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar3); + species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES); + gender = GetMonGender(&gPlayerParty[gEggHatchData->eggPartyID]); + personality = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0); DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname); } else - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; } } break; case 10: BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); - sEggHatchData->CB2_state++; + gEggHatchData->CB2_state++; break; case 11: if (!gPaletteFade.active) @@ -681,7 +682,7 @@ static void SpriteCB_Egg_0(struct Sprite* sprite) sprite->pos2.x = Sin(sprite->data1, 1); if (sprite->data0 == 15) { - PlaySE(23); + PlaySE(SE_BOWA); StartSpriteAnim(sprite, 1); CreateRandomEggShardSprite(); } @@ -704,7 +705,7 @@ static void SpriteCB_Egg_1(struct Sprite* sprite) sprite->pos2.x = Sin(sprite->data1, 2); if (sprite->data0 == 15) { - PlaySE(23); + PlaySE(SE_BOWA); StartSpriteAnim(sprite, 2); } } @@ -721,9 +722,9 @@ static void SpriteCB_Egg_2(struct Sprite* sprite) sprite->callback = SpriteCB_Egg_3; sprite->data0 = 0; - species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES); - gSprites[sEggHatchData->pokeSpriteID].pos2.x = 0; - gSprites[sEggHatchData->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset; + species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES); + gSprites[gEggHatchData->pokeSpriteID].pos2.x = 0; + gSprites[gEggHatchData->pokeSpriteID].pos2.y = gMonFrontPicCoords[species].y_offset; } else { @@ -731,13 +732,13 @@ static void SpriteCB_Egg_2(struct Sprite* sprite) sprite->pos2.x = Sin(sprite->data1, 2); if (sprite->data0 == 15) { - PlaySE(23); + PlaySE(SE_BOWA); StartSpriteAnim(sprite, 2); CreateRandomEggShardSprite(); CreateRandomEggShardSprite(); } if (sprite->data0 == 30) - PlaySE(23); + PlaySE(SE_BOWA); } } } @@ -764,7 +765,7 @@ static void SpriteCB_Egg_4(struct Sprite* sprite) sprite->data0++; if (!gPaletteFade.active) { - PlaySE(113); + PlaySE(SE_TAMAGO); sprite->invisible = 1; sprite->callback = SpriteCB_Egg_5; sprite->data0 = 0; @@ -775,13 +776,13 @@ static void SpriteCB_Egg_5(struct Sprite* sprite) { if (sprite->data0 == 0) { - gSprites[sEggHatchData->pokeSpriteID].invisible = 0; - StartSpriteAffineAnim(&gSprites[sEggHatchData->pokeSpriteID], 1); + gSprites[gEggHatchData->pokeSpriteID].invisible = 0; + StartSpriteAffineAnim(&gSprites[gEggHatchData->pokeSpriteID], 1); } if (sprite->data0 == 8) BeginNormalPaletteFade(-1, -1, 0x10, 0, 0xFFFF); if (sprite->data0 <= 9) - gSprites[sEggHatchData->pokeSpriteID].pos1.y -= 1; + gSprites[gEggHatchData->pokeSpriteID].pos1.y -= 1; if (sprite->data0 > 40) sprite->callback = SpriteCallbackDummy; sprite->data0++; @@ -831,9 +832,9 @@ static void CreateRandomEggShardSprite(void) { u16 spriteAnimIndex; - s16 velocity1 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][0]; - s16 velocity2 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][1]; - sEggHatchData->eggShardVelocityID++; + s16 velocity1 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][0]; + s16 velocity2 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][1]; + gEggHatchData->eggShardVelocityID++; spriteAnimIndex = Random() % 4; CreateEggShardSprite(120, 60, velocity1, velocity2, 100, spriteAnimIndex); } @@ -849,15 +850,15 @@ static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 static void EggHatchPrintMessage1(u8* src) { - sub_8002EB0(&sEggHatchData->window, src, sEggHatchData->tileDataStartOffset, 3, 15); + sub_8002EB0(&gEggHatchData->window, src, gEggHatchData->tileDataStartOffset, 3, 15); } static void EggHatchPrintMessage2(u8* src) { - sub_8003460(&sEggHatchData->window, src, sEggHatchData->tileDataStartOffset, 3, 15); + sub_8003460(&gEggHatchData->window, src, gEggHatchData->tileDataStartOffset, 3, 15); } static bool8 EggHatchUpdateWindowText(void) { - return sub_80035AC(&sEggHatchData->window); + return sub_80035AC(&gEggHatchData->window); } diff --git a/sym_common.txt b/sym_common.txt index ec482a6d9..0e934ba05 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -106,13 +106,7 @@ gUnknown_0300434C: @ 300434C .include "pokemon_1.o" .include "rng.o" - -@ egg_hatch - - .align 2 -sEggHatchData: @ 300481C - .space 0x4 - + .include "egg_hatch.o" .include "load_save.o" @ trade