From 7571969a458fefcfa242acdd4a38dce134897977 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 1 Apr 2019 22:30:30 -0400 Subject: [PATCH] Finish union room battle --- asm/union_room_battle.s | 636 ---------------------------------- data/union_room_battle.s | 17 - include/constants/game_stat.h | 2 +- include/main.h | 2 +- include/strings.h | 3 + include/union_room_battle.h | 1 + ld_script.txt | 2 - src/mauville_old_man.c | 2 +- src/union_room.c | 2 +- src/union_room_battle.c | 359 +++++++++++++------ sym_ewram.txt | 5 +- 11 files changed, 271 insertions(+), 760 deletions(-) delete mode 100755 asm/union_room_battle.s delete mode 100755 data/union_room_battle.s diff --git a/asm/union_room_battle.s b/asm/union_room_battle.s deleted file mode 100755 index ea4e6958e..000000000 --- a/asm/union_room_battle.s +++ /dev/null @@ -1,636 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_801AA08 -sub_801AA08: @ 801AA08 - push {r4,lr} - movs r4, 0 - adds r3, r1, 0 - adds r2, r0, 0 -_0801AA10: - ldr r1, [r2] - ldr r0, [r3] - cmp r1, r0 - beq _0801AA1C - movs r0, 0x1 - b _0801AA28 -_0801AA1C: - adds r3, 0x4 - adds r2, 0x4 - adds r4, 0x1 - cmp r4, 0x3 - ble _0801AA10 - movs r0, 0 -_0801AA28: - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_801AA08 - - thumb_func_start sub_801AA30 -sub_801AA30: @ 801AA30 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - adds r6, r0, 0 - mov r9, r1 - adds r5, r2, 0 - lsls r4, r3, 24 - lsrs r4, 24 - movs r0, 0 - mov r8, r0 - mov r0, sp - movs r1, 0 - movs r2, 0x10 - bl memset - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r7, r0, r1 - movs r4, 0 -_0801AA5E: - lsls r1, r4, 5 - ldr r0, [r7] - adds r0, r1 - mov r1, sp - bl sub_801A960 - adds r1, r0, 0 - ldr r0, [r5] - cmp r1, r0 - beq _0801AA78 - str r1, [r5] - movs r2, 0x1 - mov r8, r2 -_0801AA78: - adds r5, 0x4 - adds r4, 0x1 - cmp r4, 0xF - ble _0801AA5E - mov r0, sp - mov r1, r9 - bl sub_801AA08 - cmp r0, 0 - bne _0801AA9C - mov r3, r8 - cmp r3, 0x1 - beq _0801AAC4 - movs r0, 0 - b _0801AAC6 - .pool -_0801AA9C: - adds r1, r6, 0 - mov r0, sp - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldr r0, [r0] - str r0, [r1] - mov r1, r9 - mov r0, sp - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldr r0, [r0] - str r0, [r1] - ldr r0, [r6] - ldr r1, [r6, 0x4] - adds r0, r1 - ldr r1, [r6, 0x8] - adds r0, r1 - ldr r1, [r6, 0xC] - adds r0, r1 - str r0, [r6, 0xC] -_0801AAC4: - movs r0, 0x1 -_0801AAC6: - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_801AA30 - - thumb_func_start sub_801AAD4 -sub_801AAD4: @ 801AAD4 - push {r4-r7,lr} - movs r0, 0xA - bl sub_8014210 - movs r4, 0 - movs r7, 0x64 - ldr r6, =gPlayerParty - ldr r5, =gEnemyParty -_0801AAE4: - ldr r0, =gSelectedOrderFromParty - adds r0, r4, r0 - ldrb r0, [r0] - subs r0, 0x1 - adds r1, r0, 0 - muls r1, r7 - adds r1, r6 - adds r0, r5, 0 - movs r2, 0x64 - bl memcpy - adds r5, 0x64 - adds r4, 0x1 - cmp r4, 0x1 - ble _0801AAE4 - ldr r4, =gPlayerParty - movs r0, 0xFA - lsls r0, 1 - adds r5, r4, r0 -_0801AB0A: - adds r0, r4, 0 - bl ZeroMonData - adds r4, 0x64 - cmp r4, r5 - ble _0801AB0A - ldr r4, =gPlayerParty - movs r5, 0 - adds r6, r4, 0 - adds r6, 0x64 -_0801AB1E: - ldr r1, =gEnemyParty - adds r1, r5, r1 - adds r0, r4, 0 - movs r2, 0x64 - bl memcpy - adds r4, 0x64 - adds r5, 0x64 - cmp r4, r6 - ble _0801AB1E - movs r0, 0x32 - bl IncrementGameStat - bl CalculatePlayerPartyCount - ldr r0, =gTrainerBattleOpponent_A - movs r2, 0xC0 - lsls r2, 4 - adds r1, r2, 0 - strh r1, [r0] - ldr r0, =CB2_InitBattle - bl SetMainCallback2 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801AAD4 - - thumb_func_start sub_801AB68 -sub_801AB68: @ 801AB68 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - adds r5, r0, 0 - adds r7, r1, 0 - adds r6, r2, 0 - ldr r4, [sp, 0x38] - lsls r5, 24 - lsrs r5, 24 - lsls r6, 24 - lsrs r6, 24 - lsls r3, 24 - lsrs r3, 24 - movs r0, 0 - mov r9, r0 - movs r1, 0x1 - mov r10, r1 - ldr r0, =gUnknown_082F0DE4 - mov r8, r0 - ldrb r0, [r0] - lsls r1, r0, 4 - orrs r1, r0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r5, 0 - str r3, [sp, 0x14] - bl FillWindowPixelBuffer - mov r1, r9 - str r1, [sp] - mov r0, r10 - str r0, [sp, 0x4] - mov r1, r8 - str r1, [sp, 0x8] - lsls r4, 24 - asrs r4, 24 - str r4, [sp, 0xC] - str r7, [sp, 0x10] - adds r0, r5, 0 - movs r1, 0x1 - adds r2, r6, 0 - ldr r3, [sp, 0x14] - bl AddTextPrinterParameterized4 - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801AB68 - - thumb_func_start sub_801ABDC -sub_801ABDC: @ 801ABDC - push {r4-r6,lr} - sub sp, 0x4 - adds r4, r0, 0 - adds r6, r1, 0 - adds r5, r2, 0 - movs r1, 0 - ldrsh r0, [r4, r1] - cmp r0, 0 - beq _0801ABF4 - cmp r0, 0x1 - beq _0801AC22 - b _0801AC36 -_0801ABF4: - movs r0, 0 - movs r1, 0x1 - movs r2, 0xD - bl DrawTextBorderOuter - str r5, [sp] - movs r0, 0 - adds r1, r6, 0 - movs r2, 0 - movs r3, 0x1 - bl sub_801AB68 - movs r0, 0 - bl PutWindowTilemap - movs r0, 0 - movs r1, 0x3 - bl CopyWindowToVram - ldrh r0, [r4] - adds r0, 0x1 - strh r0, [r4] - b _0801AC36 -_0801AC22: - movs r0, 0 - bl IsTextPrinterActive - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0 - bne _0801AC36 - strh r0, [r4] - movs r0, 0x1 - b _0801AC38 -_0801AC36: - movs r0, 0 -_0801AC38: - add sp, 0x4 - pop {r4-r6} - pop {r1} - bx r1 - thumb_func_end sub_801ABDC - - thumb_func_start sub_801AC40 -sub_801AC40: @ 801AC40 - push {lr} - bl LoadOam - bl ProcessSpriteCopyRequests - bl TransferPlttBuffer - pop {r0} - bx r0 - thumb_func_end sub_801AC40 - - thumb_func_start sub_801AC54 -sub_801AC54: @ 801AC54 - push {r4,lr} - sub sp, 0xC - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r1, r2 - ldrb r0, [r0] - adds r2, r1, 0 - cmp r0, 0x33 - bls _0801AC6A - b _0801AFAE -_0801AC6A: - lsls r0, 2 - ldr r1, =_0801AC7C - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_0801AC7C: - .4byte _0801AD4C - .4byte _0801ADFC - .4byte _0801AE24 - .4byte _0801AE48 - .4byte _0801AE98 - .4byte _0801AFAE - .4byte _0801AF7C - .4byte _0801AF58 - .4byte _0801AF7C - .4byte _0801AF98 - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AFAE - .4byte _0801AF24 - .4byte _0801AF40 -_0801AD4C: - movs r0, 0 - movs r1, 0 - bl SetGpuReg - ldr r4, =gUnknown_02022C6C - movs r0, 0x4 - bl AllocZeroed - str r0, [r4] - bl ResetSpriteData - bl FreeAllSpritePalettes - bl ResetTasks - movs r0, 0 - bl ResetBgsAndClearDma3BusyFlags - ldr r1, =gUnknown_082F0DD0 - movs r0, 0 - movs r2, 0x1 - bl InitBgsFromTemplates - bl reset_temp_tile_data_buffers - ldr r0, =gUnknown_082F0DD4 - bl InitWindows - lsls r0, 16 - cmp r0, 0 - bne _0801AD8C - b _0801AFC2 -_0801AD8C: - bl DeactivateAllTextPrinters - movs r0, 0 - bl ClearWindowTilemap - movs r0, 0 - movs r1, 0 - bl FillWindowPixelBuffer - movs r0, 0 - movs r1, 0x11 - bl FillWindowPixelBuffer - movs r0, 0x1E - str r0, [sp] - movs r0, 0x14 - str r0, [sp, 0x4] - movs r0, 0xF - str r0, [sp, 0x8] - movs r0, 0 - movs r1, 0 - movs r2, 0 - movs r3, 0 - bl FillBgTilemapBufferRect - movs r0, 0 - movs r1, 0x1 - movs r2, 0xD0 - bl LoadUserWindowBorderGfx - movs r0, 0 - movs r1, 0x1 - movs r2, 0xD0 - bl LoadUserWindowBorderGfx_ - bl sub_819789C - ldr r0, =sub_801AC40 - bl SetVBlankCallback - ldr r1, =gMain - movs r0, 0x87 - lsls r0, 3 - adds r1, r0 - b _0801AF8A - .pool -_0801ADFC: - ldr r0, =gUnknown_02022C6C - ldr r0, [r0] - ldr r1, =gText_CommStandbyAwaitingOtherPlayer - movs r2, 0 - bl sub_801ABDC - cmp r0, 0 - bne _0801AE0E - b _0801AFAE -_0801AE0E: - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r2 - b _0801AF8A - .pool -_0801AE24: - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0x10 - movs r3, 0 - bl BeginNormalPaletteFade - movs r0, 0 - bl ShowBg - ldr r1, =gMain - movs r0, 0x87 - lsls r0, 3 - adds r1, r0 - b _0801AF8A - .pool -_0801AE48: - bl UpdatePaletteFade - lsls r0, 24 - cmp r0, 0 - beq _0801AE54 - b _0801AFAE -_0801AE54: - ldr r4, =gBlockSendBuffer - adds r0, r4, 0 - movs r1, 0 - movs r2, 0x20 - bl memset - ldr r0, =gSelectedOrderFromParty - ldrb r1, [r0] - ldrb r0, [r0, 0x1] - cmn r1, r0 - bne _0801AE78 - movs r0, 0x52 - b _0801AE7A - .pool -_0801AE78: - movs r0, 0x51 -_0801AE7A: - strb r0, [r4] - ldr r1, =gBlockSendBuffer - movs r0, 0 - movs r2, 0x20 - bl SendBlock - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r2 - b _0801AF8A - .pool -_0801AE98: - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - beq _0801AEA6 - b _0801AFAE -_0801AEA6: - ldr r1, =gBlockRecvBuffer - ldrh r0, [r1] - cmp r0, 0x51 - bne _0801AEE0 - movs r2, 0x80 - lsls r2, 1 - adds r0, r1, r2 - ldrh r0, [r0] - cmp r0, 0x51 - bne _0801AEE0 - movs r0, 0x1 - negs r0, r0 - movs r1, 0 - str r1, [sp] - movs r2, 0 - movs r3, 0x10 - bl BeginNormalPaletteFade - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r1, 0x32 - b _0801AF16 - .pool -_0801AEE0: - bl sub_800AC34 - ldr r4, =gBlockRecvBuffer - bl GetMultiplayerId - lsls r0, 24 - lsrs r0, 16 - adds r0, r4 - ldrh r0, [r0] - cmp r0, 0x52 - bne _0801AF0C - ldr r0, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r0, r2 - movs r1, 0x6 - b _0801AF16 - .pool -_0801AF0C: - ldr r0, =gMain - movs r1, 0x87 - lsls r1, 3 - adds r0, r1 - movs r1, 0x8 -_0801AF16: - strb r1, [r0] - bl ResetBlockReceivedFlags - b _0801AFAE - .pool -_0801AF24: - bl UpdatePaletteFade - lsls r0, 24 - cmp r0, 0 - bne _0801AFAE - bl sub_800ADF8 - ldr r1, =gMain - movs r2, 0x87 - lsls r2, 3 - adds r1, r2 - b _0801AF8A - .pool -_0801AF40: - bl IsLinkTaskFinished - lsls r0, 24 - cmp r0, 0 - beq _0801AFAE - ldr r0, =sub_801AAD4 - bl SetMainCallback2 - b _0801AFAE - .pool -_0801AF58: - ldr r0, =gUnknown_02022C6C - ldr r0, [r0] - ldr r1, =gText_RefusedBattle - movs r2, 0x1 - bl sub_801ABDC - cmp r0, 0 - beq _0801AFAE - ldr r0, =CB2_ReturnToField - bl SetMainCallback2 - b _0801AFAE - .pool -_0801AF7C: - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - bne _0801AFAE - movs r0, 0x87 - lsls r0, 3 - adds r1, r2, r0 -_0801AF8A: - ldrb r0, [r1] - adds r0, 0x1 - strb r0, [r1] - b _0801AFAE - .pool -_0801AF98: - ldr r0, =gUnknown_02022C6C - ldr r0, [r0] - ldr r1, =gText_BattleWasRefused - movs r2, 0x1 - bl sub_801ABDC - cmp r0, 0 - beq _0801AFAE - ldr r0, =CB2_ReturnToField - bl SetMainCallback2 -_0801AFAE: - bl RunTasks - bl RunTextPrinters - bl AnimateSprites - bl BuildOamBuffer - bl UpdatePaletteFade -_0801AFC2: - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801AC54 diff --git a/data/union_room_battle.s b/data/union_room_battle.s deleted file mode 100755 index 65391a82e..000000000 --- a/data/union_room_battle.s +++ /dev/null @@ -1,17 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - - .align 2 -gUnknown_082F0DD0:: @ 82F0DD0 - .4byte 0x000001FC - - .align 2 -gUnknown_082F0DD4:: @ 82F0DD4 - window_template 0x00, 0x03, 0x0f, 0x18, 0x04, 0x0e, 0x0014 - null_window_template - - .align 2 -gUnknown_082F0DE4:: @ 82F0DE4 - .byte 0x01, 0x02, 0x03 diff --git a/include/constants/game_stat.h b/include/constants/game_stat.h index 7ebf3501b..e302f1345 100644 --- a/include/constants/game_stat.h +++ b/include/constants/game_stat.h @@ -51,7 +51,7 @@ #define GAME_STAT_USED_DAYCARE 47 #define GAME_STAT_RODE_CABLE_CAR 48 #define GAME_STAT_ENTERED_HOT_SPRINGS 49 -#define GAME_STAT_50 50 +#define GAME_STAT_NUM_UNION_ROOM_BATTLES 50 #define GAME_STAT_51 51 #define NUM_USED_GAME_STATS 52 diff --git a/include/main.h b/include/main.h index 6c67fbe9f..16ac31df2 100644 --- a/include/main.h +++ b/include/main.h @@ -71,6 +71,6 @@ void RestoreSerialTimer3IntrHandlers(void); void StartTimer1(void); void SeedRngAndSetTrainerId(void); u16 GetGeneratedTrainerIdLower(void); - +void sub_819789C(void); #endif // GUARD_MAIN_H diff --git a/include/strings.h b/include/strings.h index 99c9ce73c..8aa296eb1 100644 --- a/include/strings.h +++ b/include/strings.h @@ -2677,5 +2677,8 @@ extern const u8 gText_PeopleTrading[]; extern const u8 gText_PeopleBattling[]; extern const u8 gText_PeopleInUnionRoom[]; extern const u8 gText_PeopleCommunicating[]; +extern const u8 gText_CommStandbyAwaitingOtherPlayer[]; +extern const u8 gText_RefusedBattle[]; +extern const u8 gText_BattleWasRefused[]; #endif // GUARD_STRINGS_H diff --git a/include/union_room_battle.h b/include/union_room_battle.h index 1bc9d0015..2f5086008 100644 --- a/include/union_room_battle.h +++ b/include/union_room_battle.h @@ -2,5 +2,6 @@ #define GUARD_UNION_ROOM_BATTLE_H u8 sub_8013C40(void); +void sub_8014210(u16 battleFlags); #endif //GUARD_UNION_ROOM_BATTLE_H diff --git a/ld_script.txt b/ld_script.txt index 2b0d0dd89..619abfce1 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -58,7 +58,6 @@ SECTIONS { src/mystery_gift.o(.text); src/union_room_player_avatar.o(.text); src/union_room_battle.o(.text); - asm/union_room_battle.o(.text); src/mevent2.o(.text); src/mevent_801BAAC.o(.text); asm/mevent_server.o(.text); @@ -415,7 +414,6 @@ SECTIONS { src/mystery_gift.o(.rodata); src/union_room_player_avatar.o(.rodata); src/union_room_battle.o(.rodata); - data/union_room_battle.o(.rodata); src/mevent2.o(.rodata); src/mevent_801BAAC.o(.rodata); data/mevent_server.o(.rodata); diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index ec5cb238b..ddd3f931e 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -914,7 +914,7 @@ struct Story }; static const struct Story sStorytellerStories[] = { - {GAME_STAT_50, 1, MauvilleCity_PokemonCenter_1F_Text_28E930, MauvilleCity_PokemonCenter_1F_Text_28E947, MauvilleCity_PokemonCenter_1F_Text_28E956}, + {GAME_STAT_NUM_UNION_ROOM_BATTLES, 1, MauvilleCity_PokemonCenter_1F_Text_28E930, MauvilleCity_PokemonCenter_1F_Text_28E947, MauvilleCity_PokemonCenter_1F_Text_28E956}, {GAME_STAT_STARTED_TRENDS, 1, MauvilleCity_PokemonCenter_1F_Text_28E9D7, MauvilleCity_PokemonCenter_1F_Text_28E9EF, MauvilleCity_PokemonCenter_1F_Text_28E9FE}, {GAME_STAT_PLANTED_BERRIES, 1, MauvilleCity_PokemonCenter_1F_Text_28EA7D, MauvilleCity_PokemonCenter_1F_Text_28EA98, MauvilleCity_PokemonCenter_1F_Text_28EAA8}, {GAME_STAT_TRADED_BIKES, 1, MauvilleCity_PokemonCenter_1F_Text_28EB19, MauvilleCity_PokemonCenter_1F_Text_28EB31, MauvilleCity_PokemonCenter_1F_Text_28EB3E}, diff --git a/src/union_room.c b/src/union_room.c index 88ac65baa..ea3658903 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -2332,7 +2332,7 @@ void sub_8013F90(u8 taskId) if (GetBlockReceivedStatus() == 3) { gEnemyParty[0] = *(struct Pokemon*)(gBlockRecvBuffer[GetMultiplayerId() ^ 1]); - IncrementGameStat(GAME_STAT_50); + IncrementGameStat(GAME_STAT_NUM_UNION_ROOM_BATTLES); ResetBlockReceivedFlags(); gTasks[taskId].data[0]++; } diff --git a/src/union_room_battle.c b/src/union_room_battle.c index b571e803a..9d9f9dcf3 100644 --- a/src/union_room_battle.c +++ b/src/union_room_battle.c @@ -9,6 +9,7 @@ #include "alloc.h" #include "menu.h" #include "window.h" +#include "text_window.h" #include "scanline_effect.h" #include "m4a.h" #include "dynamic_placeholder_text_util.h" @@ -18,6 +19,9 @@ #include "international_string_util.h" #include "sound.h" #include "constants/songs.h" +#include "party_menu.h" +#include "battle_setup.h" +#include "link.h" #include "union_room.h" #include "union_room_battle.h" @@ -31,13 +35,20 @@ struct UnkStruct_3000DAC /*0x62*/ u8 filler_62[10]; }; +struct UnkStruct_2022C6C +{ + s16 a0; +}; + IWRAM_DATA struct UnkStruct_3000DAC * gUnknown_03000DAC; IWRAM_DATA bool32 gUnknown_03000DB0; +EWRAM_DATA struct UnkStruct_2022C6C * gUnknown_02022C6C = NULL; + void sub_801A43C(void); void sub_801A6C0(u8 taskId); static void sub_801A8B0(u8 windowId, u8 fontId, const u8 * str, u8 x, u8 y, u8 mode); -bool32 sub_801AA30(u32 * a0, u32 * a1, u32 * a2, u8 a3); +bool32 sub_801AA30(u32 * a0, u32 * a1, u32 * a2, u8 taskId); const u16 gWirelessInfoScreenPal[] = INCBIN_U16("graphics/interface/wireless_info_screen.gbapal"); const u32 gWirelessInfoScreenGfx[] = INCBIN_U32("graphics/interface/wireless_info_screen.4bpp.lz"); @@ -128,6 +139,29 @@ const u8 gUnknown_082F0D70[][3] = { {0x0e, 0x01, 0x02} }; +const struct BgTemplate gUnknown_082F0DD0[] = { + { + .bg = 0, + .charBaseIndex = 3, + .mapBaseIndex = 31 + } +}; + +const struct WindowTemplate gUnknown_082F0DD4[] = { + { + .bg = 0, + .tilemapLeft = 3, + .tilemapTop = 15, + .width = 24, + .height = 4, + .paletteNum = 0xE, + .baseBlock = 0x014 + }, + { 0xFF } +}; + +const u8 gUnknown_082F0DE4[] = { 1, 2, 3 }; + void sub_801A3F4(void) { if (!IsDma3ManagerBusyWithBgCopy()) @@ -333,12 +367,10 @@ static void sub_801A8B0(u8 windowId, u8 fontId, const u8 * str, u8 x, u8 y, u8 m AddTextPrinterParameterized4(windowId, fontId, x, y, 0, 0, color, -1, str); } -#ifdef NONMATCHING -// register swap r2, r3 -u8 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) +u32 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) { s32 i, j, r2; - u8 result = a0->unk.field_0.unk_0a_0; + u32 result = a0->unk.field_0.unk_0a_0; for (i = 0; i < (unsigned)ARRAY_COUNT(gUnknown_082F0D70); i++) { @@ -370,97 +402,230 @@ u8 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) } return result; } -#else -NAKED -u8 sub_801A960(struct UnkStruct_x20 * a0, u32 * a1) + +bool32 sub_801AA08(u32 * a0, u32 * a1) { - 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, 0x4\n" - "\tmov r12, r0\n" - "\tadds r7, r1, 0\n" - "\tldrb r0, [r0, 0xA]\n" - "\tlsls r0, 25\n" - "\tlsrs r0, 25\n" - "\tmov r8, r0\n" - "\tmovs r4, 0\n" - "\tldr r0, =gUnknown_082F0D70\n" - "\tmov r9, r0\n" - "\tmovs r1, 0x1\n" - "\tadd r1, r9\n" - "\tmov r10, r1\n" - "\tmov r3, r12\n" - "\tadds r3, 0x4\n" - "\tstr r3, [sp]\n" - "_0801A98A:\n" - "\tlsls r0, r4, 1\n" - "\tadds r2, r0, r4\n" - "\tmov r3, r9\n" - "\tadds r1, r2, r3\n" - "\tadds r5, r0, 0\n" - "\tadds r6, r4, 0x1\n" - "\tldrb r1, [r1]\n" - "\tcmp r8, r1\n" - "\tbne _0801A9EE\n" - "\tmov r0, r12\n" - "\tldrb r1, [r0, 0x1A]\n" - "\tmovs r0, 0x3\n" - "\tands r0, r1\n" - "\tcmp r0, 0x1\n" - "\tbne _0801A9EE\n" - "\tmov r0, r9\n" - "\tadds r0, 0x2\n" - "\tadds r3, r2, r0\n" - "\tldrb r0, [r3]\n" - "\tcmp r0, 0\n" - "\tbne _0801A9DC\n" - "\tmovs r2, 0\n" - "\tmovs r1, 0\n" - "\tldr r3, [sp]\n" - "_0801A9BA:\n" - "\tadds r0, r3, r1\n" - "\tldrb r0, [r0]\n" - "\tcmp r0, 0\n" - "\tbeq _0801A9C4\n" - "\tadds r2, 0x1\n" - "_0801A9C4:\n" - "\tadds r1, 0x1\n" - "\tcmp r1, 0x3\n" - "\tble _0801A9BA\n" - "\tadds r2, 0x1\n" - "\tadds r0, r5, r4\n" - "\tadd r0, r10\n" - "\tldrb r1, [r0]\n" - "\tlsls r1, 2\n" - "\tadds r1, r7\n" - "\tb _0801A9E8\n" - "\t.pool\n" - "_0801A9DC:\n" - "\tmov r1, r10\n" - "\tadds r0, r2, r1\n" - "\tldrb r1, [r0]\n" - "\tlsls r1, 2\n" - "\tadds r1, r7\n" - "\tldrb r2, [r3]\n" - "_0801A9E8:\n" - "\tldr r0, [r1]\n" - "\tadds r0, r2\n" - "\tstr r0, [r1]\n" - "_0801A9EE:\n" - "\tadds r4, r6, 0\n" - "\tcmp r4, 0x1E\n" - "\tbls _0801A98A\n" - "\tmov r0, r8\n" - "\tadd sp, 0x4\n" - "\tpop {r3-r5}\n" - "\tmov r8, r3\n" - "\tmov r9, r4\n" - "\tmov r10, r5\n" - "\tpop {r4-r7}\n" - "\tpop {r1}\n" - "\tbx r1"); + s32 i; + for (i = 0; i < 4; i++) + { + if (a0[i] != a1[i]) + { + return TRUE; + } + } + return FALSE; +} + +bool32 sub_801AA30(u32 * a0, u32 * a1, u32 * a2, u8 taskId) +{ + bool32 r8 = FALSE; + u32 sp0[4] = {0, 0, 0, 0}; + struct UnkStruct_x20 ** data = (void *)gTasks[taskId].data; + s32 i; + + for (i = 0; i < 16; i++) + { + u32 r1 = sub_801A960(&(*data)[i], sp0); + if (r1 != a2[i]) + { + a2[i] = r1; + r8 = TRUE; + } + } + if (sub_801AA08(sp0, a1) == 0) + { + if (r8 != TRUE) + { + return FALSE; + } + } + else + { + memcpy(a0, sp0, sizeof(sp0)); + memcpy(a1, sp0, sizeof(sp0)); + a0[3] = a0[0] + a0[1] + a0[2] + a0[3]; + } + return TRUE; +} + +void sub_801AAD4(void) +{ + s32 i; + sub_8014210(10); + for (i = 0; i < 2; i++) + { + gEnemyParty[i] = gPlayerParty[gSelectedOrderFromParty[i] - 1]; + } + for (i = 0; i < 6; i++) + { + ZeroMonData(&gPlayerParty[i]); + } + for (i = 0; i < 2; i++) + { + gPlayerParty[i] = gEnemyParty[i]; + } + IncrementGameStat(GAME_STAT_NUM_UNION_ROOM_BATTLES); + CalculatePlayerPartyCount(); + gTrainerBattleOpponent_A = 0xC00; + SetMainCallback2(CB2_InitBattle); +} + +void sub_801AB68(u8 windowId, const u8 * str, u8 x, u8 y, s32 speed) +{ + s32 letterSpacing = 0; + s32 lineSpacing = 1; + FillWindowPixelBuffer(windowId, (gUnknown_082F0DE4[0] << 4) | gUnknown_082F0DE4[0]); + AddTextPrinterParameterized4(windowId, 1, x, y, letterSpacing, lineSpacing, gUnknown_082F0DE4, speed, str); +} + +bool32 sub_801ABDC(s16 * state, const u8 * str, s32 speed) +{ + switch (*state) + { + case 0: + DrawTextBorderOuter(0, 0x001, 0xD); + sub_801AB68(0, str, 0, 1, speed); + PutWindowTilemap(0); + CopyWindowToVram(0, 3); + (*state)++; + break; + case 1: + if (!IsTextPrinterActive(0)) + { + *state = 0; + return TRUE; + } + break; + } + return FALSE; +} + +void sub_801AC40(void) +{ + LoadOam(); + ProcessSpriteCopyRequests(); + TransferPlttBuffer(); +} + +void sub_801AC54(void) +{ + switch (gMain.state) + { + case 0: + SetGpuReg(REG_OFFSET_DISPCNT, 0x0000); + gUnknown_02022C6C = AllocZeroed(4); + ResetSpriteData(); + FreeAllSpritePalettes(); + ResetTasks(); + ResetBgsAndClearDma3BusyFlags(0); + InitBgsFromTemplates(0, gUnknown_082F0DD0, 1); + reset_temp_tile_data_buffers(); + if (!InitWindows(gUnknown_082F0DD4)) + { + return; + } + DeactivateAllTextPrinters(); + ClearWindowTilemap(0); + FillWindowPixelBuffer(0, 0x00); + FillWindowPixelBuffer(0, 0x11); + FillBgTilemapBufferRect(0, 0, 0, 0, 30, 20, 0xF); + LoadUserWindowBorderGfx(0, 1, 0xD0); + LoadUserWindowBorderGfx_(0, 1, 0xD0); + sub_819789C(); + SetVBlankCallback(sub_801AC40); + gMain.state++; + break; + case 1: + if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_CommStandbyAwaitingOtherPlayer, 0)) + { + gMain.state++; + } + break; + case 2: + BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0); + ShowBg(0); + gMain.state++; + break; + case 3: + if (!UpdatePaletteFade()) + { + memset(gBlockSendBuffer, 0, 0x20); + if (gSelectedOrderFromParty[0] == -gSelectedOrderFromParty[1]) + { + gBlockSendBuffer[0] = 0x52; + } + else + { + gBlockSendBuffer[0] = 0x51; + } + SendBlock(0, gBlockSendBuffer, 0x20); + gMain.state++; + } + break; + case 4: + if (GetBlockReceivedStatus() == 3) + { + if (gBlockRecvBuffer[0][0] == 0x51 && gBlockRecvBuffer[1][0] == 0x51) + { + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0); + gMain.state = 50; + } + else + { + sub_800AC34(); + if (gBlockRecvBuffer[GetMultiplayerId()][0] == 0x52) + { + gMain.state = 6; + } + else + { + gMain.state = 8; + } + } + ResetBlockReceivedFlags(); + } + break; + case 50: + if (!UpdatePaletteFade()) + { + sub_800ADF8(); + gMain.state++; + } + break; + case 51: + if (IsLinkTaskFinished()) + { + SetMainCallback2(sub_801AAD4); + } + break; + case 6: + if (gReceivedRemoteLinkPlayers == 0) + { + gMain.state++; + } + break; + case 7: + if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_RefusedBattle, 1)) + { + SetMainCallback2(CB2_ReturnToField); + } + break; + case 8: + if (gReceivedRemoteLinkPlayers == 0) + { + gMain.state++; + } + break; + case 9: + if (sub_801ABDC(&gUnknown_02022C6C->a0, gText_BattleWasRefused, 1)) + { + SetMainCallback2(CB2_ReturnToField); + } + break; + } + RunTasks(); + RunTextPrinters(); + AnimateSprites(); + BuildOamBuffer(); + UpdatePaletteFade(); } -#endif //NONMATCHING diff --git a/sym_ewram.txt b/sym_ewram.txt index 8cb156837..d029ad78f 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -9,10 +9,7 @@ .include "src/union_room.o" .include "src/mystery_gift.o" .include "src/union_room_player_avatar.o" - -gUnknown_02022C6C: @ 2022C6C - .space 0x4 - + .include "src/union_room_battle.o" .include "src/mevent2.o" .include "src/mevent_801BAAC.o"