diff options
author | Cameron Hall <cameronghall@cox.net> | 2018-01-25 21:33:46 -0600 |
---|---|---|
committer | Cameron Hall <cameronghall@cox.net> | 2018-01-25 21:33:46 -0600 |
commit | 33d2d51906bbde1c62cee3470a9b3706571d551c (patch) | |
tree | 0dfc7c3ccc0f55f8eb1c11b8445f874c1423d72d /src | |
parent | e50f5e906776a799ec69418168f032880e16384c (diff) |
decompile more debug functions
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/battle_2.c | 237 | ||||
-rw-r--r-- | src/battle/battle_ai.c | 217 |
2 files changed, 69 insertions, 385 deletions
diff --git a/src/battle/battle_2.c b/src/battle/battle_2.c index f9756db29..e72a875fb 100644 --- a/src/battle/battle_2.c +++ b/src/battle/battle_2.c @@ -6,6 +6,7 @@ #include "constants/moves.h" #include "constants/songs.h" #include "constants/species.h" +#include "gba/flash_internal.h" #include "battle.h" #include "battle_ai.h" #include "battle_interface.h" @@ -1500,6 +1501,17 @@ void debug_sub_80108B8(void) } } +// This function matches, but it somehow affects registers in SetActionsAndBanksTurnOrder. +#ifdef NONMATCHING +void debug_sub_8010A7C(u8 a, u8 b) +{ + s32 i; + + for (i = 0; i < b; i++) + gBattleTextBuff1[i] = a; + gBattleTextBuff1[i] = EOS; +} +#else __attribute__((naked)) void debug_sub_8010A7C() { @@ -1534,6 +1546,14 @@ void debug_sub_8010A7C() "\n" ); } +#endif + +/* +void debug_sub_8010AAC(u8 a) +{ + u32 r7 = gUnknown_Debug_030043A4 * 5; +} +*/ __attribute__((naked)) void debug_sub_8010AAC() @@ -3898,72 +3918,19 @@ void debug_sub_801174C() ); } -__attribute__((naked)) -void debug_sub_8011D40() +void debug_sub_8011D40(void) { - asm( - " push {lr}\n" - " ldr r1, ._774\n" - " ldr r0, ._774 + 4\n" - " str r0, [r1]\n" - " ldr r0, ._774 + 8\n" - " str r0, [r1, #0x4]\n" - " ldr r0, ._774 + 12\n" - " str r0, [r1, #0x8]\n" - " ldr r0, [r1, #0x8]\n" - " sub r1, r1, #0xc4\n" - " ldr r0, ._774 + 16\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 20\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 24\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 28\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 32\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 36\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 40\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " add r1, r1, #0x2\n" - " ldr r0, ._774 + 44\n" - " ldrh r0, [r0]\n" - " strh r0, [r1]\n" - " bl LoadOam\n" - " bl ProcessSpriteCopyRequests\n" - " pop {r0}\n" - " bx r0\n" - "._775:\n" - " .align 2, 0\n" - "._774:\n" - " .word 0x40000d4\n" - " .word gSharedMem\n" - " .word 0x6004000\n" - " .word 0x80000800\n" - " .word gBattle_BG0_X\n" - " .word gBattle_BG0_Y\n" - " .word gBattle_BG1_X\n" - " .word gBattle_BG1_Y\n" - " .word gBattle_BG2_X\n" - " .word gBattle_BG2_Y\n" - " .word gBattle_BG3_X\n" - " .word gBattle_BG3_Y\n" - "\n" - ); + DmaCopy16(3, gSharedMem, (void *)(VRAM + 0x4000), 0x1000); + REG_BG0HOFS = gBattle_BG0_X; + REG_BG0VOFS = gBattle_BG0_Y; + REG_BG1HOFS = gBattle_BG1_X; + REG_BG1VOFS = gBattle_BG1_Y; + REG_BG2HOFS = gBattle_BG2_X; + REG_BG2VOFS = gBattle_BG2_Y; + REG_BG3HOFS = gBattle_BG3_X; + REG_BG3VOFS = gBattle_BG3_Y; + LoadOam(); + ProcessSpriteCopyRequests(); } void debug_nullsub_45() @@ -6517,125 +6484,45 @@ void debug_sub_8012D10() ); } -__attribute__((naked)) -void debug_sub_8013240() +u8 debug_sub_8013240(void) { - asm( - " push {lr}\n" - " bl IdentifyFlash\n" - " lsl r0, r0, #0x10\n" - " cmp r0, #0\n" - " beq ._1068 @cond_branch\n" - " mov r0, #0x1\n" - " b ._1069\n" - "._1068:\n" - " mov r0, #0x0\n" - "._1069:\n" - " pop {r1}\n" - " bx r1\n" - "\n" - ); + if (IdentifyFlash() == 0) + return 0; + else + return 1; } -__attribute__((naked)) -void debug_sub_8013258() +u32 debug_sub_8013258(u16 sectorNum, u8 *data, u32 size) { - asm( - " push {r4, r5, r6, lr}\n" - " add r6, r1, #0\n" - " add r5, r2, #0\n" - " b ._1070\n" - "._1072:\n" - " ldr r0, ._1074\n" - " add r5, r5, r0\n" - " mov r0, #0x80\n" - " lsl r0, r0, #0x5\n" - " add r6, r6, r0\n" - " add r0, r4, #1\n" - "._1070:\n" - " lsl r0, r0, #0x10\n" - " lsr r4, r0, #0x10\n" - " add r0, r4, #0\n" - " add r1, r6, #0\n" - " bl ProgramFlashSectorAndVerify\n" - " cmp r0, #0\n" - " bne ._1071 @cond_branch\n" - " mov r0, #0x80\n" - " lsl r0, r0, #0x5\n" - " cmp r5, r0\n" - " bhi ._1072 @cond_branch\n" - " mov r0, #0x1\n" - " b ._1073\n" - "._1075:\n" - " .align 2, 0\n" - "._1074:\n" - " .word 0xfffff000\n" - "._1071:\n" - " mov r0, #0x0\n" - "._1073:\n" - " pop {r4, r5, r6}\n" - " pop {r1}\n" - " bx r1\n" - "\n" - ); + while (1) + { + if (ProgramFlashSectorAndVerify(sectorNum, data) != 0) + return 0; + if (size <= 0x1000) + break; + size -= 0x1000; + data += 0x1000; + sectorNum++; + } + return 1; } -__attribute__((naked)) -void debug_sub_8013294() +u32 debug_sub_8013294(u8 sectorNum, void *data, u32 size) { - asm( - " push {r4, r5, r6, lr}\n" - " add r5, r1, #0\n" - " add r6, r2, #0\n" - " lsl r0, r0, #0x18\n" - " lsr r4, r0, #0x18\n" - " bl debug_sub_8013240\n" - " lsl r0, r0, #0x18\n" - " cmp r0, #0\n" - " bne ._1076 @cond_branch\n" - " bl m4aSoundVSyncOff\n" - " add r0, r4, #0\n" - " add r1, r5, #0\n" - " add r2, r6, #0\n" - " bl debug_sub_8013258\n" - " add r4, r0, #0\n" - " bl m4aSoundVSyncOn\n" - " add r0, r4, #0\n" - " b ._1077\n" - "._1076:\n" - " mov r0, #0x0\n" - "._1077:\n" - " pop {r4, r5, r6}\n" - " pop {r1}\n" - " bx r1\n" - "\n" - ); + u32 result; + + if (debug_sub_8013240() != 0) + return 0; + m4aSoundVSyncOff(); + result = debug_sub_8013258(sectorNum, data, size); + m4aSoundVSyncOn(); + return result; } -__attribute__((naked)) -void debug_sub_80132C8() +void debug_sub_80132C8(u8 a, void *b, u32 c) { - asm( - " push {r4, r5, r6, lr}\n" - " add r5, r1, #0\n" - " add r6, r2, #0\n" - " lsl r0, r0, #0x18\n" - " lsr r4, r0, #0x18\n" - " bl debug_sub_8013240\n" - " lsl r0, r0, #0x18\n" - " cmp r0, #0\n" - " bne ._1078 @cond_branch\n" - " add r0, r4, #0\n" - " mov r1, #0x0\n" - " add r2, r5, #0\n" - " add r3, r6, #0\n" - " bl ReadFlash\n" - "._1078:\n" - " pop {r4, r5, r6}\n" - " pop {r0}\n" - " bx r0\n" - "\n" - ); + if (debug_sub_8013240() == 0) + ReadFlash(a, 0, b, c); } #endif @@ -10146,7 +10033,7 @@ void SetActionsAndBanksTurnOrder(void) // And doing this seems to fix it. #if DEBUG asm("");asm("");asm("");asm("");asm("");asm("");asm("");asm("");asm(""); - asm("");asm("");asm("");asm("");asm("");asm("");asm("");asm(""); + asm("");asm("");asm("");asm("");asm("");asm("");asm(""); #endif gBattleMainFunc = CheckFocusPunch_ClearVarsBeforeTurnStarts; eFocusPunchBank = 0; diff --git a/src/battle/battle_ai.c b/src/battle/battle_ai.c index 87a66c2c7..629a57d25 100644 --- a/src/battle/battle_ai.c +++ b/src/battle/battle_ai.c @@ -13,6 +13,8 @@ #include "util.h" #include "ewram.h" +extern u8 gUnknown_02023A14_50; +extern u32 gUnknown_02023A14_4C; extern u16 gBattleTypeFlags; extern u16 gBattleWeather; extern u8 gActiveBank; @@ -289,214 +291,6 @@ void BattleAI_HandleItemUseBeforeAISetup(void) BattleAI_SetupAIData(); } -#if DEBUG -__attribute__((naked)) -void BattleAI_SetupAIData() -{ - asm( - " push {r4, r5, r6, r7, lr}\n" - " ldr r2, ._16\n" - " mov r4, #0x0\n" - " ldr r3, ._16 + 4\n" - " mov r1, #0x0\n" - "._9:\n" - " add r0, r2, r4\n" - " strb r1, [r0]\n" - " add r4, r4, #0x1\n" - " cmp r4, #0x1b\n" - " bls ._9 @cond_branch\n" - " ldr r0, ._16\n" - " mov r1, #0x64\n" - " mov r4, #0x3\n" - " add r0, r0, #0x7\n" - "._10:\n" - " strb r1, [r0]\n" - " sub r0, r0, #0x1\n" - " sub r4, r4, #0x1\n" - " cmp r4, #0\n" - " bge ._10 @cond_branch\n" - " ldrb r0, [r3]\n" - " mov r1, #0x0\n" - " mov r2, #0xff\n" - " bl CheckMoveLimitations\n" - " lsl r0, r0, #0x18\n" - " lsr r7, r0, #0x18\n" - " mov r4, #0x0\n" - " ldr r0, ._16\n" - " add r5, r0, #4\n" - " ldr r6, ._16 + 8\n" - "._12:\n" - " ldr r0, [r6]\n" - " and r0, r0, r7\n" - " cmp r0, #0\n" - " beq ._11 @cond_branch\n" - " mov r0, #0x0\n" - " strb r0, [r5]\n" - "._11:\n" - " bl Random\n" - " lsl r0, r0, #0x10\n" - " lsr r0, r0, #0x10\n" - " mov r1, #0xf\n" - " and r0, r0, r1\n" - " mov r1, #0x64\n" - " sub r1, r1, r0\n" - " strb r1, [r5, #0x14]\n" - " add r5, r5, #0x1\n" - " add r6, r6, #0x4\n" - " add r4, r4, #0x1\n" - " cmp r4, #0x3\n" - " ble ._12 @cond_branch\n" - " ldr r0, ._16 + 12\n" - " add r0, r0, #0x20\n" - " mov r1, #0x0\n" - " strb r1, [r0]\n" - " ldr r1, ._16 + 16\n" - " ldr r0, ._16 + 4\n" - " ldrb r2, [r0]\n" - " strb r2, [r1]\n" - " ldr r0, ._16 + 20\n" - " ldrh r1, [r0]\n" - " mov r0, #0x1\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " beq ._13 @cond_branch\n" - " ldr r4, ._16 + 24\n" - " bl Random\n" - " mov r5, #0x2\n" - " and r0, r0, r5\n" - " strb r0, [r4]\n" - " ldr r0, ._16 + 28\n" - " ldrb r1, [r0]\n" - " ldr r2, ._16 + 8\n" - " ldrb r3, [r4]\n" - " lsl r0, r3, #0x2\n" - " add r0, r0, r2\n" - " ldr r0, [r0]\n" - " and r1, r1, r0\n" - " cmp r1, #0\n" - " beq ._15 @cond_branch\n" - " eor r3, r3, r5\n" - " strb r3, [r4]\n" - " b ._15\n" - "._17:\n" - " .align 2, 0\n" - "._16:\n" - " .word gSharedMem+0x16800\n" - " .word gActiveBank\n" - " .word gBitTable\n" - " .word +0x2016c00\n" - " .word gBankAttacker\n" - " .word gBattleTypeFlags\n" - " .word gBankTarget\n" - " .word gAbsentBankFlags\n" - "._13:\n" - " ldr r0, ._20\n" - " mov r1, #0x1\n" - " eor r1, r1, r2\n" - " strb r1, [r0]\n" - "._15:\n" - " ldr r0, ._20 + 4\n" - " ldrh r1, [r0]\n" - " mov r0, #0x80\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " beq ._18 @cond_branch\n" - " ldr r1, ._20 + 8\n" - " mov r0, #0x80\n" - " lsl r0, r0, #0x17\n" - " b ._27\n" - "._21:\n" - " .align 2, 0\n" - "._20:\n" - " .word gBankTarget\n" - " .word gBattleTypeFlags\n" - " .word gSharedMem+0x16800\n" - "._18:\n" - " mov r2, #0x80\n" - " lsl r2, r2, #0x3\n" - " add r0, r2, #0\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " beq ._22 @cond_branch\n" - " ldr r1, ._24\n" - " mov r0, #0x80\n" - " lsl r0, r0, #0x16\n" - " b ._27\n" - "._25:\n" - " .align 2, 0\n" - "._24:\n" - " .word gSharedMem+0x16800\n" - "._22:\n" - " mov r0, #0x10\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " beq ._26 @cond_branch\n" - " ldr r1, ._28\n" - " mov r0, #0x80\n" - " lsl r0, r0, #0x18\n" - " b ._27\n" - "._29:\n" - " .align 2, 0\n" - "._28:\n" - " .word gSharedMem+0x16800\n" - "._26:\n" - " mov r0, #0x90\n" - " lsl r0, r0, #0x4\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " bne ._30 @cond_branch\n" - " ldr r1, ._33\n" - " ldrh r0, [r1]\n" - " cmp r0, r2\n" - " bne ._31 @cond_branch\n" - "._30:\n" - " ldr r1, ._33 + 4\n" - " mov r0, #0x7\n" - "._27:\n" - " str r0, [r1, #0xc]\n" - " add r3, r1, #0\n" - " b ._32\n" - "._34:\n" - " .align 2, 0\n" - "._33:\n" - " .word gTrainerBattleOpponent\n" - " .word gSharedMem+0x16800\n" - "._31:\n" - " ldr r3, ._36\n" - " ldr r2, ._36 + 4\n" - " ldrh r1, [r1]\n" - " lsl r0, r1, #0x2\n" - " add r0, r0, r1\n" - " lsl r0, r0, #0x3\n" - " add r2, r2, #0x1c\n" - " add r0, r0, r2\n" - " ldr r0, [r0]\n" - " str r0, [r3, #0xc]\n" - "._32:\n" - " ldr r0, ._36 + 8\n" - " ldrb r1, [r0]\n" - " mov r0, #0x1\n" - " and r0, r0, r1\n" - " cmp r0, #0\n" - " beq ._35 @cond_branch\n" - " ldr r0, ._36 + 12\n" - " ldr r0, [r0]\n" - " str r0, [r3, #0xc]\n" - "._35:\n" - " pop {r4, r5, r6, r7}\n" - " pop {r0}\n" - " bx r0\n" - "._37:\n" - " .align 2, 0\n" - "._36:\n" - " .word gSharedMem+0x16800\n" - " .word gTrainers\n" - " .word gUnknown_02023A14_50\n" - " .word gUnknown_02023A14_4C\n" - "\n" - ); -} -#else void BattleAI_SetupAIData(void) { s32 i; @@ -544,13 +338,16 @@ void BattleAI_SetupAIData(void) else if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE) AI_THINKING_STRUCT->aiFlags = 0x80000000; #ifdef GERMAN - else if (gBattleTypeFlags & 0x900 || gTrainerBattleOpponent == 0x400) + else if (gBattleTypeFlags & (BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_BATTLE_TOWER) || gTrainerBattleOpponent == 0x400) AI_THINKING_STRUCT->aiFlags = 7; #endif else // otherwise, just set aiFlags to whatever flags the trainer has set in their data. AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent].aiFlags; -} +#if DEBUG + if (gUnknown_02023A14_50 & 1) + AI_THINKING_STRUCT->aiFlags = gUnknown_02023A14_4C; #endif +} u8 BattleAI_GetAIActionToUse(void) { |