From 4bf09504216c1c9668843cc93b5392cd1022a4c1 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 2 May 2018 08:43:27 -0400 Subject: [PATCH] through sub_80D7DE8 --- asm/contest.s | 212 +----------------------------- asm/contest_link_80FC4F4.s | 2 +- asm/contest_link_81D9DE4.s | 2 +- asm/script_pokemon_util_80F87D8.s | 4 +- common_syms/contest.txt | 1 + include/contest.h | 2 + include/contest_link_80F57C4.h | 1 + src/contest.c | 97 +++++++++++++- src/item.c | 2 + sym_common.txt | 4 +- sym_ewram.txt | 9 +- 11 files changed, 105 insertions(+), 231 deletions(-) create mode 100644 common_syms/contest.txt diff --git a/asm/contest.s b/asm/contest.s index 2a72e9f72..0fa75185c 100644 --- a/asm/contest.s +++ b/asm/contest.s @@ -5,216 +5,6 @@ .text - thumb_func_start sub_80D7C7C -sub_80D7C7C: @ 80D7C7C - push {lr} - lsls r0, 24 - lsrs r3, r0, 24 - ldr r0, =gPaletteFade - ldrb r1, [r0, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0 - bne _080D7CA2 - ldr r0, =gTasks - lsls r1, r3, 2 - adds r1, r3 - lsls r1, 3 - adds r1, r0 - strh r2, [r1, 0x8] - ldr r0, =sub_80D7CB4 - str r0, [r1] -_080D7CA2: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D7C7C - - thumb_func_start sub_80D7CB4 -sub_80D7CB4: @ 80D7CB4 - push {r4-r6,lr} - lsls r0, 24 - lsrs r5, r0, 24 - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080D7D90 - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _080D7D3A - ldr r2, =gTasks - lsls r1, r5, 2 - adds r0, r1, r5 - lsls r0, 3 - adds r4, r0, r2 - movs r2, 0x8 - ldrsh r0, [r4, r2] - adds r6, r1, 0 - cmp r0, 0x1 - beq _080D7D04 - cmp r0, 0x1 - bgt _080D7CF4 - cmp r0, 0 - beq _080D7CFA - b _080D7D3A - .pool -_080D7CF4: - cmp r0, 0x2 - beq _080D7D28 - b _080D7D3A -_080D7CFA: - bl sub_80DBF68 - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] -_080D7D04: - bl sub_800A520 - lsls r0, 24 - cmp r0, 0 - beq _080D7D9E - bl sub_800ADF8 - ldr r0, =gTasks - adds r1, r6, r5 - lsls r1, 3 - adds r1, r0 - ldrh r0, [r1, 0x8] - adds r0, 0x1 - strh r0, [r1, 0x8] - b _080D7D9E - .pool -_080D7D28: - bl sub_800A520 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080D7D9E - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] -_080D7D3A: - ldr r2, =gPaletteFade - ldrb r1, [r2, 0x7] - movs r0, 0x80 - ands r0, r1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0 - bne _080D7D9E - ldrb r1, [r2, 0x8] - movs r0, 0x7F - ands r0, r1 - strb r0, [r2, 0x8] - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - bne _080D7D62 - bl sub_80DBF68 -_080D7D62: - ldr r0, =sub_80D7DAC - movs r1, 0 - bl CreateTask - ldr r1, =gTasks - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - adds r0, r1 - strh r4, [r0, 0x8] - ldr r1, =TaskDummy1 - str r1, [r0] - b _080D7D9E - .pool -_080D7D90: - ldr r0, =gTasks - lsls r1, r5, 2 - adds r1, r5 - lsls r1, 3 - adds r1, r0 - ldr r0, =sub_80D80C8 - str r0, [r1] -_080D7D9E: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D7CB4 - - thumb_func_start sub_80D7DAC -sub_80D7DAC: @ 80D7DAC - push {lr} - lsls r0, 24 - lsrs r0, 24 - ldr r1, =sub_80FC998 - ldr r2, =sub_80D7DC8 - bl SetTaskFuncWithFollowupFunc - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D7DAC - - thumb_func_start sub_80D7DC8 -sub_80D7DC8: @ 80D7DC8 - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - movs r0, 0x1 - strh r0, [r1, 0x8] - ldr r0, =sub_80D7DE8 - str r0, [r1] - bx lr - .pool - thumb_func_end sub_80D7DC8 - - thumb_func_start sub_80D7DE8 -sub_80D7DE8: @ 80D7DE8 - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r5, =gTasks - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - adds r0, r5 - ldrh r1, [r0, 0x8] - subs r1, 0x1 - strh r1, [r0, 0x8] - lsls r1, 16 - cmp r1, 0 - bgt _080D7E2A - bl GetMultiplayerId - adds r0, r4, 0 - bl DestroyTask - ldr r0, =gContestResources - ldr r0, [r0] - ldr r0, [r0] - ldrb r1, [r0, 0x8] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r5 - ldr r1, =sub_80D80C8 - str r1, [r0] - ldr r1, =gRngValue - ldr r0, =gUnknown_030060B8 - ldr r0, [r0] - str r0, [r1] -_080D7E2A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80D7DE8 - thumb_func_start sub_80D7E44 sub_80D7E44: @ 80D7E44 push {r4-r7,lr} @@ -4722,7 +4512,7 @@ _080DA65C: bl sub_80DF4F8 bl sub_80DF750 _080DA668: - ldr r1, =gUnknown_030060B8 + ldr r1, =gContestRngValue ldr r0, =gRngValue ldr r0, [r0] str r0, [r1] diff --git a/asm/contest_link_80FC4F4.s b/asm/contest_link_80FC4F4.s index 3ba383f0b..3912731ec 100644 --- a/asm/contest_link_80FC4F4.s +++ b/asm/contest_link_80FC4F4.s @@ -434,7 +434,7 @@ _080FC858: adds r1, r4, 0 movs r2, 0x4 bl memcpy - ldr r0, =gUnknown_030060B8 + ldr r0, =gContestRngValue adds r1, r4, 0 movs r2, 0x4 bl memcpy diff --git a/asm/contest_link_81D9DE4.s b/asm/contest_link_81D9DE4.s index 4f392587a..35191e10f 100644 --- a/asm/contest_link_81D9DE4.s +++ b/asm/contest_link_81D9DE4.s @@ -558,7 +558,7 @@ _081DA2AC: adds r1, r4, 0 movs r2, 0x4 bl memcpy - ldr r0, =gUnknown_030060B8 + ldr r0, =gContestRngValue adds r1, r4, 0 movs r2, 0x4 bl memcpy diff --git a/asm/script_pokemon_util_80F87D8.s b/asm/script_pokemon_util_80F87D8.s index eeb50cd84..917d02cd0 100644 --- a/asm/script_pokemon_util_80F87D8.s +++ b/asm/script_pokemon_util_80F87D8.s @@ -979,7 +979,7 @@ sub_80F8FE8: @ 80F8FE8 ands r0, r1 cmp r0, 0 beq _080F9020 - ldr r2, =gUnknown_030060B8 + ldr r2, =gContestRngValue ldr r1, [r2] ldr r0, =0x41c64e6d muls r0, r1 @@ -1007,7 +1007,7 @@ _080F902A: thumb_func_start sub_80F903C sub_80F903C: @ 80F903C - ldr r2, =gUnknown_030060B8 + ldr r2, =gContestRngValue ldr r1, [r2] ldr r0, =0x41c64e6d muls r0, r1 diff --git a/common_syms/contest.txt b/common_syms/contest.txt new file mode 100644 index 000000000..6a519fb46 --- /dev/null +++ b/common_syms/contest.txt @@ -0,0 +1 @@ +gContestRngValue diff --git a/include/contest.h b/include/contest.h index 80b681cef..250929de7 100644 --- a/include/contest.h +++ b/include/contest.h @@ -405,6 +405,8 @@ struct ContestResources extern struct ContestResources *gContestResources; +extern u32 gContestRngValue; + bool8 IsSpeciesNotUnown(u16 species); void LoadContestBgAfterMoveAnim(void); diff --git a/include/contest_link_80F57C4.h b/include/contest_link_80F57C4.h index 98523c175..3c12e5e53 100644 --- a/include/contest_link_80F57C4.h +++ b/include/contest_link_80F57C4.h @@ -4,5 +4,6 @@ void sub_80F840C(void); void sub_80F8484(void); void sub_80F84C4(u8); +void sub_80FC998(u8 taskId); #endif // GUARD_CONTEST_LINK_80F57C4_H diff --git a/src/contest.c b/src/contest.c index 2e61b4629..2c56eb14c 100644 --- a/src/contest.c +++ b/src/contest.c @@ -30,18 +30,25 @@ #include "tv.h" #include "scanline_effect.h" #include "util.h" +#include "contest_link_80F57C4.h" #define DESTROY_POINTER(ptr) \ free(ptr); \ ptr = NULL; -void sub_80DD590(void); void sub_80D782C(void); +void sub_80D7C7C(u8 taskId); +void sub_80D7CB4(u8 taskId); +void sub_80D7DAC(u8 taskId); +void sub_80D7DC8(u8 taskId); +void sub_80D7DE8(u8 taskId); +void sub_80D80C8(u8 taskId); +void sub_80D823C(void); +void sub_80DBF68(void); void sub_80DCE58(u8); +void sub_80DD590(void); bool8 sub_80D7E44(u8 *); void sub_80DE224(void); -void sub_80D7C7C(u8 taskId); -void sub_80D823C(void); void vblank_cb_battle(void); EWRAM_DATA struct ContestPokemon gContestMons[4] = {0}; @@ -53,7 +60,9 @@ EWRAM_DATA u8 gContestFinalStandings[4] = {0}; EWRAM_DATA u8 gUnknown_02039F24 = 0; EWRAM_DATA u8 gContestPlayerMonIndex = 0; EWRAM_DATA u8 gUnknown_02039F26[4] = {0}; -EWRAM_DATA bool8 gIsLinkContest = FALSE; +EWRAM_DATA u8 gIsLinkContest = 0; +// Bit 0: Is a link contest +// Bit 1: Link contest uses wireless adapter EWRAM_DATA u8 gUnknown_02039F2B = 0; EWRAM_DATA u16 gSpecialVar_ContestCategory = 0; EWRAM_DATA u16 gSpecialVar_ContestRank = 0; @@ -61,6 +70,9 @@ EWRAM_DATA u8 gUnknown_02039F30 = 0; EWRAM_DATA u8 gUnknown_02039F31 = 0; EWRAM_DATA struct ContestResources * gContestResources = NULL; EWRAM_DATA u8 gUnknown_02039F38 = 0; +EWRAM_DATA struct ContestWinner gUnknown_02039F3C = {0}; + +u32 gContestRngValue; extern u16 gBattle_BG0_X; extern u16 gBattle_BG0_Y; @@ -89,7 +101,7 @@ void TaskDummy1(u8 taskId) void ResetLinkContestBoolean(void) { - gIsLinkContest = FALSE; + gIsLinkContest = 0; } void sub_80D7678(void) @@ -309,3 +321,78 @@ void sub_80D7B24(void) } } +void sub_80D7C7C(u8 taskId) +{ + if (!gPaletteFade.active) + { + gTasks[taskId].data[0] = 0; + gTasks[taskId].func = sub_80D7CB4; + } +} + +void sub_80D7CB4(u8 taskId) +{ + if (gIsLinkContest & 1) + { + if (gIsLinkContest & 2) + { + switch (gTasks[taskId].data[0]) + { + case 0: + sub_80DBF68(); + gTasks[taskId].data[0]++; + // fallthrough + case 1: + if (sub_800A520()) + { + sub_800ADF8(); + gTasks[taskId].data[0]++; + } + return; + case 2: + if (sub_800A520() != TRUE) + return; + gTasks[taskId].data[0]++; + break; + } + } + + if (!gPaletteFade.active) + { + gPaletteFade.bufferTransferDisabled = FALSE; + if (!(gIsLinkContest & 2)) + sub_80DBF68(); + CreateTask(sub_80D7DAC, 0); + gTasks[taskId].data[0] = 0; + gTasks[taskId].func = TaskDummy1; + } + } + else + { + gTasks[taskId].func = sub_80D80C8; + } +} + +void sub_80D7DAC(u8 taskId) +{ + SetTaskFuncWithFollowupFunc(taskId, sub_80FC998, sub_80D7DC8); +} + +void sub_80D7DC8(u8 taskId) +{ + gTasks[taskId].data[0] = 1; + gTasks[taskId].func = sub_80D7DE8; +} + +void sub_80D7DE8(u8 taskId) +{ + gTasks[taskId].data[0]--; + if (gTasks[taskId].data[0] <= 0) + { + GetMultiplayerId(); // unused return value + DestroyTask(taskId); + gTasks[gContestResources->field_0->mainTaskId].func = sub_80D80C8; + gRngValue = gContestRngValue; + } +} + diff --git a/src/item.c b/src/item.c index a17599db9..0c60c417d 100644 --- a/src/item.c +++ b/src/item.c @@ -25,6 +25,8 @@ enum KEYITEMS_POCKET }; +EWRAM_DATA struct BagPocket gBagPockets[5] = {}; + u16 GetBagItemQuantity(u16* quantity) { return gSaveBlock2Ptr->encryptionKey ^ *quantity; diff --git a/sym_common.txt b/sym_common.txt index b0548a84c..c59c30102 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -83,9 +83,7 @@ gUnknown_030060B0: @ 30060B0 gUnknown_030060B4: @ 30060B4 .space 0x4 -gUnknown_030060B8: @ 30060B8 - .space 0x4 - + .include "contest.o" .include "tv.o" gUnknown_03006130: @ 3006130 diff --git a/sym_ewram.txt b/sym_ewram.txt index d4a2ba4b6..ad1757eaa 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -414,17 +414,10 @@ gUnknown_02039DD0: @ 2039DD0 .space 0x4 .include "src/map_name_popup.o" - .space 0x3 - -gBagPockets: @ 2039DD8 - .space 0x28 - + .include "src/item.o" .include "src/contest.o" .align 2 -gUnknown_02039F3C: @ 2039F3C - .space 0x20 - gUnknown_02039F5C: @ 2039F5C .space 0x1