From eff1ad330031633b2a28f2b9e8bc8f5e5258826a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 22 Nov 2017 20:10:35 -0500 Subject: [PATCH 1/6] Decompile field poison --- asm/field_poison.s | 323 ------------------------------------ asm/fldeff_80F9BCC.s | 16 +- include/battle_frontier_2.h | 1 + include/fldeff_80F9BCC.h | 1 + include/party_menu.h | 1 + include/pokenav.h | 6 + include/strings.h | 1 + ld_script.txt | 2 +- src/field_poison.c | 157 ++++++++++++++++++ 9 files changed, 176 insertions(+), 332 deletions(-) delete mode 100644 asm/field_poison.s create mode 100644 include/pokenav.h create mode 100644 src/field_poison.c diff --git a/asm/field_poison.s b/asm/field_poison.s deleted file mode 100644 index 83262a1a56..0000000000 --- a/asm/field_poison.s +++ /dev/null @@ -1,323 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_80F9568 -sub_80F9568: @ 80F9568 - push {lr} - movs r1, 0x41 - bl GetMonData - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - beq _080F9580 - movs r0, 0xCE - lsls r0, 1 - cmp r1, r0 - bne _080F9584 -_080F9580: - movs r0, 0 - b _080F9586 -_080F9584: - movs r0, 0x1 -_080F9586: - pop {r1} - bx r1 - thumb_func_end sub_80F9568 - - thumb_func_start sub_80F958C -sub_80F958C: @ 80F958C - push {r4,r5,lr} - ldr r4, =gPlayerParty - movs r5, 0 -_080F9592: - adds r0, r4, 0 - bl sub_80F9568 - cmp r0, 0 - beq _080F95B0 - adds r0, r4, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - beq _080F95B0 - movs r0, 0 - b _080F95BA - .pool -_080F95B0: - adds r5, 0x1 - adds r4, 0x64 - cmp r5, 0x5 - ble _080F9592 - movs r0, 0x1 -_080F95BA: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_80F958C - - thumb_func_start sub_80F95C0 -sub_80F95C0: @ 80F95C0 - push {r4,r5,lr} - sub sp, 0x4 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x64 - adds r4, r0, 0 - muls r4, r1 - ldr r0, =gPlayerParty - adds r4, r0 - movs r0, 0 - str r0, [sp] - adds r0, r4, 0 - movs r1, 0x7 - bl AdjustFriendship - adds r0, r4, 0 - movs r1, 0x37 - mov r2, sp - bl SetMonData - ldr r5, =gStringVar1 - adds r0, r4, 0 - movs r1, 0x2 - adds r2, r5, 0 - bl GetMonData - adds r0, r5, 0 - bl StringGetEnd10 - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F95C0 - - thumb_func_start sub_80F960C -sub_80F960C: @ 80F960C - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x64 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - bl sub_80F9568 - cmp r0, 0 - beq _080F964C - adds r0, r4, 0 - movs r1, 0x39 - bl GetMonData - cmp r0, 0 - bne _080F964C - adds r0, r4, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080F964C - movs r0, 0x1 - b _080F964E - .pool -_080F964C: - movs r0, 0 -_080F964E: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80F960C - - thumb_func_start sub_80F9654 -sub_80F9654: @ 80F9654 - push {r4-r6,lr} - lsls r0, 24 - lsrs r6, r0, 24 - lsls r0, r6, 2 - adds r0, r6 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r4, r0, r1 - movs r0, 0 - ldrsh r5, [r4, r0] - cmp r5, 0x1 - beq _080F96AE - cmp r5, 0x1 - bgt _080F967C - cmp r5, 0 - beq _080F9682 - b _080F9722 - .pool -_080F967C: - cmp r5, 0x2 - beq _080F96C0 - b _080F9722 -_080F9682: - ldrh r1, [r4, 0x2] - movs r2, 0x2 - ldrsh r0, [r4, r2] - cmp r0, 0x5 - bgt _080F96A8 -_080F968C: - lsls r0, r1, 24 - lsrs r0, 24 - bl sub_80F960C - cmp r0, 0 - bne _080F96FC - ldrh r0, [r4, 0x2] - adds r0, 0x1 - strh r0, [r4, 0x2] - adds r1, r0, 0 - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x5 - ble _080F968C -_080F96A8: - movs r0, 0x2 - strh r0, [r4] - b _080F9722 -_080F96AE: - bl IsFieldMessageBoxHidden - lsls r0, 24 - cmp r0, 0 - beq _080F9722 - ldrh r0, [r4] - subs r0, 0x1 - strh r0, [r4] - b _080F9722 -_080F96C0: - bl sub_80F958C - adds r1, r0, 0 - cmp r1, 0 - beq _080F9714 - bl InBattlePyramid - adds r4, r0, 0 - bl InBattlePike - orrs r4, r0 - lsls r4, 24 - cmp r4, 0 - bne _080F96E6 - bl sub_81D5C18 - lsls r0, 24 - cmp r0, 0 - beq _080F96F0 -_080F96E6: - ldr r0, =gSpecialVar_Result - strh r5, [r0] - b _080F9718 - .pool -_080F96F0: - ldr r1, =gSpecialVar_Result - movs r0, 0x1 - strh r0, [r1] - b _080F9718 - .pool -_080F96FC: - ldrb r0, [r4, 0x2] - bl sub_80F95C0 - ldr r0, =gText_PkmnFainted3 - bl ShowFieldMessage - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] - b _080F9722 - .pool -_080F9714: - ldr r0, =gSpecialVar_Result - strh r1, [r0] -_080F9718: - bl EnableBothScriptContexts - adds r0, r6, 0 - bl DestroyTask -_080F9722: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F9654 - - thumb_func_start sub_80F972C -sub_80F972C: @ 80F972C - push {lr} - ldr r0, =sub_80F9654 - movs r1, 0x50 - bl CreateTask - bl ScriptContext1_Stop - pop {r0} - bx r0 - .pool - thumb_func_end sub_80F972C - - thumb_func_start overworld_poison -overworld_poison: @ 80F9744 - push {r4-r7,lr} - sub sp, 0x4 - ldr r4, =gPlayerParty - movs r7, 0 - movs r6, 0 - movs r5, 0x5 -_080F9750: - adds r0, r4, 0 - movs r1, 0x5 - bl GetMonData - cmp r0, 0 - beq _080F9794 - adds r0, r4, 0 - movs r1, 0x37 - bl GetMonData - bl pokemon_ailments_get_primary - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080F9794 - adds r0, r4, 0 - movs r1, 0x39 - bl GetMonData - str r0, [sp] - cmp r0, 0 - beq _080F9786 - subs r0, 0x1 - str r0, [sp] - cmp r0, 0 - bne _080F9788 -_080F9786: - adds r6, 0x1 -_080F9788: - adds r0, r4, 0 - movs r1, 0x39 - mov r2, sp - bl SetMonData - adds r7, 0x1 -_080F9794: - adds r4, 0x64 - subs r5, 0x1 - cmp r5, 0 - bge _080F9750 - cmp r6, 0 - bne _080F97A4 - cmp r7, 0 - beq _080F97A8 -_080F97A4: - bl overworld_posion_effect -_080F97A8: - cmp r6, 0 - beq _080F97B4 - movs r0, 0x2 - b _080F97BE - .pool -_080F97B4: - cmp r7, 0 - bne _080F97BC - movs r0, 0 - b _080F97BE -_080F97BC: - movs r0, 0x1 -_080F97BE: - add sp, 0x4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end overworld_poison - - .align 2, 0 @ Don't pad with nop. diff --git a/asm/fldeff_80F9BCC.s b/asm/fldeff_80F9BCC.s index efdc114a25..369bef8099 100644 --- a/asm/fldeff_80F9BCC.s +++ b/asm/fldeff_80F9BCC.s @@ -2200,8 +2200,8 @@ _080FAE2A: .pool thumb_func_end sub_80FADE4 - thumb_func_start task50_overworld_posion_effect -task50_overworld_posion_effect: @ 80FAE38 + thumb_func_start task50_overworld_poison_effect +task50_overworld_poison_effect: @ 80FAE38 push {lr} lsls r0, 24 lsrs r2, r0, 24 @@ -2260,25 +2260,25 @@ _080FAE92: _080FAEA2: pop {r0} bx r0 - thumb_func_end task50_overworld_posion_effect + thumb_func_end task50_overworld_poison_effect - thumb_func_start overworld_posion_effect -overworld_posion_effect: @ 80FAEA8 + thumb_func_start overworld_poison_effect +overworld_poison_effect: @ 80FAEA8 push {lr} movs r0, 0x4F bl PlaySE - ldr r0, =task50_overworld_posion_effect + ldr r0, =task50_overworld_poison_effect movs r1, 0x50 bl CreateTask pop {r0} bx r0 .pool - thumb_func_end overworld_posion_effect + thumb_func_end overworld_poison_effect thumb_func_start c3_80A0DD8_is_running c3_80A0DD8_is_running: @ 80FAEC0 push {lr} - ldr r0, =task50_overworld_posion_effect + ldr r0, =task50_overworld_poison_effect bl FuncIsActiveTask lsls r0, 24 lsrs r0, 24 diff --git a/include/battle_frontier_2.h b/include/battle_frontier_2.h index 4f37248cc1..801c3f3ece 100644 --- a/include/battle_frontier_2.h +++ b/include/battle_frontier_2.h @@ -5,5 +5,6 @@ void sub_81A8934(u8); void sub_81A895C(void); u16 sub_81A89A0(u8); void sub_81A8AF8(void); +bool8 InBattlePike(void); #endif // GUARD_BATTLE_FRONTIER_2_H diff --git a/include/fldeff_80F9BCC.h b/include/fldeff_80F9BCC.h index ecce049431..d57665c68b 100644 --- a/include/fldeff_80F9BCC.h +++ b/include/fldeff_80F9BCC.h @@ -9,5 +9,6 @@ void sub_80FA5E4(s16 id, s16 x, s16 y); void sub_80FA794(s16 x, s16 y); +void overworld_poison_effect(void); #endif //GUARD_FLDEFF_80F9BCC_H diff --git a/include/party_menu.h b/include/party_menu.h index 7a7d59cd0c..0249711931 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -4,5 +4,6 @@ bool8 pokemon_has_move(struct Pokemon *, u16); void sub_81B58A8(void); void DoWallyTutorialBagMenu(void); +u8 pokemon_ailments_get_primary(u32 status); #endif // GUARD_PARTY_MENU_H diff --git a/include/pokenav.h b/include/pokenav.h new file mode 100644 index 0000000000..06676610a4 --- /dev/null +++ b/include/pokenav.h @@ -0,0 +1,6 @@ +#ifndef GUARD_POKENAV_H +#define GUARD_POKENAV_H + +bool8 sub_81D5C18(void); + +#endif //GUARD_POKENAV_H diff --git a/include/strings.h b/include/strings.h index 08e2b4bba8..1f7267b4a8 100644 --- a/include/strings.h +++ b/include/strings.h @@ -82,5 +82,6 @@ extern const u8 gText_NoRegistry[]; extern const u8 gText_OkayToDeleteFromRegistry[]; extern const u8 gText_RegisteredDataDeleted[]; extern const u8 gUnknown_085EA79D[]; +extern const u8 gText_PkmnFainted3[]; #endif //GUARD_STRINGS_H diff --git a/ld_script.txt b/ld_script.txt index e9c810adcf..b999531346 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -153,7 +153,7 @@ SECTIONS { src/tv.o(.text); asm/contest_link_80F57C4.o(.text); asm/script_pokemon_util_80F87D8.o(.text); - asm/field_poison.o(.text); + src/field_poison.o(.text); src/pokemon_size_record.o(.text); asm/fldeff_80F9BCC.o(.text); src/field_special_scene.o(.text); diff --git a/src/field_poison.c b/src/field_poison.c new file mode 100644 index 0000000000..f9d7b16096 --- /dev/null +++ b/src/field_poison.c @@ -0,0 +1,157 @@ +#include "global.h" +#include "string_util.h" +#include "party_menu.h" +#include "species.h" +#include "task.h" +#include "field_message_box.h" +#include "strings.h" +#include "rom_818CFC8.h" +#include "battle_frontier_2.h" +#include "pokenav.h" +#include "event_data.h" +#include "script.h" +#include "fldeff_80F9BCC.h" + +static bool32 sub_80F9568(struct Pokemon *pokemon) +{ + u16 species = GetMonData(pokemon, MON_DATA_SPECIES2); + if (species == SPECIES_NONE || species == SPECIES_EGG) + { + return FALSE; + } + return TRUE; +} + +static bool32 sub_80F958C(void) +{ + int i; + struct Pokemon *pokemon; + + for (pokemon = gPlayerParty, i = 0; i < PARTY_SIZE; i++, pokemon++) + { + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) != 0) + { + return FALSE; + } + } + return TRUE; +} + +static void sub_80F95C0(u8 partyIdx) +{ + struct Pokemon *pokemon; + unsigned status; + + pokemon = &gPlayerParty[partyIdx]; + status = 0; + AdjustFriendship(pokemon, 0x07); + SetMonData(pokemon, MON_DATA_STATUS, &status); + GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); + StringGetEnd10(gStringVar1); +} + +static bool32 sub_80F960C(u8 partyIdx) +{ + struct Pokemon *pokemon; + + pokemon = &gPlayerParty[partyIdx]; + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + { + return TRUE; + } + return FALSE; +} + +static void sub_80F9654(u8 taskId) +{ + s16 *data; + + data = gTasks[taskId].data; + switch (data[0]) + { + case 0: + for (; data[1] < PARTY_SIZE; data[1]++) + { + if (sub_80F960C(data[1])) + { + sub_80F95C0(data[1]); + ShowFieldMessage(gText_PkmnFainted3); + data[0]++; + return; + } + } + data[0] = 2; + break; + case 1: + if (IsFieldMessageBoxHidden()) + { + data[0]--; + } + break; + case 2: + if (sub_80F958C()) + { + if (InBattlePyramid() | InBattlePike() || sub_81D5C18()) + { + gSpecialVar_Result = 2; + } + else + { + gSpecialVar_Result = 1; + } + } + else + { + gSpecialVar_Result = 0; + } + EnableBothScriptContexts(); + DestroyTask(taskId); + break; + } +} + +void sub_80F972C(void) +{ + CreateTask(sub_80F9654, 80); + ScriptContext1_Stop(); +} + +unsigned overworld_poison(void) +{ + int i; + unsigned cnt1; + unsigned cnt2; + unsigned hp; + struct Pokemon *pokemon; + + pokemon = gPlayerParty; + cnt2 = 0; + cnt1 = 0; + for (i = 0; i < PARTY_SIZE; i++) + { + if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + { + hp = GetMonData(pokemon, MON_DATA_HP); + if (hp == 0 || --hp == 0) + { + cnt1++; + } + SetMonData(pokemon, MON_DATA_HP, &hp); + cnt2++; + } + pokemon++; + } + if (cnt1 != 0 || cnt2 != 0) + { + overworld_poison_effect(); + } + if (cnt1 != 0) + { + return 2; + } + if (cnt2 != 0) + { + return 1; + } + return 0; +} From 89d938ea9e10a637563a5b4d0d19ddb4535bcf8e Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 13:53:51 -0500 Subject: [PATCH 2/6] Finish decompiling coins --- asm/coins.s | 74 --------------------------------------------------- ld_script.txt | 1 - src/coins.c | 21 +++++++++++---- 3 files changed, 16 insertions(+), 80 deletions(-) delete mode 100644 asm/coins.s diff --git a/asm/coins.s b/asm/coins.s deleted file mode 100644 index d2b6cbb47e..0000000000 --- a/asm/coins.s +++ /dev/null @@ -1,74 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start GiveCoins -@ bool8 GiveCoins(u16 toAdd) -GiveCoins: @ 8145C80 - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl GetCoins - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =0x0000270e - cmp r1, r0 - bls _08145C9C - movs r0, 0 - b _08145CC0 - .pool -_08145C9C: - adds r0, r1, r4 - cmp r1, r0 - ble _08145CAC - ldr r0, =0x0000270f - b _08145CBA - .pool -_08145CAC: - lsls r0, 16 - lsrs r1, r0, 16 - ldr r0, =0x0000270f - cmp r1, r0 - bls _08145CB8 - adds r1, r0, 0 -_08145CB8: - adds r0, r1, 0 -_08145CBA: - bl SetCoins - movs r0, 0x1 -_08145CC0: - pop {r4} - pop {r1} - bx r1 - .pool - thumb_func_end GiveCoins - - thumb_func_start TakeCoins -@ bool8 TakeCoins(u16 toSub) -TakeCoins: @ 8145CCC - push {r4,lr} - lsls r0, 16 - lsrs r4, r0, 16 - bl GetCoins - lsls r0, 16 - lsrs r0, 16 - cmp r0, r4 - bcs _08145CE2 - movs r0, 0 - b _08145CEE -_08145CE2: - subs r0, r4 - lsls r0, 16 - lsrs r0, 16 - bl SetCoins - movs r0, 0x1 -_08145CEE: - pop {r4} - pop {r1} - bx r1 - thumb_func_end TakeCoins - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index e9c810adcf..5292183c31 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -186,7 +186,6 @@ SECTIONS { asm/roulette.o(.text); asm/pokedex_cry_screen.o(.text); src/coins.o(.text); - asm/coins.o(.text); asm/landmark.o(.text); asm/fldeff_strength.o(.text); asm/battle_transition.o(.text); diff --git a/src/coins.c b/src/coins.c index e1694b29ca..e313a42219 100644 --- a/src/coins.c +++ b/src/coins.c @@ -53,7 +53,6 @@ void SetCoins(u16 coinAmount) gSaveBlock1Ptr->coins = coinAmount ^ gSaveBlock2Ptr->encryptionKey; } -/* Can't match it lol bool8 GiveCoins(u16 toAdd) { u16 newAmount; @@ -67,10 +66,22 @@ bool8 GiveCoins(u16 toAdd) } else { - newAmount = ownedCoins + toAdd; - if (newAmount > MAX_COINS) - newAmount = MAX_COINS; + ownedCoins += toAdd; + if (ownedCoins > MAX_COINS) + ownedCoins = MAX_COINS; + newAmount = ownedCoins; } SetCoins(newAmount); return TRUE; -}*/ +} + +bool8 TakeCoins(u16 toSub) +{ + u16 ownedCoins = GetCoins(); + if (ownedCoins >= toSub) + { + SetCoins(ownedCoins - toSub); + return TRUE; + } + return FALSE; +} From c5dcbb78ce0a2fc423190aa743907164b72997a7 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 21:04:15 -0500 Subject: [PATCH 3/6] unk_81BAD84 --- asm/unk_81BAD84.s | 57 ----------------------------------------------- ld_script.txt | 2 +- src/unk_81BAD84.c | 20 +++++++++++++++++ 3 files changed, 21 insertions(+), 58 deletions(-) delete mode 100644 asm/unk_81BAD84.s create mode 100644 src/unk_81BAD84.c diff --git a/asm/unk_81BAD84.s b/asm/unk_81BAD84.s deleted file mode 100644 index 2a95feed49..0000000000 --- a/asm/unk_81BAD84.s +++ /dev/null @@ -1,57 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_81BAD84 -sub_81BAD84: @ 81BAD84 - push {r4-r6,lr} - movs r6, 0x80 - lsls r6, 19 - movs r2, 0 - strh r2, [r6] - ldr r1, =0x04000010 - strh r2, [r1] - adds r1, 0x2 - strh r2, [r1] - adds r1, 0x3E - strh r2, [r1] - ldr r5, =gUnknown_08617128 - lsls r4, r0, 1 - adds r4, r0 - lsls r4, 2 - adds r0, r4, r5 - ldr r0, [r0] - movs r1, 0xC0 - lsls r1, 19 - bl LZ77UnCompVram - adds r0, r5, 0x4 - adds r0, r4, r0 - ldr r0, [r0] - ldr r1, =0x0600f800 - bl LZ77UnCompVram - adds r5, 0x8 - adds r4, r5 - ldr r0, [r4] - movs r1, 0xA0 - lsls r1, 19 - movs r4, 0x80 - lsls r4, 1 - adds r2, r4, 0 - bl CpuSet - ldr r1, =0x04000008 - movs r2, 0xF8 - lsls r2, 5 - adds r0, r2, 0 - strh r0, [r1] - strh r4, [r6] - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81BAD84 - - - .align 2, 0 @ Don't pad with nop. diff --git a/ld_script.txt b/ld_script.txt index e9c810adcf..76125e9e26 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -251,7 +251,7 @@ SECTIONS { asm/battle_tent.o(.text); src/unk_text_util_2.o(.text); src/multiboot.o(.text); - asm/unk_81BAD84.o(.text); + src/unk_81BAD84.o(.text); src/battle_controller_player_partner.o(.text); asm/fldeff_groundshake.o(.text); asm/fossil_specials.o(.text); diff --git a/src/unk_81BAD84.c b/src/unk_81BAD84.c new file mode 100644 index 0000000000..43cb9a4b0c --- /dev/null +++ b/src/unk_81BAD84.c @@ -0,0 +1,20 @@ +#include "global.h" + +extern const struct { + const u8 *unk_0; + const u8 *unk_4; + const u8 *unk_8; +} gUnknown_08617128[]; + +void sub_81BAD84(u32 idx) +{ + REG_DISPCNT = 0x0000; + REG_BG0HOFS = 0x0000; + REG_BG0VOFS = 0x0000; + REG_BLDCNT = 0x0000; + LZ77UnCompVram(gUnknown_08617128[idx].unk_0, (void *)BG_CHAR_ADDR(0)); + LZ77UnCompVram(gUnknown_08617128[idx].unk_4, (void *)BG_SCREEN_ADDR(31)); + CpuCopy16(gUnknown_08617128[idx].unk_8, (void *)PLTT, 0x200); + REG_BG0CNT = 0x1f00; + REG_DISPCNT = DISPCNT_BG0_ON; +} From 772da493f9ea0dcd8838dd927f1b70ff63228c21 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 21:15:57 -0500 Subject: [PATCH 4/6] data/unk_81BAD84 --- data/unk_81BAD84.s | 7 ------- include/graphics.h | 18 ++++++++++++++++++ ld_script.txt | 2 +- src/unk_81BAD84.c | 43 +++++++++++++++++++++++++++++++++++-------- 4 files changed, 54 insertions(+), 16 deletions(-) delete mode 100644 data/unk_81BAD84.s diff --git a/data/unk_81BAD84.s b/data/unk_81BAD84.s deleted file mode 100644 index de88365ac3..0000000000 --- a/data/unk_81BAD84.s +++ /dev/null @@ -1,7 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - -gUnknown_08617128:: @ 8617128 - .incbin "baserom.gba", 0x617128, 0x48 diff --git a/include/graphics.h b/include/graphics.h index c50fdef3f4..4c5a0952b2 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -91,5 +91,23 @@ extern const u8 gUnknown_08DB9F08[]; extern const u8 gUnknown_08DB9FFC[]; extern const u8 gUnknown_08DBA020[]; extern const u8 gUnknown_08DBA12C[]; +extern const u8 gUnknown_08DD87C0[]; +extern const u8 gUnknown_08DD8EE0[]; +extern const u16 gUnknown_08DD8780[]; +extern const u8 gUnknown_08DD90E0[]; +extern const u8 gUnknown_08DD9718[]; +extern const u16 gUnknown_08DD9080[]; +extern const u8 gUnknown_08DD98B4[]; +extern const u8 gUnknown_08DD9E58[]; +extern const u16 gUnknown_08DD9874[]; +extern const u8 gUnknown_08DDA02C[]; +extern const u8 gUnknown_08DDA63C[]; +extern const u16 gUnknown_08DD9FEC[]; +extern const u8 gUnknown_08DDA840[]; +extern const u8 gUnknown_08DDAE40[]; +extern const u16 gUnknown_08DDA800[]; +extern const u8 gUnknown_08DDB020[]; +extern const u8 gUnknown_08DDB2C4[]; +extern const u16 gUnknown_08DDAFE0[]; #endif //GUARD_GRAPHICS_H diff --git a/ld_script.txt b/ld_script.txt index 76125e9e26..ee423ccf3d 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -472,7 +472,7 @@ SECTIONS { data/party_menu.o(.rodata); data/battle_tent.o(.rodata); src/unk_text_util_2.o(.rodata); - data/unk_81BAD84.o(.rodata); + src/unk_81BAD84.o(.rodata); src/battle_controller_player_partner.o(.rodata); data/fossil_special_fldeff_groundshake.o(.rodata); src/berry_fix_program.o(.rodata); diff --git a/src/unk_81BAD84.c b/src/unk_81BAD84.c index 43cb9a4b0c..9ba98dd87a 100644 --- a/src/unk_81BAD84.c +++ b/src/unk_81BAD84.c @@ -1,10 +1,37 @@ #include "global.h" +#include "graphics.h" -extern const struct { - const u8 *unk_0; - const u8 *unk_4; - const u8 *unk_8; -} gUnknown_08617128[]; +const struct { + const u8 *gfx; + const u8 *tileMap; + const u16 *pltt; +} gUnknown_08617128[] = { + { + gUnknown_08DD87C0, + gUnknown_08DD8EE0, + gUnknown_08DD8780 + }, { + gUnknown_08DD90E0, + gUnknown_08DD9718, + gUnknown_08DD9080 + }, { + gUnknown_08DD98B4, + gUnknown_08DD9E58, + gUnknown_08DD9874 + }, { + gUnknown_08DDA02C, + gUnknown_08DDA63C, + gUnknown_08DD9FEC + }, { + gUnknown_08DDA840, + gUnknown_08DDAE40, + gUnknown_08DDA800 + }, { + gUnknown_08DDB020, + gUnknown_08DDB2C4, + gUnknown_08DDAFE0 + } +}; void sub_81BAD84(u32 idx) { @@ -12,9 +39,9 @@ void sub_81BAD84(u32 idx) REG_BG0HOFS = 0x0000; REG_BG0VOFS = 0x0000; REG_BLDCNT = 0x0000; - LZ77UnCompVram(gUnknown_08617128[idx].unk_0, (void *)BG_CHAR_ADDR(0)); - LZ77UnCompVram(gUnknown_08617128[idx].unk_4, (void *)BG_SCREEN_ADDR(31)); - CpuCopy16(gUnknown_08617128[idx].unk_8, (void *)PLTT, 0x200); + LZ77UnCompVram(gUnknown_08617128[idx].gfx, (void *)BG_CHAR_ADDR(0)); + LZ77UnCompVram(gUnknown_08617128[idx].tileMap, (void *)BG_SCREEN_ADDR(31)); + CpuCopy16(gUnknown_08617128[idx].pltt, (void *)PLTT, 0x200); REG_BG0CNT = 0x1f00; REG_DISPCNT = DISPCNT_BG0_ON; } From da04898840083653835db7ca997b6d57f1d3c353 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 23 Nov 2017 23:10:51 -0500 Subject: [PATCH 5/6] Clean up includes --- include/strings.h | 1 + src/coins.c | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/strings.h b/include/strings.h index 08e2b4bba8..a32ba4c83d 100644 --- a/include/strings.h +++ b/include/strings.h @@ -82,5 +82,6 @@ extern const u8 gText_NoRegistry[]; extern const u8 gText_OkayToDeleteFromRegistry[]; extern const u8 gText_RegisteredDataDeleted[]; extern const u8 gUnknown_085EA79D[]; +extern const u8 gText_Coins[]; #endif //GUARD_STRINGS_H diff --git a/src/coins.c b/src/coins.c index e313a42219..50c31cac01 100644 --- a/src/coins.c +++ b/src/coins.c @@ -2,8 +2,9 @@ #include "coins.h" #include "text.h" #include "window.h" -#include "text_window.h" +#include "strings.h" #include "string_util.h" +#include "new_menu_helpers.h" #include "menu.h" #include "international_string_util.h" @@ -11,10 +12,6 @@ EWRAM_DATA u8 sCoinsWindowId = 0; -extern void sub_819746C(u8 windowId, bool8 copyToVram); - -extern const u8 gText_Coins[]; - void PrintCoinsString(u32 coinAmount) { u32 xAlign; From 921011592cbe9018f558b7977525e49252274947 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 29 Nov 2017 08:30:18 -0500 Subject: [PATCH 6/6] unsigned -> unsigned int; create header --- include/battle.h | 1 + include/field_poison.h | 19 ++++++++++++++++ include/party_menu.h | 9 ++++++++ src/field_poison.c | 51 +++++++++++++++++------------------------- 4 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 include/field_poison.h diff --git a/include/battle.h b/include/battle.h index c172cb0f66..3f39db3746 100644 --- a/include/battle.h +++ b/include/battle.h @@ -88,6 +88,7 @@ #define BATTLE_OUTCOME_BIT_x80 0x80 +#define STATUS_NONE 0x0 #define STATUS_SLEEP 0x7 #define STATUS_POISON 0x8 #define STATUS_BURN 0x10 diff --git a/include/field_poison.h b/include/field_poison.h new file mode 100644 index 0000000000..d1a4c823b8 --- /dev/null +++ b/include/field_poison.h @@ -0,0 +1,19 @@ +#ifndef GUARD_FIELD_POISON_H +#define GUARD_FIELD_POISON_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations + +enum { + FLDPSN_NONE, + FLDPSN_PSN, + FLDPSN_FNT +}; + +void sub_80F972C(void); +unsigned int overworld_poison(void); + +#endif //GUARD_FIELD_POISON_H diff --git a/include/party_menu.h b/include/party_menu.h index 0249711931..c787bafb1a 100644 --- a/include/party_menu.h +++ b/include/party_menu.h @@ -1,6 +1,15 @@ #ifndef GUARD_PARTY_MENU_H #define GUARD_PARTY_MENU_H +enum { + AILMENT_NONE, + AILMENT_PSN, + AILMENT_PRZ, + AILMENT_SLP, + AILMENT_FRZ, + AILMENT_BRN +}; + bool8 pokemon_has_move(struct Pokemon *, u16); void sub_81B58A8(void); void DoWallyTutorialBagMenu(void); diff --git a/src/field_poison.c b/src/field_poison.c index f9d7b16096..d953ab29c6 100644 --- a/src/field_poison.c +++ b/src/field_poison.c @@ -10,7 +10,9 @@ #include "pokenav.h" #include "event_data.h" #include "script.h" +#include "battle.h" #include "fldeff_80F9BCC.h" +#include "field_poison.h" static bool32 sub_80F9568(struct Pokemon *pokemon) { @@ -39,11 +41,8 @@ static bool32 sub_80F958C(void) static void sub_80F95C0(u8 partyIdx) { - struct Pokemon *pokemon; - unsigned status; - - pokemon = &gPlayerParty[partyIdx]; - status = 0; + struct Pokemon *pokemon = gPlayerParty + partyIdx; + unsigned int status = STATUS_NONE; AdjustFriendship(pokemon, 0x07); SetMonData(pokemon, MON_DATA_STATUS, &status); GetMonData(pokemon, MON_DATA_NICKNAME, gStringVar1); @@ -52,10 +51,8 @@ static void sub_80F95C0(u8 partyIdx) static bool32 sub_80F960C(u8 partyIdx) { - struct Pokemon *pokemon; - - pokemon = &gPlayerParty[partyIdx]; - if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + struct Pokemon *pokemon = gPlayerParty + partyIdx; + if (sub_80F9568(pokemon) && GetMonData(pokemon, MON_DATA_HP) == 0 && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) { return TRUE; } @@ -64,9 +61,7 @@ static bool32 sub_80F960C(u8 partyIdx) static void sub_80F9654(u8 taskId) { - s16 *data; - - data = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; switch (data[0]) { case 0: @@ -116,42 +111,38 @@ void sub_80F972C(void) ScriptContext1_Stop(); } -unsigned overworld_poison(void) +unsigned int overworld_poison(void) { int i; - unsigned cnt1; - unsigned cnt2; - unsigned hp; - struct Pokemon *pokemon; - - pokemon = gPlayerParty; - cnt2 = 0; - cnt1 = 0; + unsigned int hp; + struct Pokemon *pokemon = gPlayerParty; + unsigned int numPoisoned = 0; + unsigned int numFainted = 0; for (i = 0; i < PARTY_SIZE; i++) { - if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == 1) + if (GetMonData(pokemon, MON_DATA_SANITY_BIT2) && pokemon_ailments_get_primary(GetMonData(pokemon, MON_DATA_STATUS)) == AILMENT_PSN) { hp = GetMonData(pokemon, MON_DATA_HP); if (hp == 0 || --hp == 0) { - cnt1++; + numFainted++; } SetMonData(pokemon, MON_DATA_HP, &hp); - cnt2++; + numPoisoned++; } pokemon++; } - if (cnt1 != 0 || cnt2 != 0) + if (numFainted != 0 || numPoisoned != 0) { overworld_poison_effect(); } - if (cnt1 != 0) + if (numFainted != 0) { - return 2; + return FLDPSN_FNT; } - if (cnt2 != 0) + if (numPoisoned != 0) { - return 1; + return FLDPSN_PSN; } - return 0; + return FLDPSN_NONE; }