From 84a94412670d1ba365b1857dbfd3de717fe3967e Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 25 Oct 2017 19:54:24 -0400 Subject: [PATCH] MWF: sub_80E9914 --- asm/secret_base.s | 177 ---------------------------------- include/global.h | 8 +- src/secret_base.c | 235 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+), 181 deletions(-) diff --git a/asm/secret_base.s b/asm/secret_base.s index 519ad4b710..6655863ed6 100644 --- a/asm/secret_base.s +++ b/asm/secret_base.s @@ -5,183 +5,6 @@ .text - thumb_func_start sub_80E9914 -sub_80E9914: @ 80E9914 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x24 - movs r0, 0 - mov r10, r0 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r2, =0x00001ad0 - adds r2, r1, r2 - str r2, [sp] - ldr r3, =0x00001a9c - adds r0, r1, r3 - ldrb r0, [r0] - cmp r0, 0 - bne _080E993A - b _080E9A60 -_080E993A: - movs r6, 0 - ldr r7, =0x00001ae8 - adds r7, r1, r7 - str r7, [sp, 0x14] - ldr r0, =0x00001b18 - adds r0, r1, r0 - str r0, [sp, 0xC] - ldr r2, =0x00001b24 - adds r2, r1, r2 - str r2, [sp, 0x10] - adds r3, 0x94 - adds r3, r1, r3 - str r3, [sp, 0x18] - ldr r7, =0x00001b36 - adds r7, r1, r7 - str r7, [sp, 0x1C] - mov r9, r6 -_080E995C: - movs r4, 0 - lsls r5, r6, 2 - lsls r3, r6, 1 - ldr r0, =gPlayerParty - mov r8, r0 - adds r1, r6, 0x1 - str r1, [sp, 0x4] - adds r2, r5, 0 - ldr r1, [sp, 0x14] -_080E996E: - adds r0, r2, r4 - lsls r0, 1 - adds r0, r1, r0 - mov r7, r9 - strh r7, [r0] - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - cmp r4, 0x3 - bls _080E996E - ldr r1, [sp, 0xC] - adds r0, r1, r3 - mov r2, r9 - strh r2, [r0] - ldr r7, [sp, 0x10] - adds r0, r7, r3 - strh r2, [r0] - ldr r1, [sp, 0x18] - adds r0, r1, r6 - mov r2, r9 - strb r2, [r0] - ldr r3, [sp] - adds r0, r3, r5 - mov r7, r9 - str r7, [r0] - ldr r1, [sp, 0x1C] - adds r0, r1, r6 - strb r7, [r0] - movs r2, 0x64 - adds r5, r6, 0 - muls r5, r2 - mov r3, r8 - adds r4, r5, r3 - adds r0, r4, 0 - movs r1, 0xB - bl GetMonData - cmp r0, 0 - beq _080E9A54 - adds r0, r4, 0 - movs r1, 0x2D - bl GetMonData - cmp r0, 0 - bne _080E9A54 - movs r4, 0 - mov r7, r10 - lsls r7, 2 - mov r8, r7 - mov r0, r10 - lsls r7, r0, 1 - adds r0, 0x1 - str r0, [sp, 0x8] - ldr r2, =gPlayerParty -_080E99DA: - adds r1, r4, 0 - adds r1, 0xD - adds r0, r5, r2 - str r2, [sp, 0x20] - bl GetMonData - mov r3, r8 - adds r1, r3, r4 - lsls r1, 1 - ldr r3, [sp, 0x14] - adds r1, r3, r1 - strh r0, [r1] - adds r0, r4, 0x1 - lsls r0, 16 - lsrs r4, r0, 16 - ldr r2, [sp, 0x20] - cmp r4, 0x3 - bls _080E99DA - movs r0, 0x64 - adds r4, r6, 0 - muls r4, r0 - ldr r0, =gPlayerParty - adds r4, r0 - adds r0, r4, 0 - movs r1, 0xB - bl GetMonData - ldr r2, [sp, 0xC] - adds r1, r2, r7 - strh r0, [r1] - adds r0, r4, 0 - movs r1, 0xC - bl GetMonData - ldr r3, [sp, 0x10] - adds r1, r3, r7 - strh r0, [r1] - adds r0, r4, 0 - movs r1, 0x38 - bl GetMonData - ldr r1, [sp, 0x18] - add r1, r10 - strb r0, [r1] - adds r0, r4, 0 - movs r1, 0 - bl GetMonData - ldr r1, [sp] - add r1, r8 - str r0, [r1] - adds r0, r4, 0 - bl sub_80E98AC - ldr r1, [sp, 0x1C] - add r1, r10 - strb r0, [r1] - ldr r7, [sp, 0x8] - lsls r0, r7, 16 - lsrs r0, 16 - mov r10, r0 -_080E9A54: - ldr r1, [sp, 0x4] - lsls r0, r1, 16 - lsrs r6, r0, 16 - cmp r6, 0x5 - bhi _080E9A60 - b _080E995C -_080E9A60: - add sp, 0x24 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E9914 - thumb_func_start sub_80E9A90 sub_80E9A90: @ 80E9A90 push {r4-r6,lr} diff --git a/include/global.h b/include/global.h index 3ac8fa6959..75d7095401 100644 --- a/include/global.h +++ b/include/global.h @@ -249,10 +249,10 @@ struct SecretBaseRecord /*0x1AAD*/ u8 sbr_field_11; /*0x1AAE*/ u8 decorations[16]; /*0x1ABE*/ u8 decorationPos[16]; - /*0x1ACE*/ u32 partyPersonality[6]; - /*0x1AE6*/ u16 partyMoves[6 * 4]; - /*0x1B16*/ u16 partySpecies[6]; - /*0x1B22*/ u16 partyHeldItems[6]; + /*0x1AD0*/ u32 partyPersonality[6]; + /*0x1AE8*/ u16 partyMoves[6 * 4]; + /*0x1B18*/ u16 partySpecies[6]; + /*0x1B24*/ u16 partyHeldItems[6]; /*0x1B2E*/ u8 partyLevels[6]; /*0x1B34*/ u8 partyEVs[6]; }; diff --git a/src/secret_base.c b/src/secret_base.c index 7154abbf24..4e9dc20900 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -5,6 +5,9 @@ #include "palette.h" #include "list_menu.h" #include "map_constants.h" +#include "species.h" +#include "moves.h" +#include "items.h" #include "overworld.h" #include "fieldmap.h" #include "field_camera.h" @@ -615,3 +618,235 @@ u8 sub_80E98AC(struct Pokemon *pokemon) evTotal += GetMonData(pokemon, MON_DATA_SPDEF_EV); return evTotal / 6; } + +#ifdef NONMATCHING +// This function is a meme +void sub_80E9914(void) +{ + u32 zero; + u32 *personality; + u16 partyidx; + u16 moveidx; + u16 sbpartyidx; + u16 *species; + u16 *items; + u16 *moves; + u8 *levels; + u8 *evs; + + sbpartyidx = 0; + personality = gSaveBlock1Ptr->secretBases[0].partyPersonality; + if (gSaveBlock1Ptr->secretBases[0].secretBaseId != 0) + { + partyidx = 0; + moves = gSaveBlock1Ptr->secretBases[0].partyMoves; + species = gSaveBlock1Ptr->secretBases[0].partySpecies; + items = gSaveBlock1Ptr->secretBases[0].partyHeldItems; + levels = gSaveBlock1Ptr->secretBases[0].partyLevels; + evs = gSaveBlock1Ptr->secretBases[0].partyEVs; + zero = 0; + for (partyidx = 0; partyidx < PARTY_SIZE; partyidx ++) + { + for (moveidx = 0; moveidx < 4; moveidx ++) + { + moves[partyidx * 4 + moveidx] = zero; + } + species[partyidx] = zero; + items[partyidx] = zero; + levels[partyidx] = zero; + personality[partyidx] = zero; + evs[partyidx] = zero; + if (GetMonData(&gPlayerParty[partyidx], MON_DATA_SPECIES) != SPECIES_NONE && !GetMonData(&gPlayerParty[partyidx], MON_DATA_IS_EGG)) + { + for (moveidx = 0; moveidx < 4; moveidx ++) + { + moves[sbpartyidx * 4 + moveidx] = GetMonData(&gPlayerParty[partyidx], MON_DATA_MOVE1 + moveidx); + } + species[sbpartyidx] = GetMonData(&gPlayerParty[partyidx], MON_DATA_SPECIES); + items[sbpartyidx] = GetMonData(&gPlayerParty[partyidx], MON_DATA_HELD_ITEM); + levels[sbpartyidx] = GetMonData(&gPlayerParty[partyidx], MON_DATA_LEVEL); + personality[sbpartyidx] = GetMonData(&gPlayerParty[partyidx], MON_DATA_PERSONALITY); + evs[sbpartyidx] = sub_80E98AC(&gPlayerParty[partyidx]); + sbpartyidx ++; + } + } + } +} +#else +__attribute__((naked)) void sub_80E9914(void) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tmov r7, r10\n" + "\tmov r6, r9\n" + "\tmov r5, r8\n" + "\tpush {r5-r7}\n" + "\tsub sp, 0x24\n" + "\tmovs r0, 0\n" + "\tmov r10, r0\n" + "\tldr r0, =gSaveBlock1Ptr\n" + "\tldr r1, [r0]\n" + "\tldr r2, =0x00001ad0\n" + "\tadds r2, r1, r2\n" + "\tstr r2, [sp]\n" + "\tldr r3, =0x00001a9c\n" + "\tadds r0, r1, r3\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _080E993A\n" + "\tb _080E9A60\n" + "_080E993A:\n" + "\tmovs r6, 0\n" + "\tldr r7, =0x00001ae8\n" + "\tadds r7, r1, r7\n" + "\tstr r7, [sp, 0x14]\n" + "\tldr r0, =0x00001b18\n" + "\tadds r0, r1, r0\n" + "\tstr r0, [sp, 0xC]\n" + "\tldr r2, =0x00001b24\n" + "\tadds r2, r1, r2\n" + "\tstr r2, [sp, 0x10]\n" + "\tadds r3, 0x94\n" + "\tadds r3, r1, r3\n" + "\tstr r3, [sp, 0x18]\n" + "\tldr r7, =0x00001b36\n" + "\tadds r7, r1, r7\n" + "\tstr r7, [sp, 0x1C]\n" + "\tmov r9, r6\n" + "_080E995C:\n" + "\tmovs r4, 0\n" + "\tlsls r5, r6, 2\n" + "\tlsls r3, r6, 1\n" + "\tldr r0, =gPlayerParty\n" + "\tmov r8, r0\n" + "\tadds r1, r6, 0x1\n" + "\tstr r1, [sp, 0x4]\n" + "\tadds r2, r5, 0\n" + "\tldr r1, [sp, 0x14]\n" + "_080E996E:\n" + "\tadds r0, r2, r4\n" + "\tlsls r0, 1\n" + "\tadds r0, r1, r0\n" + "\tmov r7, r9\n" + "\tstrh r7, [r0]\n" + "\tadds r0, r4, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r4, r0, 16\n" + "\tcmp r4, 0x3\n" + "\tbls _080E996E\n" + "\tldr r1, [sp, 0xC]\n" + "\tadds r0, r1, r3\n" + "\tmov r2, r9\n" + "\tstrh r2, [r0]\n" + "\tldr r7, [sp, 0x10]\n" + "\tadds r0, r7, r3\n" + "\tstrh r2, [r0]\n" + "\tldr r1, [sp, 0x18]\n" + "\tadds r0, r1, r6\n" + "\tmov r2, r9\n" + "\tstrb r2, [r0]\n" + "\tldr r3, [sp]\n" + "\tadds r0, r3, r5\n" + "\tmov r7, r9\n" + "\tstr r7, [r0]\n" + "\tldr r1, [sp, 0x1C]\n" + "\tadds r0, r1, r6\n" + "\tstrb r7, [r0]\n" + "\tmovs r2, 0x64\n" + "\tadds r5, r6, 0\n" + "\tmuls r5, r2\n" + "\tmov r3, r8\n" + "\tadds r4, r5, r3\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0xB\n" + "\tbl GetMonData\n" + "\tcmp r0, 0\n" + "\tbeq _080E9A54\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0x2D\n" + "\tbl GetMonData\n" + "\tcmp r0, 0\n" + "\tbne _080E9A54\n" + "\tmovs r4, 0\n" + "\tmov r7, r10\n" + "\tlsls r7, 2\n" + "\tmov r8, r7\n" + "\tmov r0, r10\n" + "\tlsls r7, r0, 1\n" + "\tadds r0, 0x1\n" + "\tstr r0, [sp, 0x8]\n" + "\tldr r2, =gPlayerParty\n" + "_080E99DA:\n" + "\tadds r1, r4, 0\n" + "\tadds r1, 0xD\n" + "\tadds r0, r5, r2\n" + "\tstr r2, [sp, 0x20]\n" + "\tbl GetMonData\n" + "\tmov r3, r8\n" + "\tadds r1, r3, r4\n" + "\tlsls r1, 1\n" + "\tldr r3, [sp, 0x14]\n" + "\tadds r1, r3, r1\n" + "\tstrh r0, [r1]\n" + "\tadds r0, r4, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r4, r0, 16\n" + "\tldr r2, [sp, 0x20]\n" + "\tcmp r4, 0x3\n" + "\tbls _080E99DA\n" + "\tmovs r0, 0x64\n" + "\tadds r4, r6, 0\n" + "\tmuls r4, r0\n" + "\tldr r0, =gPlayerParty\n" + "\tadds r4, r0\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0xB\n" + "\tbl GetMonData\n" + "\tldr r2, [sp, 0xC]\n" + "\tadds r1, r2, r7\n" + "\tstrh r0, [r1]\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0xC\n" + "\tbl GetMonData\n" + "\tldr r3, [sp, 0x10]\n" + "\tadds r1, r3, r7\n" + "\tstrh r0, [r1]\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0x38\n" + "\tbl GetMonData\n" + "\tldr r1, [sp, 0x18]\n" + "\tadd r1, r10\n" + "\tstrb r0, [r1]\n" + "\tadds r0, r4, 0\n" + "\tmovs r1, 0\n" + "\tbl GetMonData\n" + "\tldr r1, [sp]\n" + "\tadd r1, r8\n" + "\tstr r0, [r1]\n" + "\tadds r0, r4, 0\n" + "\tbl sub_80E98AC\n" + "\tldr r1, [sp, 0x1C]\n" + "\tadd r1, r10\n" + "\tstrb r0, [r1]\n" + "\tldr r7, [sp, 0x8]\n" + "\tlsls r0, r7, 16\n" + "\tlsrs r0, 16\n" + "\tmov r10, r0\n" + "_080E9A54:\n" + "\tldr r1, [sp, 0x4]\n" + "\tlsls r0, r1, 16\n" + "\tlsrs r6, r0, 16\n" + "\tcmp r6, 0x5\n" + "\tbhi _080E9A60\n" + "\tb _080E995C\n" + "_080E9A60:\n" + "\tadd sp, 0x24\n" + "\tpop {r3-r5}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tmov r10, r5\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.pool"); +} +#endif