From 826d0ea2abe1ef505fb6b2b9b78e36c5c7a76c0e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 27 Oct 2018 15:44:29 +0200 Subject: [PATCH] Begin frontier records --- asm/battle_frontier_2.s | 1129 +------------------------------------- include/field_specials.h | 1 + include/global.h | 5 +- ld_script.txt | 1 + src/battle_frontier_2.c | 378 +++++++++++++ 5 files changed, 387 insertions(+), 1127 deletions(-) create mode 100644 src/battle_frontier_2.c diff --git a/asm/battle_frontier_2.s b/asm/battle_frontier_2.s index 6f267bcc1..b0c83b39b 100644 --- a/asm/battle_frontier_2.s +++ b/asm/battle_frontier_2.s @@ -6,1123 +6,6 @@ .text - thumb_func_start sub_81A1780 -sub_81A1780: @ 81A1780 - push {lr} - ldr r1, =gUnknown_08611C18 - ldr r0, =gSpecialVar_0x8004 - ldrh r0, [r0] - lsls r0, 2 - adds r0, r1 - ldr r0, [r0] - bl _call_via_r0 - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1780 - - thumb_func_start sub_81A17A0 -sub_81A17A0: @ 81A17A0 - push {lr} - movs r0, 0x80 - lsls r0, 7 - movs r1, 0xFF - bl VarSet - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =0x00000ca8 - adds r0, r1 - ldrb r0, [r0] - cmp r0, 0x4 - bhi _081A1822 - lsls r0, 2 - ldr r1, =_081A17D0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A17D0: - .4byte _081A1822 - .4byte _081A17E4 - .4byte _081A1810 - .4byte _081A17EC - .4byte _081A17E8 -_081A17E4: - movs r0, 0 - b _081A17EE -_081A17E8: - movs r0, 0 - b _081A17EE -_081A17EC: - movs r0, 0x1 -_081A17EE: - bl sub_813A878 - movs r0, 0x80 - lsls r0, 7 - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - ldr r2, =0x00000ca8 - adds r1, r2 - ldrb r1, [r1] - bl VarSet - b _081A1822 - .pool -_081A1810: - movs r0, 0x80 - lsls r0, 7 - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - ldr r2, =0x00000ca8 - adds r1, r2 - ldrb r1, [r1] - bl VarSet -_081A1822: - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A17A0 - - thumb_func_start sub_81A1830 -sub_81A1830: @ 81A1830 - push {r4-r6,lr} - ldr r0, =0x000040cf - bl VarGet - lsls r0, 24 - lsrs r6, r0, 24 - adds r0, r6, 0 - bl sub_81A3B30 - lsls r0, 24 - lsrs r5, r0, 24 - cmp r5, 0x2 - bne _081A184C - movs r5, 0x1 -_081A184C: - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0x7 - bls _081A1856 - b _081A1956 -_081A1856: - lsls r0, 2 - ldr r1, =_081A186C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A186C: - .4byte _081A188C - .4byte _081A18A8 - .4byte _081A18C8 - .4byte _081A18E4 - .4byte _081A1956 - .4byte _081A1900 - .4byte _081A1918 - .4byte _081A1938 -_081A188C: - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ca8 - adds r0, r2 - ldrb r0, [r0] - strh r0, [r1] - b _081A1956 - .pool -_081A18A8: - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 30 - lsrs r0, 30 - strh r0, [r1] - b _081A1956 - .pool -_081A18C8: - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000cb2 - adds r0, r2 - ldrh r0, [r0] - strh r0, [r1] - b _081A1956 - .pool -_081A18E4: - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 29 - b _081A1926 - .pool -_081A1900: - ldr r2, =gSpecialVar_Result - ldr r1, =gBattleOutcome - ldrb r0, [r1] - strh r0, [r2] - movs r0, 0 - strb r0, [r1] - b _081A1956 - .pool -_081A1918: - ldr r1, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r2, =0x00000ca9 - adds r0, r2 - ldrb r0, [r0] - lsls r0, 28 -_081A1926: - lsrs r0, 31 - strh r0, [r1] - b _081A1956 - .pool -_081A1938: - ldr r4, =gSpecialVar_Result - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - movs r0, 0xD0 - lsls r0, 4 - adds r2, r0 - ldr r3, =gUnknown_08611BFC - lsls r0, r5, 1 - lsls r1, r6, 2 - adds r0, r1 - adds r0, r3 - ldrh r1, [r2] - ldrh r0, [r0] - ands r0, r1 - strh r0, [r4] -_081A1956: - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1830 - - thumb_func_start sub_81A1968 -sub_81A1968: @ 81A1968 - push {r4,r5,lr} - ldr r0, =0x000040cf - bl VarGet - lsls r0, 24 - lsrs r5, r0, 24 - adds r0, r5, 0 - bl sub_81A3B30 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x2 - bne _081A1984 - movs r4, 0x1 -_081A1984: - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0x7 - bls _081A198E - b _081A1AC4 -_081A198E: - lsls r0, 2 - ldr r1, =_081A19A4 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A19A4: - .4byte _081A19C4 - .4byte _081A19E0 - .4byte _081A1A0C - .4byte _081A1A28 - .4byte _081A1A50 - .4byte _081A1AC4 - .4byte _081A1A7C - .4byte _081A1AA8 -_081A19C4: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =gSpecialVar_0x8006 - ldrh r1, [r1] - ldr r2, =0x00000ca8 - adds r0, r2 - strb r1, [r0] - b _081A1AC4 - .pool -_081A19E0: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - ldr r0, =gSpecialVar_0x8006 - ldrb r0, [r0] - ldr r1, =0x00000ca9 - adds r2, r1 - movs r1, 0x3 - ands r1, r0 - ldrb r3, [r2] - movs r0, 0x4 - negs r0, r0 - ands r0, r3 - orrs r0, r1 - strb r0, [r2] - b _081A1AC4 - .pool -_081A1A0C: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r1, =gSpecialVar_0x8006 - ldrh r1, [r1] - ldr r2, =0x00000cb2 - adds r0, r2 - strh r1, [r0] - b _081A1AC4 - .pool -_081A1A28: - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r0, =gSpecialVar_0x8006 - ldrb r0, [r0] - ldr r1, =0x00000ca9 - adds r3, r1 - movs r1, 0x1 - ands r1, r0 - lsls r1, 2 - ldrb r2, [r3] - movs r0, 0x5 - negs r0, r0 - b _081A1A94 - .pool -_081A1A50: - movs r2, 0 - ldr r5, =gSaveBlock2Ptr - ldr r4, =0x00000caa - ldr r3, =gUnknown_0203CEF8 -_081A1A58: - ldr r1, [r5] - lsls r0, r2, 1 - adds r1, r4 - adds r1, r0 - adds r0, r2, r3 - ldrb r0, [r0] - strh r0, [r1] - adds r2, 0x1 - cmp r2, 0x3 - ble _081A1A58 - b _081A1AC4 - .pool -_081A1A7C: - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - ldr r0, =gSpecialVar_0x8006 - ldrb r0, [r0] - ldr r2, =0x00000ca9 - adds r3, r2 - movs r1, 0x1 - ands r1, r0 - lsls r1, 3 - ldrb r2, [r3] - movs r0, 0x9 - negs r0, r0 -_081A1A94: - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - b _081A1AC4 - .pool -_081A1AA8: - ldr r0, =gSaveBlock2Ptr - ldr r2, [r0] - movs r0, 0xD0 - lsls r0, 4 - adds r2, r0 - ldr r3, =gUnknown_08611BFC - lsls r1, r4, 1 - lsls r0, r5, 2 - adds r1, r0 - adds r1, r3 - ldrh r0, [r2] - ldrh r1, [r1] - orrs r0, r1 - strh r0, [r2] -_081A1AC4: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1968 - - thumb_func_start sub_81A1AD4 -sub_81A1AD4: @ 81A1AD4 - push {r4-r7,lr} - bl sub_81B8558 - movs r3, 0 - ldr r4, =gSpecialVar_0x8005 - ldrh r0, [r4] - cmp r3, r0 - bge _081A1B00 - ldr r7, =gUnknown_0203CEF8 - ldr r6, =gSaveBlock2Ptr - ldr r5, =0x00000caa -_081A1AEA: - adds r2, r3, r7 - ldr r0, [r6] - lsls r1, r3, 1 - adds r0, r5 - adds r0, r1 - ldrh r0, [r0] - strb r0, [r2] - adds r3, 0x1 - ldrh r0, [r4] - cmp r3, r0 - blt _081A1AEA -_081A1B00: - bl ReducePlayerPartyToThree - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1AD4 - - thumb_func_start sub_81A1B1C -sub_81A1B1C: @ 81A1B1C - push {lr} - bl DoSoftReset - pop {r0} - bx r0 - thumb_func_end sub_81A1B1C - - thumb_func_start sub_81A1B28 -sub_81A1B28: @ 81A1B28 - ldr r1, =gFacilityTrainers - ldr r0, =gBattleFrontierTrainers - str r0, [r1] - bx lr - .pool - thumb_func_end sub_81A1B28 - - thumb_func_start sub_81A1B38 -sub_81A1B38: @ 81A1B38 - push {r4,r5,lr} - movs r4, 0 - movs r5, 0x64 -_081A1B3E: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - lsls r1, r4, 1 - ldr r2, =0x00000caa - adds r0, r2 - adds r1, r0, r1 - ldrh r0, [r1] - subs r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x5 - bhi _081A1B76 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldrh r1, [r1] - subs r1, 0x1 - muls r1, r5 - adds r0, r1 - movs r1, 0x8E - lsls r1, 2 - adds r0, r1 - ldr r2, =gPlayerParty - adds r1, r4, 0 - muls r1, r5 - adds r1, r2 - movs r2, 0x64 - bl memcpy -_081A1B76: - adds r0, r4, 0x1 - lsls r0, 24 - lsrs r4, r0, 24 - cmp r4, 0x3 - bls _081A1B3E - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1B38 - - thumb_func_start sub_81A1B98 -sub_81A1B98: @ 81A1B98 - push {lr} - ldr r0, =gSpecialVar_0x8006 - ldrh r1, [r0] - adds r2, r0, 0 - cmp r1, 0x3 - bls _081A1BA8 - movs r0, 0 - strh r0, [r2] -_081A1BA8: - ldr r0, =gSpecialVar_0x8005 - ldrh r0, [r0] - cmp r0, 0x7 - bhi _081A1C1E - lsls r0, 2 - ldr r1, =_081A1BC8 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_081A1BC8: - .4byte _081A1BE8 - .4byte _081A1BF0 - .4byte _081A1BF8 - .4byte _081A1C0E - .4byte _081A1C06 - .4byte _081A1C00 - .4byte _081A1C14 - .4byte _081A1C1A -_081A1BE8: - ldrb r0, [r2] - bl sub_81A1EA8 - b _081A1C1E -_081A1BF0: - ldrb r0, [r2] - bl sub_81A2134 - b _081A1C1E -_081A1BF8: - ldrb r0, [r2] - bl sub_81A2460 - b _081A1C1E -_081A1C00: - bl sub_81A2698 - b _081A1C1E -_081A1C06: - ldrb r0, [r2] - bl sub_81A2C94 - b _081A1C1E -_081A1C0E: - bl sub_81A2968 - b _081A1C1E -_081A1C14: - bl sub_81A2F38 - b _081A1C1E -_081A1C1A: - bl sub_81A2FF8 -_081A1C1E: - pop {r0} - bx r0 - thumb_func_end sub_81A1B98 - - thumb_func_start sub_81A1C24 -sub_81A1C24: @ 81A1C24 - push {lr} - ldr r1, =gSaveBlock2Ptr - ldr r1, [r1] - ldr r2, =0x00000cdc - adds r1, r2 - ldr r1, [r1] - ands r1, r0 - cmp r1, 0 - bne _081A1C44 - movs r0, 0 - b _081A1C46 - .pool -_081A1C44: - movs r0, 0x1 -_081A1C46: - pop {r1} - bx r1 - thumb_func_end sub_81A1C24 - - thumb_func_start sub_81A1C4C -sub_81A1C4C: @ 81A1C4C - push {r4,r5,lr} - sub sp, 0xC - adds r4, r0, 0 - adds r5, r1, 0 - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0xE0 - bl GetStringCenterAlignXOffset - adds r3, r0, 0 - lsls r0, r5, 3 - adds r5, r0, 0x1 - ldr r0, =gRecordsWindowId - ldrb r0, [r0] - lsls r3, 24 - lsrs r3, 24 - lsls r1, r5, 24 - lsrs r1, 24 - str r1, [sp] - movs r1, 0xFF - str r1, [sp, 0x4] - movs r1, 0 - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - bl AddTextPrinterParameterized - add sp, 0xC - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1C4C - - thumb_func_start sub_81A1C90 -sub_81A1C90: @ 81A1C90 - push {r4,lr} - sub sp, 0x34 - adds r2, r0, 0 - ldr r3, =gRecordsWindowId - movs r1, 0xAE - mov r0, sp - adds r0, 0x2F -_081A1C9E: - strb r1, [r0] - subs r0, 0x1 - add r4, sp, 0xC - cmp r0, r4 - bge _081A1C9E - add r1, sp, 0x30 - movs r0, 0xFF - strb r0, [r1] - lsls r0, r2, 3 - adds r2, r0, 0x1 - ldrb r0, [r3] - lsls r1, r2, 24 - lsrs r1, 24 - str r1, [sp] - movs r1, 0xFF - str r1, [sp, 0x4] - movs r1, 0 - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - movs r3, 0x4 - bl AddTextPrinterParameterized - add sp, 0x34 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1C90 - - thumb_func_start sub_81A1CD8 -sub_81A1CD8: @ 81A1CD8 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - adds r5, r0, 0 - adds r4, r2, 0 - ldr r0, [sp, 0x30] - lsls r1, 16 - lsrs r6, r1, 16 - lsls r4, 24 - lsrs r4, 24 - lsls r3, 24 - lsrs r3, 24 - str r3, [sp, 0xC] - lsls r0, 24 - lsrs r0, 24 - adds r7, r0, 0 - ldr r0, =gRecordsWindowId - mov r10, r0 - ldrb r0, [r0] - str r7, [sp] - movs r1, 0xFF - mov r9, r1 - str r1, [sp, 0x4] - movs r1, 0 - mov r8, r1 - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r5, 0 - adds r3, r4, 0 - bl AddTextPrinterParameterized - ldr r0, =0x0000270f - cmp r6, r0 - bls _081A1D24 - adds r6, r0, 0 -_081A1D24: - ldr r0, =gStringVar1 - adds r1, r6, 0 - movs r2, 0x1 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - ldr r4, =gStringVar4 - ldr r1, =gText_WinStreak - adds r0, r4, 0 - bl StringExpandPlaceholders - mov r1, r10 - ldrb r0, [r1] - str r7, [sp] - mov r1, r9 - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - ldr r3, [sp, 0xC] - bl AddTextPrinterParameterized - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1CD8 - - thumb_func_start sub_81A1D78 -sub_81A1D78: @ 81A1D78 - push {r4,r5,lr} - sub sp, 0x4 - ldr r5, [sp, 0x10] - lsls r0, 24 - lsls r1, 24 - lsls r2, 24 - lsrs r2, 24 - lsls r3, 24 - lsrs r3, 24 - lsls r5, 24 - lsrs r5, 24 - ldr r4, =gSaveBlock2Ptr - ldr r4, [r4] - lsrs r1, 23 - lsrs r0, 22 - adds r1, r0 - movs r0, 0xCF - lsls r0, 4 - adds r4, r0 - adds r4, r1 - ldrh r1, [r4] - ldr r0, =gText_Record - str r5, [sp] - bl sub_81A1CD8 - add sp, 0x4 - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1D78 - - thumb_func_start sub_81A1DBC -sub_81A1DBC: @ 81A1DBC - push {lr} - lsls r0, 24 - lsls r1, 24 - ldr r2, =gSaveBlock2Ptr - ldr r2, [r2] - lsrs r1, 23 - lsrs r0, 22 - adds r1, r0 - movs r0, 0xCE - lsls r0, 4 - adds r2, r0 - adds r2, r1 - ldrh r0, [r2] - ldr r1, =0x0000270f - cmp r0, r1 - bls _081A1DDE - adds r0, r1, 0 -_081A1DDE: - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A1DBC - - thumb_func_start sub_81A1DEC -sub_81A1DEC: @ 81A1DEC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x4 - ldr r4, [sp, 0x20] - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r2, 24 - mov r8, r2 - lsls r3, 24 - lsrs r3, 24 - mov r9, r3 - lsls r4, 24 - lsrs r7, r4, 24 - adds r0, r5, 0 - adds r1, r6, 0 - bl sub_81A1DBC - lsls r0, 16 - lsrs r4, r0, 16 - cmp r5, 0x1 - beq _081A1E38 - cmp r5, 0x1 - ble _081A1E2C - cmp r5, 0x2 - beq _081A1E48 - cmp r5, 0x3 - beq _081A1E58 -_081A1E2C: - cmp r6, 0 - beq _081A1E34 - movs r0, 0x2 - b _081A1E66 -_081A1E34: - movs r0, 0x1 - b _081A1E66 -_081A1E38: - cmp r6, 0 - beq _081A1E42 - movs r0, 0x80 - lsls r0, 8 - b _081A1E66 -_081A1E42: - movs r0, 0x80 - lsls r0, 7 - b _081A1E66 -_081A1E48: - cmp r6, 0 - beq _081A1E52 - movs r0, 0x80 - lsls r0, 10 - b _081A1E66 -_081A1E52: - movs r0, 0x80 - lsls r0, 9 - b _081A1E66 -_081A1E58: - cmp r6, 0 - beq _081A1E62 - movs r0, 0x80 - lsls r0, 12 - b _081A1E66 -_081A1E62: - movs r0, 0x80 - lsls r0, 11 -_081A1E66: - bl sub_81A1C24 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _081A1E88 - ldr r0, =gText_Current - str r7, [sp] - adds r1, r4, 0 - mov r2, r8 - mov r3, r9 - bl sub_81A1CD8 - b _081A1E96 - .pool -_081A1E88: - ldr r0, =gText_Prev - str r7, [sp] - adds r1, r4, 0 - mov r2, r8 - mov r3, r9 - bl sub_81A1CD8 -_081A1E96: - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1DEC - - thumb_func_start sub_81A1EA8 -sub_81A1EA8: @ 81A1EA8 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0xC - lsls r0, 24 - lsrs r7, r0, 24 - ldr r4, =gRecordsWindowId - ldr r0, =gUnknown_08611C74 - bl AddWindow - strb r0, [r4] - ldrb r0, [r4] - movs r1, 0 - bl NewMenuHelpers_DrawStdWindowFrame - ldrb r0, [r4] - movs r1, 0x11 - bl FillWindowPixelBuffer - cmp r7, 0 - bne _081A1EF0 - ldr r0, =gStringVar4 - ldr r1, =gText_SingleBattleRoomResults - bl StringExpandPlaceholders - b _081A1F28 - .pool -_081A1EF0: - cmp r7, 0x1 - bne _081A1F08 - ldr r0, =gStringVar4 - ldr r1, =gText_DoubleBattleRoomResults - bl StringExpandPlaceholders - b _081A1F28 - .pool -_081A1F08: - cmp r7, 0x2 - bne _081A1F20 - ldr r0, =gStringVar4 - ldr r1, =gText_MultiBattleRoomResults - bl StringExpandPlaceholders - b _081A1F28 - .pool -_081A1F20: - ldr r0, =gStringVar4 - ldr r1, =gText_LinkMultiBattleRoomResults - bl StringExpandPlaceholders -_081A1F28: - ldr r0, =gStringVar4 - movs r1, 0x2 - bl sub_81A1C4C - ldr r6, =gRecordsWindowId - ldrb r0, [r6] - ldr r2, =gText_Lv502 - movs r1, 0x31 - mov r8, r1 - str r1, [sp] - movs r5, 0xFF - str r5, [sp, 0x4] - movs r4, 0 - str r4, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x10 - bl AddTextPrinterParameterized - ldrb r0, [r6] - ldr r2, =gText_OpenLv - movs r1, 0x61 - mov r9, r1 - str r1, [sp] - str r5, [sp, 0x4] - str r4, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x10 - bl AddTextPrinterParameterized - movs r0, 0xA - bl sub_81A1C90 - mov r0, r8 - str r0, [sp] - adds r0, r7, 0 - movs r1, 0 - movs r2, 0x48 - movs r3, 0x84 - bl sub_81A1DEC - movs r0, 0x41 - str r0, [sp] - adds r0, r7, 0 - movs r1, 0 - movs r2, 0x48 - movs r3, 0x84 - bl sub_81A1D78 - mov r1, r9 - str r1, [sp] - adds r0, r7, 0 - movs r1, 0x1 - movs r2, 0x48 - movs r3, 0x84 - bl sub_81A1DEC - movs r0, 0x71 - str r0, [sp] - adds r0, r7, 0 - movs r1, 0x1 - movs r2, 0x48 - movs r3, 0x84 - bl sub_81A1D78 - ldrb r0, [r6] - bl PutWindowTilemap - ldrb r0, [r6] - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0xC - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A1EA8 - - thumb_func_start sub_81A1FD8 -sub_81A1FD8: @ 81A1FD8 - push {lr} - lsls r0, 24 - lsls r1, 24 - ldr r2, =gSaveBlock2Ptr - ldr r2, [r2] - lsrs r1, 23 - lsrs r0, 22 - adds r1, r0 - ldr r0, =0x00000d0c - adds r2, r0 - adds r2, r1 - ldrh r0, [r2] - ldr r1, =0x0000270f - cmp r0, r1 - bls _081A1FF8 - adds r0, r1, 0 -_081A1FF8: - pop {r1} - bx r1 - .pool - thumb_func_end sub_81A1FD8 - - thumb_func_start sub_81A2008 -sub_81A2008: @ 81A2008 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - mov r12, r0 - adds r7, r1, 0 - adds r4, r2, 0 - ldr r6, [sp, 0x2C] - ldr r5, [sp, 0x30] - lsls r4, 16 - lsrs r4, 16 - lsls r3, 24 - lsrs r3, 24 - lsls r6, 24 - lsrs r6, 24 - lsls r5, 24 - lsrs r5, 24 - ldr r0, =gRecordsWindowId - mov r10, r0 - ldrb r0, [r0] - str r5, [sp] - movs r1, 0xFF - mov r9, r1 - str r1, [sp, 0x4] - movs r1, 0 - mov r8, r1 - str r1, [sp, 0x8] - movs r1, 0x1 - mov r2, r12 - bl AddTextPrinterParameterized - ldr r0, =gStringVar1 - adds r1, r4, 0 - movs r2, 0x1 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - ldr r4, =gStringVar4 - adds r0, r4, 0 - adds r1, r7, 0 - bl StringExpandPlaceholders - mov r1, r10 - ldrb r0, [r1] - str r5, [sp] - mov r1, r9 - str r1, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - adds r3, r6, 0 - bl AddTextPrinterParameterized - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A2008 - - thumb_func_start sub_81A2094 -sub_81A2094: @ 81A2094 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x8 - ldr r4, [sp, 0x24] - lsls r0, 24 - lsrs r5, r0, 24 - lsls r1, 24 - lsrs r6, r1, 24 - lsls r2, 24 - lsrs r2, 24 - mov r9, r2 - lsls r3, 24 - lsrs r7, r3, 24 - lsls r4, 24 - lsrs r4, 24 - adds r0, r5, 0 - adds r1, r6, 0 - bl sub_81A1FD8 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r5, 0 - beq _081A20CC - cmp r5, 0x1 - beq _081A20D8 -_081A20CC: - cmp r6, 0 - beq _081A20D4 - movs r0, 0x8 - b _081A20E6 -_081A20D4: - movs r0, 0x4 - b _081A20E6 -_081A20D8: - cmp r6, 0 - beq _081A20E2 - movs r0, 0x80 - lsls r0, 14 - b _081A20E6 -_081A20E2: - movs r0, 0x80 - lsls r0, 13 -_081A20E6: - bl sub_81A1C24 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _081A210C - ldr r0, =gText_Current - ldr r1, =gText_ClearStreak - str r7, [sp] - str r4, [sp, 0x4] - mov r2, r8 - mov r3, r9 - bl sub_81A2008 - b _081A211C - .pool -_081A210C: - ldr r0, =gText_Prev - ldr r1, =gText_ClearStreak - str r7, [sp] - str r4, [sp, 0x4] - mov r2, r8 - mov r3, r9 - bl sub_81A2008 -_081A211C: - add sp, 0x8 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81A2094 thumb_func_start sub_81A2134 sub_81A2134: @ 81A2134 @@ -1182,7 +65,7 @@ _081A2184: movs r3, 0x8 bl AddTextPrinterParameterized movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens str r6, [sp] adds r0, r7, 0 movs r1, 0 @@ -1536,7 +419,7 @@ _081A24B0: movs r3, 0x10 bl AddTextPrinterParameterized movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens mov r0, r8 str r0, [sp] adds r0, r7, 0 @@ -1773,7 +656,7 @@ sub_81A2698: @ 81A2698 movs r3, 0x8 bl AddTextPrinterParameterized movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens movs r0, 0 movs r1, 0x40 movs r2, 0x72 @@ -2049,7 +932,7 @@ sub_81A2968: @ 81A2968 movs r1, 0x11 bl FillWindowPixelBuffer movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens ldr r4, =gStringVar4 ldr r1, =gText_SetKOTourneyResults adds r0, r4, 0 @@ -2471,7 +1354,7 @@ _081A2CE0: movs r3, 0x8 bl AddTextPrinterParameterized movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens movs r4, 0x9E str r4, [sp] movs r0, 0x31 @@ -2746,7 +1629,7 @@ sub_81A2F38: @ 81A2F38 movs r3, 0x8 bl AddTextPrinterParameterized movs r0, 0xA - bl sub_81A1C90 + bl PrintHyphens movs r0, 0 movs r1, 0x40 movs r2, 0x6F diff --git a/include/field_specials.h b/include/field_specials.h index 0e2daf9c3..50823ba7d 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -15,5 +15,6 @@ bool32 sub_8138168(void); bool32 sub_81381B0(void); bool32 sub_81381F8(void); bool32 CountSSTidalStep(u16 delta); +void sub_813A878(u8 a0); #endif // GUARD_FIELD_SPECIALS_H diff --git a/include/global.h b/include/global.h index 0cff281e7..d23800139 100644 --- a/include/global.h +++ b/include/global.h @@ -401,10 +401,7 @@ struct BattleFrontier /*0xCB4*/ u16 field_CB4[20]; /*0xCDC*/ u32 field_CDC; /*0xCE0*/ u16 winStreaks[4][2]; - /*0xCF0*/ u16 field_CF0[2]; - /*0xCF4*/ u16 field_CF4[2]; - /*0xCF8*/ u16 field_CF8[2]; - /*0xCFC*/ u16 field_CFC[2]; + /*0xCF0*/ u16 field_CF0[4][2]; /*0xD06*/ u16 field_D00; /*0xD06*/ u16 field_D02; /*0xD06*/ u16 field_D04; diff --git a/ld_script.txt b/ld_script.txt index 1582f01e5..8d07bbe9b 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -246,6 +246,7 @@ SECTIONS { src/menu.o(.text); src/battle_factory.o(.text); src/apprentice.o(.text); + src/battle_frontier_2.o(.text); asm/battle_frontier_2.o(.text); src/item_menu.o(.text); src/list_menu.o(.text); diff --git a/src/battle_frontier_2.c b/src/battle_frontier_2.c new file mode 100644 index 000000000..9e8d20033 --- /dev/null +++ b/src/battle_frontier_2.c @@ -0,0 +1,378 @@ +#include "global.h" +#include "event_data.h" +#include "battle_setup.h" +#include "overworld.h" +#include "random.h" +#include "battle_tower.h" +#include "field_specials.h" +#include "battle.h" +#include "script_pokemon_util_80F87D8.h" +#include "main.h" +#include "window.h" +#include "menu.h" +#include "text.h" +#include "battle_records.h" +#include "international_string_util.h" +#include "string_util.h" +#include "constants/battle_frontier.h" + +extern u8 gUnknown_0203CEF8[]; + +extern void (* const gUnknown_08611C18[])(void); +extern const u16 gUnknown_08611BFC[][2]; + +extern void sub_81B8558(void); + +// This file's functions. +u8 sub_81A3B30(u8 facility); + +void sub_81A1780(void) +{ + gUnknown_08611C18[gSpecialVar_0x8004](); +} + +void sub_81A17A0(void) +{ + VarSet(VAR_TEMP_0, 0xFF); + switch (gSaveBlock2Ptr->frontier.field_CA8) + { + case 0: + break; + case 1: + sub_813A878(0); + VarSet(VAR_TEMP_0, gSaveBlock2Ptr->frontier.field_CA8); + break; + case 4: + sub_813A878(0); + VarSet(VAR_TEMP_0, gSaveBlock2Ptr->frontier.field_CA8); + break; + case 3: + sub_813A878(1); + VarSet(VAR_TEMP_0, gSaveBlock2Ptr->frontier.field_CA8); + break; + case 2: + VarSet(VAR_TEMP_0, gSaveBlock2Ptr->frontier.field_CA8); + break; + } +} + +void sub_81A1830(void) +{ + u8 facility = VarGet(VAR_FRONTIER_FACILITY); + u8 currSymbol = sub_81A3B30(facility); + if (currSymbol == 2) + currSymbol = 1; + + switch (gSpecialVar_0x8005) + { + case 0: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CA8; + break; + case 1: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.lvlMode; + break; + case 2: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + break; + case 3: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CA9_a; + break; + case 5: + gSpecialVar_Result = gBattleOutcome; + gBattleOutcome = 0; + break; + case 6: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_CA9_b; + break; + case 7: + gSpecialVar_Result = gSaveBlock2Ptr->frontier.field_D00 & gUnknown_08611BFC[facility][currSymbol]; + break; + } +} + +void sub_81A1968(void) +{ + s32 i; + u8 facility = VarGet(VAR_FRONTIER_FACILITY); + u8 currSymbol = sub_81A3B30(facility); + if (currSymbol == 2) + currSymbol = 1; + + switch (gSpecialVar_0x8005) + { + case 0: + gSaveBlock2Ptr->frontier.field_CA8 = gSpecialVar_0x8006; + break; + case 1: + gSaveBlock2Ptr->frontier.lvlMode = gSpecialVar_0x8006; + break; + case 2: + gSaveBlock2Ptr->frontier.curChallengeBattleNum = gSpecialVar_0x8006; + break; + case 3: + gSaveBlock2Ptr->frontier.field_CA9_a = gSpecialVar_0x8006; + break; + case 4: + for (i = 0; i < 4; i++) + gSaveBlock2Ptr->frontier.selectedPartyMons[i] = gUnknown_0203CEF8[i]; + break; + case 6: + gSaveBlock2Ptr->frontier.field_CA9_b = gSpecialVar_0x8006; + break; + case 7: + gSaveBlock2Ptr->frontier.field_D00 |= gUnknown_08611BFC[facility][currSymbol]; + break; + } +} + +void sub_81A1AD4(void) +{ + s32 i; + + sub_81B8558(); + for (i = 0; i < gSpecialVar_0x8005; i++) + gUnknown_0203CEF8[i] = gSaveBlock2Ptr->frontier.selectedPartyMons[i]; + ReducePlayerPartyToThree(); +} + +void sub_81A1B1C(void) +{ + DoSoftReset(); +} + +extern const struct BattleFrontierTrainer gBattleFrontierTrainers[]; + +void sub_81A1B28(void) +{ + gFacilityTrainers = gBattleFrontierTrainers; +} + +void sub_81A1B38(void) +{ + u8 i; + + for (i = 0; i < 4; i++) + { + u16 monId = gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1; + if (monId < PARTY_SIZE) + gSaveBlock1Ptr->playerParty[gSaveBlock2Ptr->frontier.selectedPartyMons[i] - 1] = gPlayerParty[i]; + } +} + +void PutTowerResultsWindow(u8); +void sub_81A2134(u8); +void sub_81A2460(u8); +void sub_81A2698(void); +void sub_81A2C94(u8); +void sub_81A2968(void); +void sub_81A2F38(void); +void sub_81A2FF8(void); + +void sub_81A1B98(void) +{ + if (gSpecialVar_0x8006 > 3) + gSpecialVar_0x8006 = 0; + switch (gSpecialVar_0x8005) + { + case 0: + PutTowerResultsWindow(gSpecialVar_0x8006); + break; + case 1: + sub_81A2134(gSpecialVar_0x8006); + break; + case 2: + sub_81A2460(gSpecialVar_0x8006); + break; + case 5: + sub_81A2698(); + break; + case 4: + sub_81A2C94(gSpecialVar_0x8006); + break; + case 3: + sub_81A2968(); + break; + case 6: + sub_81A2F38(); + break; + case 7: + sub_81A2FF8(); + break; + } +} + +bool8 sub_81A1C24(u32 flags) +{ + if (gSaveBlock2Ptr->frontier.field_CDC & flags) + return TRUE; + else + return FALSE; +} + +void sub_81A1C4C(const u8 *str, s32 y) +{ + s32 x = GetStringCenterAlignXOffset(1, str, 0xE0); + y = (y * 8) + 1; + AddTextPrinterParameterized(gRecordsWindowId, 1, str, x, y, TEXT_SPEED_FF, NULL); +} + +void PrintHyphens(s32 y) +{ + s32 i; + u8 text[37]; + + for (i = 0; i < 36; i++) + text[i] = CHAR_HYPHEN; + text[i] = EOS; + + y = (y * 8) + 1; + AddTextPrinterParameterized(gRecordsWindowId, 1, text, 4, y, TEXT_SPEED_FF, NULL); +} + +extern const u8 gText_WinStreak[]; +extern const u8 gText_Record[]; +extern const u8 gText_Current[]; +extern const u8 gText_Prev[]; +extern const u8 gText_SingleBattleRoomResults[]; +extern const u8 gText_DoubleBattleRoomResults[]; +extern const u8 gText_MultiBattleRoomResults[]; +extern const u8 gText_LinkMultiBattleRoomResults[]; +extern const u8 gText_Lv502[]; +extern const u8 gText_OpenLv[]; +extern const u8 gText_ClearStreak[]; + +void TowerPrintStreak(const u8 *str, u16 num, u8 x1, u8 x2, u8 y) +{ + AddTextPrinterParameterized(gRecordsWindowId, 1, str, x1, y, TEXT_SPEED_FF, NULL); + if (num > 9999) + num = 9999; + ConvertIntToDecimalStringN(gStringVar1, num, STR_CONV_MODE_RIGHT_ALIGN, 4); + StringExpandPlaceholders(gStringVar4, gText_WinStreak); + AddTextPrinterParameterized(gRecordsWindowId, 1, gStringVar4, x2, y, TEXT_SPEED_FF, NULL); +} + +void TowerPrintRecordStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 x2, u8 y) +{ + u16 num = gSaveBlock2Ptr->frontier.field_CF0[battleMode][lvlMode]; + TowerPrintStreak(gText_Record, num, x1, x2, y); +} + +u16 TowerGetStreak(u8 battleMode, u8 lvlMode) +{ + u16 winStreak = gSaveBlock2Ptr->frontier.winStreaks[battleMode][lvlMode]; + if (winStreak > 9999) + return 9999; + else + return winStreak; +} + +void TowerPrintPrevOrCurrentStreak(u8 battleMode, u8 lvlMode, u8 x1, u8 x2, u8 y) +{ + bool8 isCurrent; + u16 winStreak = TowerGetStreak(battleMode, lvlMode); + switch (battleMode) + { + default: + case FRONTIER_MODE_SINGLES: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(2); + else + isCurrent = sub_81A1C24(1); + break; + case FRONTIER_MODE_DOUBLES: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(0x8000); + else + isCurrent = sub_81A1C24(0x4000); + break; + case FRONTIER_MODE_MULTIS: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(0x20000); + else + isCurrent = sub_81A1C24(0x10000); + break; + case FRONTIER_MODE_LINK_MULTIS: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(0x80000); + else + isCurrent = sub_81A1C24(0x40000); + break; + } + + if (isCurrent == TRUE) + TowerPrintStreak(gText_Current, winStreak, x1, x2, y); + else + TowerPrintStreak(gText_Prev, winStreak, x1, x2, y); +} + +extern const struct WindowTemplate gUnknown_08611C74; + +void PutTowerResultsWindow(u8 battleMode) +{ + gRecordsWindowId = AddWindow(&gUnknown_08611C74); + NewMenuHelpers_DrawStdWindowFrame(gRecordsWindowId, FALSE); + FillWindowPixelBuffer(gRecordsWindowId, 0x11); + if (battleMode == FRONTIER_MODE_SINGLES) + StringExpandPlaceholders(gStringVar4, gText_SingleBattleRoomResults); + else if (battleMode == FRONTIER_MODE_DOUBLES) + StringExpandPlaceholders(gStringVar4, gText_DoubleBattleRoomResults); + else if (battleMode == FRONTIER_MODE_MULTIS) + StringExpandPlaceholders(gStringVar4, gText_MultiBattleRoomResults); + else + StringExpandPlaceholders(gStringVar4, gText_LinkMultiBattleRoomResults); + + sub_81A1C4C(gStringVar4, 2); + AddTextPrinterParameterized(gRecordsWindowId, 1, gText_Lv502, 16, 49, TEXT_SPEED_FF, NULL); + AddTextPrinterParameterized(gRecordsWindowId, 1, gText_OpenLv, 16, 97, TEXT_SPEED_FF, NULL); + PrintHyphens(10); + TowerPrintPrevOrCurrentStreak(battleMode, FRONTIER_LVL_50, 72, 132, 49); + TowerPrintRecordStreak(battleMode, FRONTIER_LVL_50, 72, 132, 65); + TowerPrintPrevOrCurrentStreak(battleMode, FRONTIER_LVL_OPEN, 72, 132, 97); + TowerPrintRecordStreak(battleMode, FRONTIER_LVL_OPEN, 72, 132, 113); + PutWindowTilemap(gRecordsWindowId); + CopyWindowToVram(gRecordsWindowId, 3); +} + +u16 sub_81A1FD8(u8 battleMode, u8 lvlMode) +{ + u16 winStreak = gSaveBlock2Ptr->frontier.field_D0C[battleMode][lvlMode]; + if (winStreak > 9999) + return 9999; + else + return winStreak; +} + +void sub_81A2008(const u8 *str1, const u8 *str2, u16 num, u8 x1, u8 x2, u8 y) +{ + AddTextPrinterParameterized(gRecordsWindowId, 1, str1, x1, y, TEXT_SPEED_FF, NULL); + ConvertIntToDecimalStringN(gStringVar1, num, STR_CONV_MODE_RIGHT_ALIGN, 4); + StringExpandPlaceholders(gStringVar4, str2); + AddTextPrinterParameterized(gRecordsWindowId, 1, gStringVar4, x2, y, TEXT_SPEED_FF, NULL); +} + +void sub_81A2094(u8 battleMode, u8 lvlMode, u8 x1, u8 x2, u8 y) +{ + bool8 isCurrent; + u16 winStreak = sub_81A1FD8(battleMode, lvlMode); + switch (battleMode) + { + default: + case FRONTIER_MODE_SINGLES: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(8); + else + isCurrent = sub_81A1C24(4); + break; + case FRONTIER_MODE_DOUBLES: + if (lvlMode != FRONTIER_LVL_50) + isCurrent = sub_81A1C24(0x200000); + else + isCurrent = sub_81A1C24(0x100000); + break; + } + + if (isCurrent == TRUE) + sub_81A2008(gText_Current, gText_ClearStreak, winStreak, x1, x2, y); + else + sub_81A2008(gText_Prev, gText_ClearStreak, winStreak, x1, x2, y); +}