From 3dea8fa2658cb1055fb835983e8a738cf543e232 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 29 Aug 2018 20:38:54 +0200 Subject: [PATCH] battle tent review changes --- asm/battle_tent.s | 188 ------------------------------------ include/gba/io_reg.h | 2 + src/battle_dome.c | 47 ++++----- src/battle_tent.c | 225 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 233 insertions(+), 229 deletions(-) diff --git a/asm/battle_tent.s b/asm/battle_tent.s index ba4a31530..8de98850f 100644 --- a/asm/battle_tent.s +++ b/asm/battle_tent.s @@ -6,194 +6,6 @@ .text - thumb_func_start sub_81B9EC0 -sub_81B9EC0: @ 81B9EC0 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x3C - ldr r1, =gFacilityTrainers - ldr r0, =gSlateportBattleTentTrainers - str r0, [r1] - add r0, sp, 0xC - mov r9, r0 - mov r1, sp - adds r1, 0x18 - str r1, [sp, 0x2C] - ldr r5, =gFacilityTrainerMons - ldr r4, =gSlateportBattleTentMons - movs r2, 0 - adds r3, r1, 0 - mov r1, r9 - mov r0, sp - movs r6, 0x5 - mov r8, r6 -_081B9EEC: - strh r2, [r0] - strh r2, [r1] - strh r2, [r3] - adds r3, 0x2 - adds r1, 0x2 - adds r0, 0x2 - movs r7, 0x1 - negs r7, r7 - add r8, r7 - mov r6, r8 - cmp r6, 0 - bge _081B9EEC - str r4, [r5] - movs r7, 0 - mov r10, r7 - movs r0, 0 - mov r8, r0 - ldr r1, [sp, 0x2C] - str r1, [sp, 0x30] - mov r2, sp - str r2, [sp, 0x34] - lsls r6, r0, 1 - str r6, [sp, 0x24] - add r6, r9 - str r6, [sp, 0x28] -_081B9F1E: - bl Random - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x46 - bl __umodsi3 - lsls r0, 16 - lsrs r5, r0, 16 - movs r2, 0 - mov r7, r8 - adds r6, r2, r7 - cmp r2, r6 - bge _081B9F7C - ldr r1, [sp, 0x28] - ldrh r0, [r1] - cmp r0, r5 - beq _081B9F7C - ldr r0, =gFacilityTrainerMons - ldr r1, [r0] - lsls r0, r5, 4 - adds r4, r0, r1 - ldrh r7, [r4] - mov r12, r7 - lsls r3, r2, 1 - ldr r1, [sp, 0x24] - add r1, sp - str r6, [sp, 0x38] -_081B9F56: - ldrh r0, [r1] - cmp r0, r12 - bne _081B9F66 - mov r0, r10 - cmp r0, 0 - bne _081B9F7C - ldrh r7, [r4] - mov r10, r7 -_081B9F66: - adds r3, 0x2 - adds r1, 0x2 - adds r2, 0x1 - ldr r0, [sp, 0x38] - cmp r2, r0 - bge _081B9F7C - mov r7, r9 - adds r0, r7, r3 - ldrh r0, [r0] - cmp r0, r5 - bne _081B9F56 -_081B9F7C: - cmp r2, r6 - bne _081BA01C - movs r2, 0 - cmp r2, r6 - bge _081B9FD4 - ldr r0, =gBattleFrontierHeldItems - mov r12, r0 - ldr r7, =gFacilityTrainerMons - ldr r1, [sp, 0x24] - ldr r0, [sp, 0x2C] - adds r4, r1, r0 -_081B9F92: - ldrh r3, [r4] - cmp r3, 0 - beq _081B9FCC - ldr r1, [r7] - lsls r0, r5, 4 - adds r1, r0, r1 - ldrb r0, [r1, 0xA] - lsls r0, 1 - add r0, r12 - ldrh r0, [r0] - cmp r3, r0 - bne _081B9FCC - ldrh r0, [r1] - cmp r0, r10 - bne _081B9FD4 - movs r1, 0 - mov r10, r1 - b _081B9FD4 - .pool -_081B9FCC: - adds r4, 0x2 - adds r2, 0x1 - cmp r2, r6 - blt _081B9F92 -_081B9FD4: - cmp r2, r6 - bne _081BA01C - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - mov r2, r8 - lsls r3, r2, 1 - adds r0, r3, r2 - lsls r0, 2 - adds r1, r0 - movs r6, 0xE7 - lsls r6, 4 - adds r1, r6 - strh r5, [r1] - ldr r0, =gFacilityTrainerMons - ldr r0, [r0] - lsls r1, r5, 4 - adds r1, r0 - ldrh r0, [r1] - ldr r7, [sp, 0x34] - strh r0, [r7] - ldr r2, =gBattleFrontierHeldItems - ldrb r0, [r1, 0xA] - lsls r0, 1 - adds r0, r2 - ldrh r0, [r0] - ldr r1, [sp, 0x30] - strh r0, [r1] - add r3, r9 - strh r5, [r3] - adds r1, 0x2 - str r1, [sp, 0x30] - adds r2, r7, 0 - adds r2, 0x2 - str r2, [sp, 0x34] - movs r6, 0x1 - add r8, r6 -_081BA01C: - mov r7, r8 - cmp r7, 0x6 - beq _081BA024 - b _081B9F1E -_081BA024: - add sp, 0x3C - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81B9EC0 thumb_func_start sub_81BA040 sub_81BA040: @ 81BA040 diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index 01d8c311e..9327d6cb0 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -550,12 +550,14 @@ #define WININ_WIN0_BG1 (1 << 1) #define WININ_WIN0_BG2 (1 << 2) #define WININ_WIN0_BG3 (1 << 3) +#define WININ_WIN0_BG_ALL (WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_BG3) #define WININ_WIN0_OBJ (1 << 4) #define WININ_WIN0_CLR (1 << 5) #define WININ_WIN1_BG0 (1 << 8) #define WININ_WIN1_BG1 (1 << 9) #define WININ_WIN1_BG2 (1 << 10) #define WININ_WIN1_BG3 (1 << 11) +#define WININ_WIN1_BG_ALL (WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_BG3) #define WININ_WIN1_OBJ (1 << 12) #define WININ_WIN1_CLR (1 << 13) diff --git a/src/battle_dome.c b/src/battle_dome.c index 4505ce8b0..0183811cd 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -31,6 +31,7 @@ #include "constants/abilities.h" #include "constants/songs.h" #include "constants/battle_frontier.h" +#include "constants/rgb.h" #define DOME_ROUND1 0 #define DOME_ROUND2 1 @@ -2784,7 +2785,7 @@ static void CalcDomeMonStats(u16 species, s32 level, s32 ivs, u8 evBits, u8 natu count++; } - resultingEvs = 510 / count; + resultingEvs = MAX_TOTAL_EVS / count; for (i = 0; i < 6; bits <<= 1, i++) { evs[i] = 0; @@ -3933,7 +3934,7 @@ static void sub_8190CD4(u8 taskId) case 0: if (!gPaletteFade.active) { - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); gTasks[taskId].data[0] = 1; } break; @@ -3946,7 +3947,7 @@ static void sub_8190CD4(u8 taskId) switch (i) { case 9: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].data[0] = 8; break; case 1 ... 8: @@ -4986,7 +4987,7 @@ static void DisplayTrainerInfoOnCard(u8 flags, u8 trainerTournamentId) k++; evBits >>= 1; } - k = 510 / k; + k = MAX_TOTAL_EVS / k; evBits = gFacilityTrainerMons[gSaveBlock2Ptr->frontier.domeMonId[trainerTournamentId][i]].evSpread; for (j = 0; j < 6; j++) { @@ -5412,7 +5413,7 @@ static void sub_819395C(u8 taskId) case 0: if (!gPaletteFade.active) { - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); gTasks[taskId].data[0] = 1; StartSpriteAnim(&gSprites[spriteId], 1); } @@ -5426,17 +5427,17 @@ static void sub_819395C(u8 taskId) { case 0: default: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].data[0] = 7; break; case 1: break; case 2: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].data[0] = 3; break; case 3: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].data[0] = 5; break; } @@ -5930,7 +5931,7 @@ static void sub_8194950(u8 taskId) switch (gTasks[taskId].data[0]) { case 0: - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, RGB_BLACK); gTasks[taskId].data[0] = 1; break; case 1: @@ -5978,7 +5979,7 @@ static void sub_8194950(u8 taskId) case 3: if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { - BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, 0); + BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].data[0] = 4; } break; @@ -6029,44 +6030,44 @@ static void HblankCb_BattleDome(void) { if (vCount < 50) { - REG_WININ = 0x3B3B; - SET_WIN0H_WIN1H(0x989B, 0x5558); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(152, 155), WINHV_COORDS(85, 88)); return; } else if (vCount > 57) { if (vCount < 75) { - REG_WININ = 0x3B3B; - SET_WIN0H_WIN1H(0x9098, 0x5860); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(144, 152), WINHV_COORDS(88, 96)); return; } else if (vCount < 82) { - REG_WININ = 0x3B3B; - SET_WIN0H_WIN1H(0x989B, 0x5558); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG3 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG3 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(152, 155), WINHV_COORDS(85, 88)); return; } else if (vCount > 94) { if (vCount < 103) { - REG_WININ = 0x3737; - SET_WIN0H_WIN1H(0x989B, 0x5558); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(152, 155), WINHV_COORDS(85, 88)); return; } else if (vCount < 119) { - REG_WININ = 0x3737; - SET_WIN0H_WIN1H(0x9098, 0x5860); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(144, 152), WINHV_COORDS(88, 96)); return; } else if (vCount > 126) { if (vCount_ < 135) { - REG_WININ = 0x3737; - SET_WIN0H_WIN1H(0x989B, 0x5558); + REG_WININ = WININ_WIN0_BG0 | WININ_WIN0_BG1 | WININ_WIN0_BG2 | WININ_WIN0_OBJ | WININ_WIN0_CLR | WININ_WIN1_BG0 | WININ_WIN1_BG1 | WININ_WIN1_BG2 | WININ_WIN1_OBJ | WININ_WIN1_CLR; + SET_WIN0H_WIN1H(WINHV_COORDS(152, 155), WINHV_COORDS(85, 88)); return; } } @@ -6074,7 +6075,7 @@ static void HblankCb_BattleDome(void) } } - REG_WININ = 0x3F3F; + REG_WININ = WININ_WIN0_BG_ALL | WININ_WIN0_CLR | WININ_WIN0_OBJ | WININ_WIN1_BG_ALL | WININ_WIN1_CLR | WININ_WIN1_OBJ; SET_WIN0H_WIN1H(0, 0); } diff --git a/src/battle_tent.c b/src/battle_tent.c index f39bf8837..516f3fc4d 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -272,15 +272,15 @@ bool8 sub_81B9E94(void) } // This function was written very...oddly. -/* +#ifdef NONMATCHING void sub_81B9EC0(void) { s32 i, j; - u16 currMonId, currSpecies; + u16 currMonId = 0, currSpecies = 0; u16 species[PARTY_SIZE]; u16 monIds[PARTY_SIZE]; u16 heldItems[PARTY_SIZE]; - s32 var; + s32 zero = 0; gFacilityTrainers = gSlateportBattleTentTrainers; for (i = 0; i < PARTY_SIZE; i++) @@ -290,17 +290,15 @@ void sub_81B9EC0(void) heldItems[i] = 0; } gFacilityTrainerMons = gSlateportBattleTentMons; - currSpecies = 0; - i = 0; - while (i != PARTY_SIZE) + for (i = 0; i != PARTY_SIZE;) { // Cannot have two pokemon of the same species. currMonId = Random() % 70; - j = 0; - var = 0 + i; - while (j < var && monIds[j] != currMonId) + for (j = zero; j < i + zero; j++) { + if (monIds[j] == currMonId) + break; if (species[j] == gFacilityTrainerMons[currMonId].species) { if (currSpecies == 0) @@ -308,13 +306,12 @@ void sub_81B9EC0(void) else break; } - j++; } - if (j != var) + if (j != i + zero) continue; // Cannot have two same held items. - for (j = 0; j < var; j++) + for (j = zero; j < i + zero; j++) { if (heldItems[j] == 0) continue; @@ -326,14 +323,206 @@ void sub_81B9EC0(void) break; } } - if (j != var) + if (j != i + zero) continue; - gSaveBlock2Ptr->frontier.field_E70[var].monId = currMonId; - species[var] = gFacilityTrainerMons[currMonId].species; - heldItems[var] = gBattleFrontierHeldItems[gFacilityTrainerMons[currMonId].itemTableId]; - monIds[var] = currMonId; + gSaveBlock2Ptr->frontier.field_E70[i].monId = currMonId; + species[i] = gFacilityTrainerMons[currMonId].species; + heldItems[i] = gBattleFrontierHeldItems[gFacilityTrainerMons[currMonId].itemTableId]; + monIds[i] = currMonId; i++; } } -*/ +#else +NAKED +void sub_81B9EC0(void) +{ + asm_unified("\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x3C\n\ + ldr r1, =gFacilityTrainers\n\ + ldr r0, =gSlateportBattleTentTrainers\n\ + str r0, [r1]\n\ + add r0, sp, 0xC\n\ + mov r9, r0\n\ + mov r1, sp\n\ + adds r1, 0x18\n\ + str r1, [sp, 0x2C]\n\ + ldr r5, =gFacilityTrainerMons\n\ + ldr r4, =gSlateportBattleTentMons\n\ + movs r2, 0\n\ + adds r3, r1, 0\n\ + mov r1, r9\n\ + mov r0, sp\n\ + movs r6, 0x5\n\ + mov r8, r6\n\ +_081B9EEC:\n\ + strh r2, [r0]\n\ + strh r2, [r1]\n\ + strh r2, [r3]\n\ + adds r3, 0x2\n\ + adds r1, 0x2\n\ + adds r0, 0x2\n\ + movs r7, 0x1\n\ + negs r7, r7\n\ + add r8, r7\n\ + mov r6, r8\n\ + cmp r6, 0\n\ + bge _081B9EEC\n\ + str r4, [r5]\n\ + movs r7, 0\n\ + mov r10, r7\n\ + movs r0, 0\n\ + mov r8, r0\n\ + ldr r1, [sp, 0x2C]\n\ + str r1, [sp, 0x30]\n\ + mov r2, sp\n\ + str r2, [sp, 0x34]\n\ + lsls r6, r0, 1\n\ + str r6, [sp, 0x24]\n\ + add r6, r9\n\ + str r6, [sp, 0x28]\n\ +_081B9F1E:\n\ + bl Random\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + movs r1, 0x46\n\ + bl __umodsi3\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + movs r2, 0\n\ + mov r7, r8\n\ + adds r6, r2, r7\n\ + cmp r2, r6\n\ + bge _081B9F7C\n\ + ldr r1, [sp, 0x28]\n\ + ldrh r0, [r1]\n\ + cmp r0, r5\n\ + beq _081B9F7C\n\ + ldr r0, =gFacilityTrainerMons\n\ + ldr r1, [r0]\n\ + lsls r0, r5, 4\n\ + adds r4, r0, r1\n\ + ldrh r7, [r4]\n\ + mov r12, r7\n\ + lsls r3, r2, 1\n\ + ldr r1, [sp, 0x24]\n\ + add r1, sp\n\ + str r6, [sp, 0x38]\n\ +_081B9F56:\n\ + ldrh r0, [r1]\n\ + cmp r0, r12\n\ + bne _081B9F66\n\ + mov r0, r10\n\ + cmp r0, 0\n\ + bne _081B9F7C\n\ + ldrh r7, [r4]\n\ + mov r10, r7\n\ +_081B9F66:\n\ + adds r3, 0x2\n\ + adds r1, 0x2\n\ + adds r2, 0x1\n\ + ldr r0, [sp, 0x38]\n\ + cmp r2, r0\n\ + bge _081B9F7C\n\ + mov r7, r9\n\ + adds r0, r7, r3\n\ + ldrh r0, [r0]\n\ + cmp r0, r5\n\ + bne _081B9F56\n\ +_081B9F7C:\n\ + cmp r2, r6\n\ + bne _081BA01C\n\ + movs r2, 0\n\ + cmp r2, r6\n\ + bge _081B9FD4\n\ + ldr r0, =gBattleFrontierHeldItems\n\ + mov r12, r0\n\ + ldr r7, =gFacilityTrainerMons\n\ + ldr r1, [sp, 0x24]\n\ + ldr r0, [sp, 0x2C]\n\ + adds r4, r1, r0\n\ +_081B9F92:\n\ + ldrh r3, [r4]\n\ + cmp r3, 0\n\ + beq _081B9FCC\n\ + ldr r1, [r7]\n\ + lsls r0, r5, 4\n\ + adds r1, r0, r1\n\ + ldrb r0, [r1, 0xA]\n\ + lsls r0, 1\n\ + add r0, r12\n\ + ldrh r0, [r0]\n\ + cmp r3, r0\n\ + bne _081B9FCC\n\ + ldrh r0, [r1]\n\ + cmp r0, r10\n\ + bne _081B9FD4\n\ + movs r1, 0\n\ + mov r10, r1\n\ + b _081B9FD4\n\ + .pool\n\ +_081B9FCC:\n\ + adds r4, 0x2\n\ + adds r2, 0x1\n\ + cmp r2, r6\n\ + blt _081B9F92\n\ +_081B9FD4:\n\ + cmp r2, r6\n\ + bne _081BA01C\n\ + ldr r0, =gSaveBlock2Ptr\n\ + ldr r1, [r0]\n\ + mov r2, r8\n\ + lsls r3, r2, 1\n\ + adds r0, r3, r2\n\ + lsls r0, 2\n\ + adds r1, r0\n\ + movs r6, 0xE7\n\ + lsls r6, 4\n\ + adds r1, r6\n\ + strh r5, [r1]\n\ + ldr r0, =gFacilityTrainerMons\n\ + ldr r0, [r0]\n\ + lsls r1, r5, 4\n\ + adds r1, r0\n\ + ldrh r0, [r1]\n\ + ldr r7, [sp, 0x34]\n\ + strh r0, [r7]\n\ + ldr r2, =gBattleFrontierHeldItems\n\ + ldrb r0, [r1, 0xA]\n\ + lsls r0, 1\n\ + adds r0, r2\n\ + ldrh r0, [r0]\n\ + ldr r1, [sp, 0x30]\n\ + strh r0, [r1]\n\ + add r3, r9\n\ + strh r5, [r3]\n\ + adds r1, 0x2\n\ + str r1, [sp, 0x30]\n\ + adds r2, r7, 0\n\ + adds r2, 0x2\n\ + str r2, [sp, 0x34]\n\ + movs r6, 0x1\n\ + add r8, r6\n\ +_081BA01C:\n\ + mov r7, r8\n\ + cmp r7, 0x6\n\ + beq _081BA024\n\ + b _081B9F1E\n\ +_081BA024:\n\ + add sp, 0x3C\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + "); +} +#endif // NONMATCHING