From c05444679059e0692275781d065d36e79610cc4c Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 10:15:58 -0400 Subject: [PATCH] through sub_80E715C --- asm/cable_club.s | 2 +- asm/link.s | 26 +++-- asm/record_mixing.s | 241 +-------------------------------------- include/cable_club.h | 1 + include/field_screen.h | 1 + include/fldeff_80F9BCC.h | 2 + include/link.h | 3 +- include/overworld.h | 1 + include/strings.h | 1 + src/record_mixing.c | 114 ++++++++++++++++-- 10 files changed, 134 insertions(+), 258 deletions(-) diff --git a/asm/cable_club.s b/asm/cable_club.s index 15ba76e9c..80c177d20 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -795,7 +795,7 @@ sub_80B2A08: @ 80B2A08 ldrh r0, [r0] cmp r0, 0x4 bne _080B2A38 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 bne _080B2A4A bl sub_800AC34 diff --git a/asm/link.s b/asm/link.s index 291f71a57..840b153e7 100644 --- a/asm/link.s +++ b/asm/link.s @@ -1394,8 +1394,10 @@ _08009FF4: bx r1 thumb_func_end GetLinkPlayerCount - thumb_func_start sub_8009FF8 -sub_8009FF8: @ 8009FF8 + thumb_func_start LinkPartnerVersionCheck +LinkPartnerVersionCheck: @ 8009FF8 +@ s32 LinkPartnerVersionCheck(u32 version1, u32 version2) +@ returns 1 if any link partners are playing either version1 or version2, -1 if no link partners are playing either version1 or version2 push {r4-r7,lr} adds r6, r0, 0 adds r5, r1, 0 @@ -1431,7 +1433,7 @@ _0800A034: pop {r4-r7} pop {r1} bx r1 - thumb_func_end sub_8009FF8 + thumb_func_end LinkPartnerVersionCheck thumb_func_start sub_800A03C sub_800A03C: @ 800A03C @@ -1439,8 +1441,8 @@ sub_800A03C: @ 800A03C bx lr thumb_func_end sub_800A03C - thumb_func_start sub_800A040 -sub_800A040: @ 800A040 + thumb_func_start Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire +Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire: @ 800A040 push {lr} bl GetLinkPlayerCount lsls r0, 24 @@ -1449,7 +1451,7 @@ sub_800A040: @ 800A040 bne _0800A05A movs r0, 0x2 movs r1, 0x1 - bl sub_8009FF8 + bl LinkPartnerVersionCheck cmp r0, 0 bge _0800A05E _0800A05A: @@ -1460,14 +1462,14 @@ _0800A05E: _0800A060: pop {r1} bx r1 - thumb_func_end sub_800A040 + thumb_func_end Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire - thumb_func_start sub_800A064 -sub_800A064: @ 800A064 + thumb_func_start Link_AnyPartnersPlayingRubyOrSapphrie +Link_AnyPartnersPlayingRubyOrSapphrie: @ 800A064 push {lr} movs r0, 0x2 movs r1, 0x1 - bl sub_8009FF8 + bl LinkPartnerVersionCheck cmp r0, 0 bge _0800A076 movs r0, 0 @@ -1477,14 +1479,14 @@ _0800A076: _0800A078: pop {r1} bx r1 - thumb_func_end sub_800A064 + thumb_func_end Link_AnyPartnersPlayingRubyOrSapphrie thumb_func_start sub_800A07C sub_800A07C: @ 800A07C push {lr} movs r0, 0x4 movs r1, 0x5 - bl sub_8009FF8 + bl LinkPartnerVersionCheck adds r2, r0, 0 cmp r2, 0 blt _0800A0A4 diff --git a/asm/record_mixing.s b/asm/record_mixing.s index bc1b27bd4..ebfc0eff4 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,237 +5,6 @@ .text - thumb_func_start sub_80E70F4 -sub_80E70F4: @ 80E70F4 - push {r4,lr} - sub sp, 0xC - adds r4, r0, 0 - movs r0, 0 - movs r1, 0 - bl sub_81973C4 - movs r0, 0x1 - str r0, [sp] - movs r0, 0 - str r0, [sp, 0x4] - str r0, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - movs r3, 0 - bl PrintTextOnWindow - movs r0, 0 - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_80E70F4 - - thumb_func_start sub_80E7128 -sub_80E7128: @ 80E7128 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x32 - bne _080E7150 - movs r0, 0xE2 - bl PlaySE - movs r0, 0 - strh r0, [r4, 0x8] -_080E7150: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7128 - - thumb_func_start sub_80E715C -sub_80E715C: @ 80E715C - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r5, r0, r1 - movs r1, 0 - ldrsh r0, [r5, r1] - cmp r0, 0x5 - bls _080E7176 - b _080E730A -_080E7176: - lsls r0, 2 - ldr r1, =_080E7188 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080E7188: - .4byte _080E71A0 - .4byte _080E7218 - .4byte _080E724C - .4byte _080E726C - .4byte _080E72AC - .4byte _080E72C0 -_080E71A0: - ldr r4, =gUnknown_0203A018 - ldr r0, =0x00001444 - bl Alloc - str r0, [r4] - ldr r4, =gUnknown_0203A014 - ldr r0, =0x00005110 - bl Alloc - str r0, [r4] - ldr r0, =gSpecialVar_0x8005 - ldrb r0, [r0] - bl sub_8009628 - movs r0, 0x80 - lsls r0, 7 - movs r1, 0x1 - bl VarSet - ldr r1, =gUnknown_03001130 - movs r0, 0 - strb r0, [r1] - bl sub_80E6E24 - bl sub_80FB00C - movs r0, 0x1 - strh r0, [r5] - ldr r0, =sub_80E7324 - movs r1, 0x50 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] - ldr r0, =sub_80E7128 - movs r1, 0x51 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x1E] - b _080E730A - .pool -_080E7218: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _080E730A - movs r0, 0x2 - strh r0, [r5] - ldr r0, =0x00000894 - bl FlagSet - bl sub_80FB074 - ldrb r0, [r5, 0x1E] - bl DestroyTask - b _080E730A - .pool -_080E724C: - ldr r0, =sub_80E7FF8 - movs r1, 0xA - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] - movs r0, 0x3 - strh r0, [r5] - movs r0, 0xE0 - bl PlaySE - b _080E730A - .pool -_080E726C: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r4, [r0, 0x4] - cmp r4, 0 - bne _080E730A - movs r0, 0x4 - strh r0, [r5] - ldr r0, =gLinkVSyncDisabled - ldrb r0, [r0] - cmp r0, 0 - bne _080E7296 - bl sub_80B3050 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] -_080E7296: - ldr r0, =gText_RecordMixingComplete - bl sub_80E70F4 - strh r4, [r5, 0x10] - b _080E730A - .pool -_080E72AC: - ldrh r0, [r5, 0x10] - adds r0, 0x1 - strh r0, [r5, 0x10] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x3C - ble _080E730A - movs r0, 0x5 - strh r0, [r5] - b _080E730A -_080E72C0: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _080E730A - ldr r0, =gUnknown_0203A014 - ldr r0, [r0] - bl Free - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - bl Free - bl sub_808729C - ldr r0, =gLinkVSyncDisabled - ldrb r0, [r0] - cmp r0, 0 - beq _080E72F8 - ldr r0, =sub_80AF2B4 - movs r1, 0xA - bl CreateTask -_080E72F8: - movs r0, 0 - movs r1, 0x1 - bl sub_8197434 - adds r0, r4, 0 - bl DestroyTask - bl EnableBothScriptContexts -_080E730A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E715C - thumb_func_start sub_80E7324 sub_80E7324: @ 80E7324 push {r4-r6,lr} @@ -431,7 +200,7 @@ _080E7490: strh r0, [r5, 0x12] ldr r0, =sub_80E756C str r0, [r5] - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E7504 ldr r0, =gUnknown_0203A018 @@ -963,7 +732,7 @@ sub_80E78C4: @ 80E78C4 adds r0, r2 ldrb r4, [r0] ldrh r5, [r0, 0x1A] - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E7910 adds r0, r6, 0 @@ -1013,7 +782,7 @@ sub_80E7948: @ 80E7948 lsrs r6, r2, 24 mov r0, sp bl sub_80E7830 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E79AC lsls r0, r6, 2 @@ -1330,7 +1099,7 @@ _080E7BB0: mov r8, r0 cmp r0, 0x3 bls _080E7BB0 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie str r0, [sp, 0x3C] movs r2, 0 mov r8, r2 @@ -1887,7 +1656,7 @@ _080E8024: .4byte _080E80EE .4byte _080E80FA _080E804C: - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 bne _080E80F2 movs r0, 0x6 diff --git a/include/cable_club.h b/include/cable_club.h index adb0c4f90..44831235c 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -8,5 +8,6 @@ // Exported ROM declarations void sub_80B37D4(TaskFunc taskFunc); +u8 sub_80B3050(void); #endif //GUARD_CABLE_CLUB_H diff --git a/include/field_screen.h b/include/field_screen.h index 089e79cc4..6e33a8b7b 100644 --- a/include/field_screen.h +++ b/include/field_screen.h @@ -9,5 +9,6 @@ void pal_fill_black(void); bool8 sub_80ABDFC(void); void sub_80AF168(void); +void sub_80AF2B4(u8 taskId); #endif //GUARD_FIELD_SCREEN_H diff --git a/include/fldeff_80F9BCC.h b/include/fldeff_80F9BCC.h index ecce04943..aae4751c1 100644 --- a/include/fldeff_80F9BCC.h +++ b/include/fldeff_80F9BCC.h @@ -9,5 +9,7 @@ void sub_80FA5E4(s16 id, s16 x, s16 y); void sub_80FA794(s16 x, s16 y); +void sub_80FB00C(void); +void sub_80FB074(void); #endif //GUARD_FLDEFF_80F9BCC_H diff --git a/include/link.h b/include/link.h index 1bcdb047c..6e60a1a84 100644 --- a/include/link.h +++ b/include/link.h @@ -192,7 +192,8 @@ void sub_8011BD0(void); u8 sub_800ABAC(void); u8 sub_800ABBC(void); void sub_800AC34(void); -bool32 sub_800A064(void); +bool32 Link_AnyPartnersPlayingRubyOrSapphrie(void); bool32 sub_800A03C(void); +void sub_8009628(u8); #endif // GUARD_LINK_H diff --git a/include/overworld.h b/include/overworld.h index 19bcaaf01..63c54eee3 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -64,5 +64,6 @@ void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpNum); void c2_load_new_map(void); void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void mapldr_default(void); +void sub_808729C(void); #endif //GUARD_ROM4_H diff --git a/include/strings.h b/include/strings.h index fcdb1eca4..735fc1f1c 100644 --- a/include/strings.h +++ b/include/strings.h @@ -75,5 +75,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_RecordMixingComplete[]; #endif //GUARD_STRINGS_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 4853afb29..902dcde1d 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1,19 +1,30 @@ // Includes #include "global.h" +#include "malloc.h" #include "task.h" #include "cable_club.h" #include "link.h" #include "tv.h" #include "battle_tower.h" +#include "new_menu_helpers.h" +#include "window.h" #include "mystery_event_script.h" #include "secret_base.h" #include "mauville_old_man.h" +#include "sound.h" +#include "songs.h" +#include "overworld.h" +#include "field_screen.h" +#include "fldeff_80F9BCC.h" +#include "script.h" +#include "event_data.h" +#include "strings.h" #include "record_mixing.h" // Static type declarations -struct RecordMixingData { +struct PlayerRecords { /* 0x0000 */ struct SecretBaseRecord secretBases[20]; /* 0x0c80 */ TVShow tvShows[25]; /* 0x1004 */ PokeNews pokeNews[16]; @@ -47,18 +58,20 @@ IWRAM_DATA u8 gUnknown_03001160[8]; IWRAM_DATA u32 gUnknown_03001168[3]; EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; -EWRAM_DATA struct RecordMixingData *gUnknown_0203A014 = NULL; -EWRAM_DATA struct RecordMixingData *gUnknown_0203A018 = NULL; +EWRAM_DATA struct PlayerRecords *gUnknown_0203A014 = NULL; +EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; // Static ROM declarations -void sub_80E715C(u8 taskId); +static void sub_80E715C(u8 taskId); +void sub_80E7324(u8 taskId); void sub_80E78C4(OldMan *, size_t, u8); void sub_80E7948(void *, size_t, u8); void sub_80E7A14(LilycoveLady *, size_t, u8); void sub_80E7B2C(TVShow *); void sub_80E7B60(void *, size_t, u8, TVShow *); void sub_80E7F68(void *, u8); +void sub_80E7FF8(u8 taskId); void sub_80E8110(void *, void *); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); @@ -94,7 +107,7 @@ void sub_80E6BF8(void) gUnknown_03001158 = gSaveBlock2Ptr->field_64C; } -void sub_80E6CA0(struct RecordMixingData *dest) +void sub_80E6CA0(struct PlayerRecords *dest) { memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); @@ -110,7 +123,7 @@ void sub_80E6CA0(struct RecordMixingData *dest) } } -void sub_80E6D54(struct RecordMixingData *dest) +void sub_80E6D54(struct PlayerRecords *dest) { memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); sub_80EB18C(dest->secretBases); @@ -135,7 +148,7 @@ void sub_80E6E24(void) sub_80E9914(); sub_80F0BB8(); sub_80E6BF8(); - if (sub_800A064()) + if (Link_AnyPartnersPlayingRubyOrSapphrie()) { if (sub_800A03C() == FALSE) { @@ -168,7 +181,7 @@ void sub_80E6E24(void) void sub_80E6F60(u32 a0) { - if (sub_800A064()) + if (Link_AnyPartnersPlayingRubyOrSapphrie()) { // Ruby/Sapphire sub_80E7B2C(gUnknown_0203A014[0].tvShows); @@ -198,3 +211,88 @@ void sub_80E6F60(u32 a0) sub_80E89AC(gUnknown_0203A014[0].unk_12dc, 0x1444, a0); } } + +void sub_80E70F4(const u8 *src) +{ + sub_81973C4(0, 0); + PrintTextOnWindow(0, 1, src, 0, 1, 0, NULL); + CopyWindowToVram(0, 3); +} + +void sub_80E7128(u8 taskId) +{ + if (++ gTasks[taskId].data[0] == 50) + { + PlaySE(SE_W213); + gTasks[taskId].data[0] = 0; + } +} + +static void sub_80E715C(u8 taskId) +{ + s16 *data; + + data = gTasks[taskId].data; + switch (data[0]) + { + case 0: + gUnknown_0203A018 = malloc(sizeof(struct PlayerRecords)); + gUnknown_0203A014 = malloc(sizeof(struct PlayerRecords) * 4); + sub_8009628(gSpecialVar_0x8005); + VarSet(VAR_0x4000, 1); + gUnknown_03001130 = FALSE; + sub_80E6E24(); + sub_80FB00C(); + data[0] = 1; + data[10] = CreateTask(sub_80E7324, 80); + data[15] = CreateTask(sub_80E7128, 81); + break; + case 1: + if (!gTasks[data[10]].isActive) + { + data[0] = 2; + FlagSet(SYS_MIX_RECORD); + sub_80FB074(); + DestroyTask(data[15]); + } + break; + case 2: + data[10] = CreateTask(sub_80E7FF8, 10); + data[0] = 3; + PlaySE(SE_W226); + break; + case 3: + if (!gTasks[data[10]].isActive) + { + data[0] = 4; + if (!gLinkVSyncDisabled) + { + data[10] = sub_80B3050(); + } + sub_80E70F4(gText_RecordMixingComplete); + data[8] = 0; + } + break; + case 4: + if (++ data[8] > 60) + { + data[0] = 5; + } + break; + case 5: + if (!gTasks[data[10]].isActive) + { + free(gUnknown_0203A014); + free(gUnknown_0203A018); + sub_808729C(); + if (gLinkVSyncDisabled) + { + CreateTask(sub_80AF2B4, 10); + } + sub_8197434(0, 1); + DestroyTask(taskId); + EnableBothScriptContexts(); + } + break; + } +}