diff options
Diffstat (limited to 'src')
125 files changed, 2063 insertions, 1916 deletions
diff --git a/src/AgbRfu_LinkManager.c b/src/AgbRfu_LinkManager.c index 42cc9aea3..f6ebcc726 100644 --- a/src/AgbRfu_LinkManager.c +++ b/src/AgbRfu_LinkManager.c @@ -352,7 +352,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID) { for (i = 0; i < RFU_CHILD_MAX; i++) { - if (bm_linkLossSlot & (1 << i)) + if ((bm_linkLossSlot >> i) & 1) { lman.linkRecoveryTimer.active |= (1 << i); lman.linkRecoveryTimer.count[i] = lman.linkRecoveryTimer.count_max; @@ -396,7 +396,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID) bm_disconnectSlot = 0; for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((lman.linkRecoveryTimer.active) & (1 << i) && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0) + if ((lman.linkRecoveryTimer.active >> i) & 1 && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0) { lman.linkRecoveryTimer.active &= ~(1 << i); bm_disconnectSlot |= (1 << i); diff --git a/src/agb_flash.c b/src/agb_flash.c index f63f84509..6b9381c70 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -41,7 +41,7 @@ u16 ReadFlashId(void) u8 (*readFlash1)(u8 *); SetReadFlash1(readFlash1Buffer); - readFlash1 = (u8 (*)(u8 *))((uintptr_t)readFlash1Buffer + 1); + readFlash1 = (u8 (*)(u8 *))((s32)readFlash1Buffer + 1); // Enter ID mode. FLASH_WRITE(0x5555, 0xAA); @@ -113,12 +113,12 @@ void SetReadFlash1(u16 *dest) u16 *src; u16 i; - PollFlashStatus = (u8 (*)(u8 *))((uintptr_t)dest + 1); + PollFlashStatus = (u8 (*)(u8 *))((s32)dest + 1); src = (u16 *)ReadFlash1; - src = (u16 *)((uintptr_t)src ^ 1); + src = (u16 *)((s32)src ^ 1); - i = ((uintptr_t)SetReadFlash1 - (uintptr_t)ReadFlash1) >> 1; + i = ((s32)SetReadFlash1 - (s32)ReadFlash1) >> 1; while (i != 0) { @@ -154,10 +154,10 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) } funcSrc = (vu16 *)ReadFlash_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = readFlash_Core_Buffer; - i = ((uintptr_t)ReadFlash - (uintptr_t)ReadFlash_Core) >> 1; + i = ((s32)ReadFlash - (s32)ReadFlash_Core) >> 1; while (i != 0) { @@ -165,7 +165,7 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) i--; } - readFlash_Core = (void (*)(vu8 *, u8 *, u32))((uintptr_t)readFlash_Core_Buffer + 1); + readFlash_Core = (void (*)(vu8 *, u8 *, u32))((s32)readFlash_Core_Buffer + 1); src = FLASH_BASE + (sectorNum << gFlash->sector.shift) + offset; @@ -202,10 +202,10 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) } funcSrc = (vu16 *)VerifyFlashSector_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); + i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; while (i != 0) { @@ -213,7 +213,7 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); size = gFlash->sector.size; @@ -239,10 +239,10 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) REG_WAITCNT = (REG_WAITCNT & ~WAITCNT_SRAM_MASK) | WAITCNT_SRAM_8; funcSrc = (vu16 *)VerifyFlashSector_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1; + i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; while (i != 0) { @@ -250,7 +250,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); diff --git a/src/apprentice.c b/src/apprentice.c index ad157f301..7ef094988 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1296,13 +1296,13 @@ const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, s32 language) // Functionally unused static void Task_SwitchToFollowupFuncAfterButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) SwitchTaskToFollowupFunc(taskId); } static void Task_ExecuteFuncAfterButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { gApprenticeFunc = (void*)(u32)(((u16)gTasks[taskId].data[0] | (gTasks[taskId].data[1] << 16))); gApprenticeFunc(); diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 1fd0642ad..4185f8017 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1298,7 +1298,7 @@ static void Cmd_count_usable_party_mons(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - u8 position; + u32 position; battlerOnField1 = gBattlerPartyIndexes[battlerId]; position = GetBattlerPosition(battlerId) ^ BIT_FLANK; battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; diff --git a/src/battle_anim_bug.c b/src/battle_anim_bug.c index 5e8a8b2a7..ea3df8098 100644 --- a/src/battle_anim_bug.c +++ b/src/battle_anim_bug.c @@ -372,11 +372,14 @@ static void AnimTranslateStinger(struct Sprite *sprite) { gBattleAnimArgs[2] = -gBattleAnimArgs[2]; } - else if (GetBattlerSide(gBattleAnimAttacker)) + else { - gBattleAnimArgs[2] = -gBattleAnimArgs[2]; - gBattleAnimArgs[1] = -gBattleAnimArgs[1]; - gBattleAnimArgs[3] = -gBattleAnimArgs[3]; + if (GetBattlerSide(gBattleAnimAttacker)) + { + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + gBattleAnimArgs[3] = -gBattleAnimArgs[3]; + } } if (!IsContest() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) @@ -384,8 +387,13 @@ static void AnimTranslateStinger(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimTarget) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimTarget) == B_POSITION_OPPONENT_LEFT) { - gBattleAnimArgs[2] *= -1; - gBattleAnimArgs[0] *= -1; + s16 temp1, temp2; + + temp1 = gBattleAnimArgs[2]; + gBattleAnimArgs[2] = -temp1; + + temp2 = gBattleAnimArgs[0]; + gBattleAnimArgs[0] = -temp2; } } @@ -440,24 +448,28 @@ static void AnimMissileArc_Step(struct Sprite *sprite) else { s16 tempData[8]; - s16 xpos, ypos; + u16 *data = sprite->data; + u16 x1 = sprite->pos1.x; + s16 x2 = sprite->pos2.x; + u16 y1 = sprite->pos1.y; + s16 y2 = sprite->pos2.y; int i; for (i = 0; i < 8; i++) - tempData[i] = sprite->data[i]; + tempData[i] = data[i]; - xpos = sprite->pos1.x + sprite->pos2.x; - ypos = sprite->pos1.y + sprite->pos2.y; + x2 += x1; + y2 += y1; if (!TranslateAnimHorizontalArc(sprite)) { - u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - xpos, //Isn't this zero lol - sprite->pos1.y + sprite->pos2.y - ypos); + u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - x2, + sprite->pos1.y + sprite->pos2.y - y2); rotation += 0xC000; TrySetSpriteRotScale(sprite, FALSE, 0x100, 0x100, rotation); for (i = 0; i < 8; i++) - sprite->data[i] = tempData[i]; + data[i] = tempData[i]; } } } diff --git a/src/battle_anim_dark.c b/src/battle_anim_dark.c index 7253b5247..faa5884a5 100644 --- a/src/battle_anim_dark.c +++ b/src/battle_anim_dark.c @@ -635,6 +635,8 @@ void AnimTask_MoveTargetMementoShadow(u8 taskId) static void AnimTask_MoveTargetMementoShadow_Step(u8 taskId) { + u8 pos; + u16 i; struct Task *task = &gTasks[taskId]; switch (task->data[0]) diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index c8d43e12e..04bab2f85 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3967,25 +3967,24 @@ static void AnimProtect(struct Sprite* sprite) static void AnimProtect_Step(struct Sprite *sprite) { - int i, savedPal; + int i, id, savedPal; sprite->data[5] += 96; sprite->pos2.x = -(sprite->data[5] >> 8); if (++sprite->data[1] > 1) { - int id; sprite->data[1] = 0; savedPal = gPlttBufferFaded[sprite->data[2] + 1]; i = 0; - do + while (i < 6) { id = sprite->data[2] + ++i; gPlttBufferFaded[id] = gPlttBufferFaded[id + 1]; - } while (i < 6); + } gPlttBufferFaded[sprite->data[2] + 7] = savedPal; } - if (sprite->data[7] > 6 && sprite->data[0] > 0 && ++sprite->data[6] > 1) + if (sprite->data[7] > 6 && sprite->data[0] >0 && ++sprite->data[6] > 1) { sprite->data[6] = 0; sprite->data[7] -= 1; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index abb3223e0..65c560cdf 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -5002,11 +5002,11 @@ void AnimTask_GetReturnPowerLevel(u8 taskId) void AnimTask_SnatchOpposingMonMove(u8 taskId) { u8 spriteId, spriteId2; - u32 personality; - u32 otId; + int personality; + int otId; u16 species; u8 subpriority; - bool8 isBackPic; + u8 isBackPic; s16 x; switch (gTasks[taskId].data[0]) @@ -5034,34 +5034,37 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) otId = gContestResources->moveAnim->otId; species = gContestResources->moveAnim->species; subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker); - isBackPic = FALSE; + isBackPic = 0; x = -32; } - else if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) - { - personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); - otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); - if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) - species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); - else - species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; - - subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; - isBackPic = FALSE; - x = 272; - } else { - personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); - otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); - if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) - species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + { + personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; + isBackPic = 0; + x = 272; + } else - species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + { + personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; - subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; - isBackPic = TRUE; - x = -32; + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; + isBackPic = 1; + x = -32; + } } spriteId2 = sub_80A8394(species, isBackPic, 0, x, GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y), subpriority, personality, otId, gBattleAnimAttacker, 0); @@ -5088,7 +5091,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } else @@ -5096,7 +5099,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x > GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } } @@ -5134,7 +5137,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) gSprites[spriteId].pos2.x = 0; } - gTasks[taskId].data[1] &= 0xFF; + gTasks[taskId].data[1] = (u8)gTasks[taskId].data[1]; if (gSprites[spriteId].pos2.x == 0) DestroyAnimVisualTask(taskId); break; diff --git a/src/battle_anim_flying.c b/src/battle_anim_flying.c index fe94dc9a2..d7f079886 100644 --- a/src/battle_anim_flying.c +++ b/src/battle_anim_flying.c @@ -380,18 +380,21 @@ static void AnimTask_AnimateGustTornadoPalette_Step(u8 taskId) { u8 data2; u16 temp; + int i, base; if (gTasks[taskId].data[10]++ == gTasks[taskId].data[1]) { - int i, base; gTasks[taskId].data[10] = 0; data2 = gTasks[taskId].data[2]; temp = gPlttBufferFaded[16 * data2 + 0x108]; i = 7; base = data2 * 16; - for (; i > 0; --i) + do + { gPlttBufferFaded[base + 0x101 + i] = gPlttBufferFaded[base + 0x100 + i]; + i--; + } while (i > 0); gPlttBufferFaded[base + 0x101] = temp; } @@ -533,16 +536,17 @@ static void AnimFlyBallAttack_Step(struct Sprite *sprite) void DestroyAnimSpriteAfterTimer(struct Sprite *sprite) { - if (sprite->data[0]-- > 0) - return; - if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK) + if (sprite->data[0]-- <= 0) { - FreeOamMatrix(sprite->oam.matrixNum); - sprite->oam.affineMode = ST_OAM_AFFINE_OFF; - } + if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK) + { + FreeOamMatrix(sprite->oam.matrixNum); + sprite->oam.affineMode = ST_OAM_AFFINE_OFF; + } - DestroySprite(sprite); - gAnimVisualTaskCount--; + DestroySprite(sprite); + gAnimVisualTaskCount--; + } } struct FeatherDanceData @@ -563,41 +567,35 @@ struct FeatherDanceData u16 unkE_1:15; }; -#define ANIM_SWITCH(sprite) \ - { \ - (sprite)->hFlip ^= 1; \ - (sprite)->animNum = (sprite)->hFlip; \ - (sprite)->animBeginning = TRUE; \ - (sprite)->animEnded = FALSE; \ - } - static void AnimFallingFeather(struct Sprite *sprite) { - u8 battler, sinIndex; - u32 matrixNum; - s16 sinVal; + u8 battler, matrixNum, sinIndex; + s16 spriteCoord; struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; - battler = (gBattleAnimArgs[7] & 0x100) ? gBattleAnimAttacker : gBattleAnimTarget; + if (gBattleAnimArgs[7] & 0x100) + battler = gBattleAnimAttacker; + else + battler = gBattleAnimTarget; if (GetBattlerSide(battler) == B_SIDE_PLAYER) gBattleAnimArgs[0] = -gBattleAnimArgs[0]; sprite->pos1.x = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_HEIGHT) + gBattleAnimArgs[0]; - sinVal = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_WIDTH); - sprite->pos1.y = sinVal + gBattleAnimArgs[1]; + spriteCoord = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_WIDTH); + sprite->pos1.y = spriteCoord + gBattleAnimArgs[1]; - data->unk8 = (u16)(sprite->pos1.y) << 8; - data->unkE_1 = (u16)(sinVal + gBattleAnimArgs[6]); + data->unk8 = sprite->pos1.y << 8; + data->unkE_1 = spriteCoord + gBattleAnimArgs[6]; data->unk0_0c = 1; - data->unk2 = (u16)(gBattleAnimArgs[2] & 0xFF); - data->unkA = (u16)gBattleAnimArgs[2] >> 8; + data->unk2 = gBattleAnimArgs[2] & 0xFF; + data->unkA = (gBattleAnimArgs[2] >> 8) & 0xFF; data->unk4 = gBattleAnimArgs[3]; - data->unk6 = (u16)gBattleAnimArgs[4]; - *(u16 *)(data->unkC) = (u16)gBattleAnimArgs[5]; + data->unk6 = gBattleAnimArgs[4]; + *(u16*)(data->unkC) = gBattleAnimArgs[5]; - if (data->unk2 >= 64 && data->unk2 < 192) + if (data->unk2 >= 64 && data->unk2 <= 191) { if (!IsContest()) sprite->oam.priority = GetBattlerSpriteBGPriority(battler) + 1; @@ -608,7 +606,11 @@ static void AnimFallingFeather(struct Sprite *sprite) if (!(data->unk4 & 0x8000)) { - ANIM_SWITCH(sprite); + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + + sprite->animBeginning = 1; + sprite->animEnded = 0; } } else @@ -618,28 +620,31 @@ static void AnimFallingFeather(struct Sprite *sprite) if (data->unk4 & 0x8000) { - ANIM_SWITCH(sprite); + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + + sprite->animBeginning = 1; + sprite->animEnded = 0; } } - data->unk0_1 = data->unk2 / 64; - sprite->pos2.x = (gSineTable[data->unk2] * (s32)data->unkC[0]) >> 8; + data->unk0_1 = data->unk2 >> 6; + sprite->pos2.x = (gSineTable[data->unk2] * data->unkC[0]) >> 8; matrixNum = sprite->oam.matrixNum; sinIndex = (-sprite->pos2.x >> 1) + data->unkA; - sinVal = gSineTable[sinIndex]; + spriteCoord = gSineTable[sinIndex]; gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - gOamMatrices[matrixNum].c = -sinVal; + gOamMatrices[matrixNum].b = spriteCoord; + gOamMatrices[matrixNum].c = -spriteCoord; sprite->callback = sub_810E520; } static void sub_810E520(struct Sprite *sprite) { - u8 sinIndex; - u32 matrixNum; + u8 matrixNum, sinIndex; s16 sinVal = 0; struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; if (data->unk0_0a) @@ -649,226 +654,240 @@ static void sub_810E520(struct Sprite *sprite) data->unk0_0a = 0; data->unk1 = 0; } - return; } - - switch (data->unk2 / 64) + else { - case 0: - if ((u8)data->unk0_1 == 1) // this must be cast to u8 - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 3) - { - data->unk0_0b ^= 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) + switch (data->unk2 / 64) { - ANIM_SWITCH(sprite); - if (data->unk0_0c) + case 0: + if ((u8)data->unk0_1 == 1) //casts to u8 here are necessary for matching { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; } - data->unk0_0d = 0; - } - data->unk0_1 = 0; - break; - case 1: - if ((u8)data->unk0_1 == 0) - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 2) - { - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) + else if ((u8)data->unk0_1 == 3) { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } + data->unk0_0b ^= 1; + data->unk0_0a = 1; + data->unk1 = 0; } - data->unk0_0d = 0; - } - data->unk0_1 = 1; - break; - case 2: - if ((u8)data->unk0_1 == 3) - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 1) - { - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) + else if (data->unk0_0d) { - if (!IsContest()) + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) { - if (!data->unkE_0) + if (!IsContest()) { - sprite->oam.priority--; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } } else { - sprite->oam.priority++; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } } } - else + data->unk0_0d = 0; + data->unk2; + } + data->unk0_1 = 0; + break; + case 1: + if ((u8)data->unk0_1 == 0) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if ((u8)data->unk0_1 == 2) + { + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) { - if (!data->unkE_0) + if (!IsContest()) { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } } else { - sprite->subpriority += 12; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } } } + data->unk0_0d = 0; } - data->unk0_0d = 0; - } - data->unk0_1 = 2; - break; - case 3: - if ((u8)data->unk0_1 == 2) - { - data->unk0_0d = 1; - } - else if ((u8)data->unk0_1 == 0) - { - data->unk0_0b ^= 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) + data->unk0_1 = 1; + break; + case 2: + if ((u8)data->unk0_1 == 3) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if ((u8)data->unk0_1 == 1) { - if (!IsContest()) + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) { - if (!data->unkE_0) + if (!IsContest()) { - sprite->oam.priority--; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } } else { - sprite->oam.priority++; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } } } - else + data->unk0_0d = 0; + } + data->unk0_1 = 2; + break; + case 3: + if ((u8)data->unk0_1 == 2) + { + data->unk0_0d = 1; + } + else if ((u8)data->unk0_1 == 0) + { + data->unk0_0b ^= 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) { - if (!data->unkE_0) + if (!IsContest()) { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } } else { - sprite->subpriority += 12; - data->unkE_0 ^= 1; + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } } } + data->unk0_0d = 0; } - data->unk0_0d = 0; + data->unk0_1 = 3; + break; } - data->unk0_1 = 3; - break; - } - sprite->pos2.x = ((s32)(data->unkC[data->unk0_0b]) * gSineTable[data->unk2]) >> 8; - matrixNum = sprite->oam.matrixNum; + sprite->pos2.x = ((s32)data->unkC[data->unk0_0b] * gSineTable[data->unk2]) >> 8; + matrixNum = sprite->oam.matrixNum; - sinIndex = ((-sprite->pos2.x >> 1) + data->unkA); - sinVal = gSineTable[sinIndex]; + sinIndex = (-sprite->pos2.x >> 1) + data->unkA; + sinVal = gSineTable[sinIndex]; - gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - gOamMatrices[matrixNum].c = -sinVal; + gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; - data->unk8 += data->unk6; - sprite->pos1.y = (s16)(data->unk8 >> 8); - if (data->unk4 & 0x8000) - data->unk2 = (data->unk2 - (data->unk4 & 0x7FFF)) & 0xFF; - else - data->unk2 = (data->unk2 + (data->unk4 & 0x7FFF)) & 0xFF; + data->unk8 += data->unk6; + sprite->pos1.y = data->unk8 >> 8; + if (data->unk4 & 0x8000) + data->unk2 = (data->unk2 - (data->unk4 & 0x7FFF)) & 0xFF; + else + data->unk2 = (data->unk2 + (data->unk4 & 0x7FFF)) & 0xFF; - if (sprite->pos1.y + sprite->pos2.y >= data->unkE_1) - { - sprite->data[0] = 0; - sprite->callback = DestroyAnimSpriteAfterTimer; + if (sprite->pos1.y + sprite->pos2.y >= data->unkE_1) + { + sprite->data[0] = 0; + sprite->callback = DestroyAnimSpriteAfterTimer; + } } } @@ -912,20 +931,20 @@ static void sub_810EB40(struct Sprite *sprite) { sprite->pos2.x += sprite->data[1] >> 8; - if (sprite->data[0]++ == 5) + if (++sprite->data[0] == 6) { sprite->data[0] = 0; sprite->pos2.x = 0; StartSpriteAnim(sprite, 0); } - if (sprite->data[7]-- == 0) + if (--sprite->data[7] == -1) DestroyAnimSprite(sprite); } void AnimTask_DrillPeckHitSplats(u8 task) { - if ((gTasks[task].data[0] % 32) == 0) + if (!(gTasks[task].data[0] % 32)) { gAnimVisualTaskCount++; @@ -1028,8 +1047,8 @@ static void AnimDiveBall_Step2(struct Sprite *sprite) static void AnimDiveWaterSplash(struct Sprite *sprite) { - u8 matrixNum; - s32 t1, t2; + u32 matrixNum; + int t1, t2; switch (sprite->data[0]) { @@ -1051,7 +1070,7 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) sprite->data[0]++; break; case 1: - if (sprite->data[2] < 12) + if (sprite->data[2] <= 11) sprite->data[1] -= 40; else sprite->data[1] += 40; @@ -1059,7 +1078,7 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) sprite->data[2]++; TrySetSpriteRotScale(sprite, 0, 256, sprite->data[1], 0); - + matrixNum = sprite->oam.matrixNum; t1 = 15616; @@ -1083,8 +1102,8 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) // Launches a water droplet away from the specified battler. Used by Astonish and Dive static void AnimSprayWaterDroplet(struct Sprite *sprite) { - const u16 v1 = Random2() & 0x1ff; - const u16 v2 = Random2() & 0x07f; + int v1 = 0x1ff & Random2(); + int v2 = 0x7f & Random2(); if (v1 % 2) sprite->data[0] = 736 + v1; @@ -1128,13 +1147,13 @@ static void AnimSprayWaterDroplet_Step(struct Sprite *sprite) sprite->pos2.y -= sprite->data[1] >> 8; } - sprite->data[0] -= 0; // Needed to Match + sprite->data[0] = sprite->data[0]; sprite->data[1] -= 32; if (sprite->data[0] < 0) sprite->data[0] = 0; - if (sprite->data[3]++ == 30) + if (++sprite->data[3] == 31) DestroyAnimSprite(sprite); } @@ -1180,7 +1199,7 @@ static void AnimSkyAttackBird(struct Sprite *sprite) sprite->data[7] = ((posy - sprite->pos1.y) << 4) / 12; rotation = ArcTan2Neg(posx - sprite->pos1.x, posy - sprite->pos1.y); - rotation -= 16384; + rotation += 49152; TrySetSpriteRotScale(sprite, 1, 0x100, 0x100, rotation); @@ -1204,12 +1223,12 @@ void unref_sub_810F184(u8 taskId) { if (gBattleAnimArgs[0] == 0) { - const u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); gSprites[spriteId].invisible = TRUE; } else { - const u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); gSprites[spriteId].invisible = FALSE; } DestroyAnimVisualTask(taskId); diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index 3f451998c..0a07b9070 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -1101,7 +1101,7 @@ static void AnimTask_TransparentCloneGrowAndShrink_Step(u8 taskId) break; case 1: task->data[1] -= 4; - task->data[2] = 256 - (gSineTable[task->data[1]] >> 1); + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1);; SetSpriteRotScale(task->data[15], task->data[2], task->data[2], 0); SetBattlerSpriteYOffsetFromOtherYScale(task->data[15], task->data[13]); if (task->data[1] == 0) diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index 9790cf9ea..af48ac3b9 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -569,7 +569,7 @@ static void sub_81172EC(u8 taskId) if (gTasks[taskId].data[12] == 0) { sub_80A477C(0); - gTasks[taskId].data[15]++; + gTasks[taskId].data[15]++;; } } break; diff --git a/src/battle_anim_water.c b/src/battle_anim_water.c index 12f37dbba..2bb90e585 100644 --- a/src/battle_anim_water.c +++ b/src/battle_anim_water.c @@ -52,7 +52,7 @@ static void CreateWaterSpoutLaunchDroplets(struct Task*, u8); static void CreateWaterSpoutRainDroplet(struct Task*, u8); static void AnimTask_WaterSport_Step(u8); static void CreateWaterSportDroplet(struct Task*); -static void CreateWaterPulseRingBubbles(struct Sprite*, s32, s32); +static void CreateWaterPulseRingBubbles(struct Sprite*, int, int); // Both unused const u8 gUnknown_8593C80[] = INCBIN_U8("graphics/unknown/unknown_593C80.4bpp"); @@ -631,13 +631,13 @@ static void AnimTask_RotateAuroraRingColors_Step(u8 taskId) if (++gTasks[taskId].data[10] == 3) { - u16 tempPlt; + u16 rgbBuffer; gTasks[taskId].data[10] = 0; palIndex = gTasks[taskId].data[2] + 1; - tempPlt = gPlttBufferFaded[palIndex]; + rgbBuffer = gPlttBufferFaded[palIndex]; for (i = 1; i < 8; i++) gPlttBufferFaded[palIndex + i - 1] = gPlttBufferFaded[palIndex + i]; - gPlttBufferFaded[palIndex + 7] = tempPlt; + gPlttBufferFaded[palIndex + 7] = rgbBuffer; } if (++gTasks[taskId].data[11] == gTasks[taskId].data[0]) DestroyAnimVisualTask(taskId); @@ -748,7 +748,6 @@ static void AnimHydroCannonBeam(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimAttacker) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimAttacker) == B_POSITION_OPPONENT_LEFT) gBattleAnimArgs[0] *= -1; } - if ((gBattleAnimArgs[5] & 0xFF00) == 0) animType = TRUE; else @@ -794,7 +793,7 @@ static void AnimSmallBubblePair_Step(struct Sprite *sprite) sprite->pos2.x = Sin(sprite->data[0], 4); sprite->data[1] += 48; sprite->pos2.y = -(sprite->data[1] >> 8); - if (sprite->data[7]-- == 0) + if (--sprite->data[7] == -1) DestroyAnimSprite(sprite); } @@ -802,17 +801,17 @@ void AnimTask_CreateSurfWave(u8 taskId) { struct BattleAnimBgData animBg; u8 taskId2; - u16 *x, *y; //These pointers are needed to match + u16 *x; + u16 *y; x = &gBattle_BG1_X; y = &gBattle_BG1_Y; - SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL | BLDCNT_TGT1_BG1); - SetGpuReg(REG_OFFSET_BLDALPHA, (16 << 8)); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); SetAnimBgAttribute(1, BG_ANIM_SCREEN_SIZE, 1); sub_80A6B30(&animBg); - if (!IsContest()) { SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 1); @@ -877,13 +876,13 @@ void AnimTask_CreateSurfWave(u8 taskId) static void AnimTask_CreateSurfWave_Step1(u8 taskId) { - u16 rgbBuffer; - u8 i; - u16 *BGptrX, *BGptrY; struct BattleAnimBgData animBg; - - BGptrX = &gBattle_BG1_X; - BGptrY = &gBattle_BG1_Y; + u8 i; + u16 rgbBuffer; + u16 *BGptrX = &gBattle_BG1_X; + u16 *BGptrY = &gBattle_BG1_Y; + u32 palOffset; + u16 palNum; *BGptrX += gTasks[taskId].data[0]; *BGptrY += gTasks[taskId].data[1]; @@ -891,18 +890,18 @@ static void AnimTask_CreateSurfWave_Step1(u8 taskId) gTasks[taskId].data[2] += gTasks[taskId].data[1]; if (++gTasks[taskId].data[5] == 4) { - rgbBuffer = gPlttBufferFaded[16 * animBg.paletteId + 7]; - for (i = 6; i != 0; i--) // i > 0 generates the exact same code in this context + rgbBuffer = gPlttBufferFaded[animBg.paletteId * 16 + 7]; + for (i = 6; i != 0; i--) { - gPlttBufferFaded[16 * animBg.paletteId + 1 + i] = gPlttBufferFaded[16 * animBg.paletteId + 1 + i - 1]; // 1 + i - 1 is needed to match for some bizarre reason + gPlttBufferFaded[animBg.paletteId * 16 + 1 + i] = gPlttBufferFaded[animBg.paletteId * 16 + 1 + i - 1]; // 1 + i - 1 is needed to match for some bizarre reason } - gPlttBufferFaded[16 * animBg.paletteId + 1] = rgbBuffer; + gPlttBufferFaded[animBg.paletteId * 16 + 1] = rgbBuffer; gTasks[taskId].data[5] = 0; } if (++gTasks[taskId].data[6] > 1) { gTasks[taskId].data[6] = 0; - if (++gTasks[taskId].data[3] < 14) + if (++gTasks[taskId].data[3] <= 13) { gTasks[gTasks[taskId].data[15]].data[1] = (s16)((gTasks[taskId].data[3]) | ((16 - gTasks[taskId].data[3]) << 8)); gTasks[taskId].data[4]++; @@ -920,7 +919,6 @@ static void AnimTask_CreateSurfWave_Step1(u8 taskId) } } - static void AnimTask_CreateSurfWave_Step2(u8 taskId) { u16 *BGptrX = &gBattle_BG1_X; @@ -1543,50 +1541,45 @@ static void AnimWaterPulseRing_Step(struct Sprite *sprite) sprite->data[0]++; } -static void CreateWaterPulseRingBubbles(struct Sprite *sprite, s32 xDiff, s32 yDiff) +static void CreateWaterPulseRingBubbles(struct Sprite *sprite, int xDiff, int yDiff) { - s16 combinedX, combinedY; - s16 i, something; + s16 combinedX; + s16 combinedY; + s16 i; + s16 something; s16 unusedVar = 1; //unusedVar is needed to match - s16 somethingRandomX, somethingRandomY; + s16 randomSomethingY; + s16 randomSomethingX; u8 spriteId; - + something = sprite->data[0] / 2; combinedX = sprite->pos1.x + sprite->pos2.x; combinedY = sprite->pos1.y + sprite->pos2.y; if (yDiff < 0) - unusedVar *= -1; //Needed to Match - somethingRandomY = yDiff + (Random2() % 10) - 5; - somethingRandomX = -xDiff + (Random2() % 10) - 5; + unusedVar *= -1; //Needed to match + randomSomethingY = yDiff + (Random2() % 10) - 5; + randomSomethingX = -xDiff + (Random2() % 10) - 5; - for (i = 0; i < 1; i++) + for (i = 0; i <= 0; i++) { spriteId = CreateSprite(&gWaterPulseRingBubbleSpriteTemplate, combinedX, combinedY + something, 130); gSprites[spriteId].data[0] = 20; - gSprites[spriteId].data[1] = somethingRandomY; + gSprites[spriteId].data[1] = randomSomethingY; gSprites[spriteId].subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker) - 1; - if (somethingRandomX < 0) - { - gSprites[spriteId].data[2] = -somethingRandomX; - } + if (randomSomethingX < 0) + gSprites[spriteId].data[2] = -randomSomethingX; else - { - gSprites[spriteId].data[2] = somethingRandomX; - } + gSprites[spriteId].data[2] = randomSomethingX; } - for (i = 0; i < 1; i++) + for (i = 0; i <= 0; i++) { spriteId = CreateSprite(&gWaterPulseRingBubbleSpriteTemplate, combinedX, combinedY - something, 130); gSprites[spriteId].data[0] = 20; - gSprites[spriteId].data[1] = somethingRandomY; + gSprites[spriteId].data[1] = randomSomethingY; gSprites[spriteId].subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker) - 1; - if (somethingRandomX > 0) - { - gSprites[spriteId].data[2] = -somethingRandomX; - } + if (randomSomethingX > 0) + gSprites[spriteId].data[2] = -randomSomethingX; else - { - gSprites[spriteId].data[2] = somethingRandomX; - } + gSprites[spriteId].data[2] = randomSomethingX; } } diff --git a/src/battle_bg.c b/src/battle_bg.c index 6a0e4c10c..7c9b05b25 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -1126,7 +1126,7 @@ void DrawBattleEntryBackground(void) if (gBattleTypeFlags & BATTLE_TYPE_LINK) { LZDecompressVram(gUnknown_08D778F0, (void*)(BG_CHAR_ADDR(1))); - LZDecompressVram(gVsLettersGfx, (void*)(OBJ_VRAM0)); + LZDecompressVram(gVsLettersGfx, (void*)(VRAM + 0x10000)); LoadCompressedPalette(gUnknown_08D77AE4, 0x60, 0x20); SetBgAttribute(1, BG_ATTR_SCREENSIZE, 1); SetGpuReg(REG_OFFSET_BG1CNT, 0x5C04); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 7c34efd44..d8005e808 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -240,12 +240,12 @@ static void HandleInputChooseAction(void) DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); - if (JOY_REPEAT(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -266,7 +266,7 @@ static void HandleInputChooseAction(void) } PlayerBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gActionSelectionCursor[gActiveBattler] & 1) // if is B_ACTION_USE_ITEM or B_ACTION_RUN { @@ -276,7 +276,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gActionSelectionCursor[gActiveBattler] & 1)) // if is B_ACTION_USE_MOVE or B_ACTION_SWITCH { @@ -286,7 +286,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gActionSelectionCursor[gActiveBattler] & 2) // if is B_ACTION_SWITCH or B_ACTION_RUN { @@ -296,7 +296,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gActionSelectionCursor[gActiveBattler] & 2)) // if is B_ACTION_USE_MOVE or B_ACTION_USE_ITEM { @@ -306,7 +306,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT @@ -326,7 +326,7 @@ static void HandleInputChooseAction(void) PlayerBufferExecCompleted(); } } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { SwapHpBarsWithHpText(); } @@ -359,12 +359,12 @@ static void HandleInputChooseTarget(void) } while (i < gBattlersCount); } - if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -372,7 +372,7 @@ static void HandleInputChooseTarget(void) EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); PlayerBufferExecCompleted(); } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -381,7 +381,7 @@ static void HandleInputChooseTarget(void) DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); } - else if (JOY_NEW(DPAD_LEFT | DPAD_UP)) + else if (gMain.newKeys & (DPAD_LEFT | DPAD_UP)) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -423,7 +423,7 @@ static void HandleInputChooseTarget(void) } while (i == 0); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } - else if (JOY_NEW(DPAD_RIGHT | DPAD_DOWN)) + else if (gMain.newKeys & (DPAD_RIGHT | DPAD_DOWN)) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -472,12 +472,12 @@ static void HandleInputChooseMove(void) bool32 canSelectTarget = FALSE; struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleBufferA[gActiveBattler][4]); - if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 moveTarget; @@ -539,13 +539,13 @@ static void HandleInputChooseMove(void) gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); BtlController_EmitTwoReturnValues(1, 10, 0xFFFF); PlayerBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gMoveSelectionCursor[gActiveBattler] & 1) { @@ -557,7 +557,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gMoveSelectionCursor[gActiveBattler] & 1) && (gMoveSelectionCursor[gActiveBattler] ^ 1) < gNumberOfMovesToChoose) @@ -570,7 +570,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gMoveSelectionCursor[gActiveBattler] & 2) { @@ -582,7 +582,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gMoveSelectionCursor[gActiveBattler] & 2) && (gMoveSelectionCursor[gActiveBattler] ^ 2) < gNumberOfMovesToChoose) @@ -595,7 +595,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { if (gNumberOfMovesToChoose > 1 && !(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -617,26 +617,26 @@ u32 sub_8057FBC(void) // unused { u32 var = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); var = 1; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattle_BG0_X = 0; gBattle_BG0_Y = 0x140; var = 0xFF; } - if (JOY_NEW(DPAD_LEFT) && gMoveSelectionCursor[gActiveBattler] & 1) + if (gMain.newKeys & DPAD_LEFT && gMoveSelectionCursor[gActiveBattler] & 1) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); gMoveSelectionCursor[gActiveBattler] ^= 1; PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_RIGHT) && !(gMoveSelectionCursor[gActiveBattler] & 1) + if (gMain.newKeys & DPAD_RIGHT && !(gMoveSelectionCursor[gActiveBattler] & 1) && (gMoveSelectionCursor[gActiveBattler] ^ 1) < gNumberOfMovesToChoose) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); @@ -644,14 +644,14 @@ u32 sub_8057FBC(void) // unused PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_UP) && gMoveSelectionCursor[gActiveBattler] & 2) + if (gMain.newKeys & DPAD_UP && gMoveSelectionCursor[gActiveBattler] & 2) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); gMoveSelectionCursor[gActiveBattler] ^= 2; PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_DOWN) && !(gMoveSelectionCursor[gActiveBattler] & 2) + if (gMain.newKeys & DPAD_DOWN && !(gMoveSelectionCursor[gActiveBattler] & 2) && (gMoveSelectionCursor[gActiveBattler] ^ 2) < gNumberOfMovesToChoose) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); @@ -669,7 +669,7 @@ static void HandleMoveSwitching(void) struct ChooseMoveStruct moveStruct; u8 totalPPBonuses; - if (JOY_NEW(A_BUTTON | SELECT_BUTTON)) + if (gMain.newKeys & (A_BUTTON | SELECT_BUTTON)) { PlaySE(SE_SELECT); @@ -763,7 +763,7 @@ static void HandleMoveSwitching(void) MoveSelectionDisplayPpNumber(); MoveSelectionDisplayMoveType(); } - else if (JOY_NEW(B_BUTTON | SELECT_BUTTON)) + else if (gMain.newKeys & (B_BUTTON | SELECT_BUTTON)) { PlaySE(SE_SELECT); MoveSelectionDestroyCursorAt(gMultiUsePlayerCursor); @@ -773,7 +773,7 @@ static void HandleMoveSwitching(void) MoveSelectionDisplayPpNumber(); MoveSelectionDisplayMoveType(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gMultiUsePlayerCursor & 1) { @@ -791,7 +791,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gMultiUsePlayerCursor & 1) && (gMultiUsePlayerCursor ^ 1) < gNumberOfMovesToChoose) { @@ -809,7 +809,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gMultiUsePlayerCursor & 2) { @@ -827,7 +827,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gMultiUsePlayerCursor & 2) && (gMultiUsePlayerCursor ^ 2) < gNumberOfMovesToChoose) { @@ -1402,21 +1402,21 @@ static void DoHitAnimBlinkSpriteEffect(void) static void PlayerHandleUnknownYesNoInput(void) { - if (JOY_NEW(DPAD_UP) && gMultiUsePlayerCursor != 0) + if (gMain.newKeys & DPAD_UP && gMultiUsePlayerCursor != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor); gMultiUsePlayerCursor = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gMultiUsePlayerCursor == 0) + if (gMain.newKeys & DPAD_DOWN && gMultiUsePlayerCursor == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor); gMultiUsePlayerCursor = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); @@ -1428,7 +1428,7 @@ static void PlayerHandleUnknownYesNoInput(void) PlayerBufferExecCompleted(); } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 9cb427e12..70e41cf8d 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -170,7 +170,7 @@ static void SafariBufferRunCommand(void) static void HandleInputChooseAction(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -191,7 +191,7 @@ static void HandleInputChooseAction(void) } SafariBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gActionSelectionCursor[gActiveBattler] & 1) { @@ -201,7 +201,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gActionSelectionCursor[gActiveBattler] & 1)) { @@ -211,7 +211,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gActionSelectionCursor[gActiveBattler] & 2) { @@ -221,7 +221,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gActionSelectionCursor[gActiveBattler] & 2)) { diff --git a/src/battle_dome.c b/src/battle_dome.c index e504115a6..fff8dc0c4 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2763,10 +2763,10 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) // BUG: TYPE_x2 is not necessary and makes the condition always false if the ability is wonder guard. if (TYPE_EFFECT_DEF_TYPE(i) == defType1) if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD) - typePower = typePower * TYPE_EFFECT_MULTIPLIER(i) / 10; + typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10; if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2) if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD) - typePower = typePower * TYPE_EFFECT_MULTIPLIER(i) / 10; + typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10; } i += 3; } @@ -2777,10 +2777,10 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case 0: switch (typePower) { - default: - case TYPE_x0: - case TYPE_x0_25: case TYPE_x0_50: + case TYPE_x0_25: + case TYPE_x0: + default: typePower = 0; break; case TYPE_x1: @@ -2797,19 +2797,19 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case 1: switch (typePower) { - case TYPE_x0: - typePower = 8; + default: + case TYPE_x1: + typePower = 0; break; case TYPE_x0_25: typePower = 4; break; + case TYPE_x0: + typePower = 8; + break; case TYPE_x0_50: typePower = 2; break; - default: - case TYPE_x1: - typePower = 0; - break; case TYPE_x2: typePower = -2; break; @@ -2827,8 +2827,8 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case TYPE_x0_25: typePower = -8; break; - default: case TYPE_x0_50: + default: typePower = 0; break; case TYPE_x1: @@ -4110,7 +4110,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) u8 tourneyId = sTourneyTreeTrainerIds[position]; u16 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) input = INFOCARD_INPUT_AB; // Next opponent card cant scroll @@ -4121,7 +4121,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) { // For trainer info cards, pos is 0 when on a trainer info card (not viewing that trainer's match progression) // Scrolling up/down from a trainer info card goes to other trainer info cards - if (JOY_NEW(DPAD_UP) && sInfoCard->pos == 0) + if (gMain.newKeys & DPAD_UP && sInfoCard->pos == 0) { if (position == 0) position = DOME_TOURNAMENT_TRAINERS_COUNT - 1; @@ -4129,7 +4129,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) position--; input = TRAINERCARD_INPUT_UP; } - else if (JOY_NEW(DPAD_DOWN) && sInfoCard->pos == 0) + else if (gMain.newKeys & DPAD_DOWN && sInfoCard->pos == 0) { if (position == DOME_TOURNAMENT_TRAINERS_COUNT - 1) position = 0; @@ -4138,13 +4138,13 @@ static u8 Task_GetInfoCardInput(u8 taskId) input = TRAINERCARD_INPUT_DOWN; } // Scrolling left can only be done after scrolling right - else if (JOY_NEW(DPAD_LEFT) && sInfoCard->pos != 0) + else if (gMain.newKeys & DPAD_LEFT && sInfoCard->pos != 0) { sInfoCard->pos--; input = TRAINERCARD_INPUT_LEFT; } // Scrolling right from a trainer info card shows their match progression - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { // Can only scroll right from a trainer card until the round they were eliminated if (DOME_TRAINERS[tourneyId].isEliminated && sInfoCard->pos - 1 < DOME_TRAINERS[tourneyId].eliminatedAt) @@ -4172,7 +4172,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) { // For match info cards, pos is 1 when on the match card, 0 when on the left trainer, and 1 when on the right trainer // Scrolling up/down from a match info card goes to the next/previous match - if (JOY_NEW(DPAD_UP) && sInfoCard->pos == 1) + if (gMain.newKeys & DPAD_UP && sInfoCard->pos == 1) { if (position == DOME_TOURNAMENT_TRAINERS_COUNT) position = sLastMatchCardNum[roundId]; @@ -4180,7 +4180,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) position--; input = MATCHCARD_INPUT_UP; } - else if (JOY_NEW(DPAD_DOWN) && sInfoCard->pos == 1) + else if (gMain.newKeys & DPAD_DOWN && sInfoCard->pos == 1) { if (position == sLastMatchCardNum[roundId]) position = DOME_TOURNAMENT_TRAINERS_COUNT; @@ -4189,12 +4189,12 @@ static u8 Task_GetInfoCardInput(u8 taskId) input = MATCHCARD_INPUT_DOWN; } // Scrolling left/right from a match info card shows the trainer info card of the competitors for that match - else if (JOY_NEW(DPAD_LEFT) && sInfoCard->pos != 0) + else if (gMain.newKeys & DPAD_LEFT && sInfoCard->pos != 0) { input = MATCHCARD_INPUT_LEFT; sInfoCard->pos--; } - else if (JOY_NEW(DPAD_RIGHT) && (sInfoCard->pos == 0 || sInfoCard->pos == 1)) + else if (gMain.newKeys & DPAD_RIGHT && (sInfoCard->pos == 0 || sInfoCard->pos == 1)) { input = MATCHCARD_INPUT_RIGHT; sInfoCard->pos++; @@ -4304,7 +4304,7 @@ static void DisplayTrainerInfoOnCard(u8 flags, u8 trainerTourneyId) textPrinter.currentY = textPrinter.y; textPrinter.letterSpacing = 2; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -4837,7 +4837,7 @@ static void DisplayMatchInfoOnCard(u8 flags, u8 matchNo) textPrinter.currentY = textPrinter.y; textPrinter.letterSpacing = 0; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5042,12 +5042,12 @@ static u8 UpdateTourneyTreeCursor(u8 taskId) int tourneyTreeCursorSpriteId = gTasks[taskId].data[1]; int roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (gMain.newKeys == B_BUTTON || (JOY_NEW(A_BUTTON) && tourneyTreeCursorSpriteId == TOURNEY_TREE_CLOSE_BUTTON)) + if (gMain.newKeys == B_BUTTON || (gMain.newKeys & A_BUTTON && tourneyTreeCursorSpriteId == TOURNEY_TREE_CLOSE_BUTTON)) { PlaySE(SE_SELECT); selection = TOURNEY_TREE_SELECTED_CLOSE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (tourneyTreeCursorSpriteId < DOME_TOURNAMENT_TRAINERS_COUNT) { @@ -5291,7 +5291,7 @@ static void Task_ShowTourneyTree(u8 taskId) gTasks[taskId].tState++; break; case 2: - sTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); + sTilemapBuffer = AllocZeroed(0x800); LZDecompressWram(gDomeTourneyLineMask_Tilemap, sTilemapBuffer); SetBgTilemapBuffer(1, sTilemapBuffer); CopyBgTilemapBufferToVram(1); @@ -5335,7 +5335,7 @@ static void Task_ShowTourneyTree(u8 taskId) textPrinter.lineSpacing = 0; textPrinter.currentX = GetStringCenterAlignXOffsetWithLetterSpacing(textPrinter.fontId, textPrinter.currentChar, 0x70, textPrinter.letterSpacing); textPrinter.currentY = 1; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5516,7 +5516,7 @@ static void Task_HandleStaticTourneyTreeInput(u8 taskId) textPrinter.y = 0; textPrinter.letterSpacing = 2; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_2; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5551,7 +5551,7 @@ static void Task_HandleStaticTourneyTreeInput(u8 taskId) gTasks[taskId].tState = STATE_WAIT_FOR_INPUT; break; case STATE_WAIT_FOR_INPUT: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].tState = STATE_CLOSE_TOURNEY_TREE; diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index a3fa275c5..388881a1c 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -1478,7 +1478,7 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 5; break; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sFactorySelectScreen->yesNoCursorPos == 0) @@ -1496,7 +1496,7 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819B958(4); @@ -1505,12 +1505,12 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Select_UpdateYesNoCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Select_UpdateYesNoCursorPosition(1); @@ -1538,7 +1538,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 retVal; PlaySE(SE_SELECT); @@ -1565,7 +1565,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) gTasks[taskId].func = Task_FromSelectScreenToSummaryScreen; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); @@ -1574,12 +1574,12 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(1); @@ -1618,21 +1618,21 @@ static void Task_HandleSelectionScreenChooseMons(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sFactorySelectScreen->unk2A2 = FALSE; gTasks[taskId].data[0] = 2; gTasks[taskId].func = Task_HandleSelectionScreenMenu; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { PlaySE(SE_SELECT); Select_UpdateBallCursorPosition(-1); Select_PrintMonCategory(); Select_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { PlaySE(SE_SELECT); Select_UpdateBallCursorPosition(1); @@ -1641,7 +1641,7 @@ static void Task_HandleSelectionScreenChooseMons(u8 taskId) } break; case 11: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); @@ -2361,7 +2361,7 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 5; break; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sFactorySwapScreen->yesNoCursorPos == 0) @@ -2380,7 +2380,7 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gTasks[taskId].data[1] = 0; @@ -2389,12 +2389,12 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) loPtr = gTasks[taskId].data[7]; gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Swap_UpdateYesNoCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Swap_UpdateYesNoCursorPosition(1); @@ -2485,12 +2485,12 @@ static void Task_HandleSwapScreenMenu(u8 taskId) case 3: if (sFactorySwapScreen->unk30 != TRUE) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); Swap_RunMenuOptionFunc(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); @@ -2501,11 +2501,11 @@ static void Task_HandleSwapScreenMenu(u8 taskId) gTasks[taskId].data[5] = 1; gTasks[taskId].func = sub_819D770; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { Swap_UpdateMenuCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { Swap_UpdateMenuCursorPosition(1); } @@ -2526,7 +2526,7 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sFactorySwapScreen->unk22 = FALSE; @@ -2534,7 +2534,7 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) sub_819EAC0(); Swap_RunActionFunc(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sFactorySwapScreen->unk22 = FALSE; @@ -2546,25 +2546,25 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) gTasks[taskId].data[5] = 0; gTasks[taskId].func = sub_819D588; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { Swap_UpdateBallCursorPosition(-1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { Swap_UpdateBallCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { Swap_UpdateActionCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { Swap_UpdateActionCursorPosition(-1); Swap_PrintMonCategory(); @@ -3929,7 +3929,7 @@ static void Task_SwapCantHaveSameMons(u8 taskId) gTasks[taskId].data[0]++; break; case 1: - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index d044f2fbd..41cffec3d 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -956,7 +956,7 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform } src = gMonSpritesGfxPtr->sprites[position]; - dst = (void *)(OBJ_VRAM0 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); + dst = (void *)(VRAM + 0x10000 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); DmaCopy32(3, src, dst, 0x800); paletteOffset = 0x100 + battlerAtk * 16; lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(targetSpecies, otId, personalityValue); @@ -1013,12 +1013,15 @@ void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite) palOffset = (battlerId * 16) + 0x100; LoadCompressedPalette(gSubstituteDollPal, palOffset, 32); } - else if (!IsContest()) + else { - if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); - else - BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); + if (!IsContest()) + { + if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) + BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); + else + BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); + } } } diff --git a/src/battle_main.c b/src/battle_main.c index bdde96be2..ec4c651f0 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -127,7 +127,6 @@ static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); - // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0; @@ -633,16 +632,19 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0V = 0x5051; ScanlineEffect_Clear(); - for (i = 0; i < 80; i++) + i = 0; + while (i < 80) { gScanlineEffectRegBuffers[0][i] = 0xF0; gScanlineEffectRegBuffers[1][i] = 0xF0; + i++; } - for (; i < 160; i++) + while (i < 160) { gScanlineEffectRegBuffers[0][i] = 0xFF10; gScanlineEffectRegBuffers[1][i] = 0xFF10; + i++; } ScanlineEffect_SetParams(sIntroScanlineParams16Bit); @@ -769,7 +771,8 @@ static void SetPlayerBerryDataInBattleStruct(void) static void SetAllPlayersBerryData(void) { - s32 i, j; + s32 i; + s32 j; if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -1828,7 +1831,7 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (gMain.heldKeys & B_BUTTON && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); @@ -2484,7 +2487,7 @@ static void sub_803939C(void) } break; case 5: - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (gBattleCommunication[CURSOR_POSITION] != 0) { @@ -2494,7 +2497,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (gBattleCommunication[CURSOR_POSITION] == 0) { @@ -2504,7 +2507,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(1); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -2518,7 +2521,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE]++; @@ -2685,7 +2688,8 @@ static void sub_80398BC(struct Sprite *sprite) // unused? static void sub_80398D0(struct Sprite *sprite) { - if (--sprite->data[4] == 0) + sprite->data[4]--; + if (sprite->data[4] == 0) { sprite->data[4] = 8; sprite->invisible ^= 1; @@ -3416,13 +3420,17 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) } } - if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) && (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - BtlController_EmitDrawTrainerPic(0); - MarkBattlerForControllerExec(gActiveBattler); + if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT + || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) + { + BtlController_EmitDrawTrainerPic(0); + MarkBattlerForControllerExec(gActiveBattler); + } } - if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) { BtlController_EmitDrawTrainerPic(0); MarkBattlerForControllerExec(gActiveBattler); @@ -3529,7 +3537,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u8 position; + u32 position; if (gBattleControllerExecFlags) return; @@ -3552,7 +3560,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3580,7 +3588,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { @@ -3595,9 +3603,7 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) position = B_POSITION_OPPONENT_LEFT; } else - { position = B_POSITION_OPPONENT_LEFT; - } if (gBattleControllerExecFlags) return; @@ -3639,7 +3645,7 @@ static void BattleIntroRecordMonsToDex(void) } } -static void sub_803B3AC(void) // unused +void sub_803B3AC(void) // unused { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3672,7 +3678,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3704,7 +3710,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; @@ -3742,7 +3748,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -static void sub_803B598(void) // unused +void sub_803B598(void) // unused { if (gBattleControllerExecFlags == 0) { @@ -3765,7 +3771,8 @@ static void sub_803B598(void) // unused static void TryDoEventsBeforeFirstTurn(void) { - s32 i, j; + s32 i; + s32 j; u8 effect = 0; if (gBattleControllerExecFlags) @@ -3955,7 +3962,11 @@ u8 IsRunningFromBattleImpossible(void) gPotentialItemEffectBattler = gActiveBattler; - if ((holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) || (gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY)) + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + return 0; + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + return 0; + if (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY) return 0; side = GetBattlerSide(gActiveBattler); @@ -4732,38 +4743,40 @@ static void SetActionsAndBattlersTurnOrder(void) gBattleStruct->focusPunchBattlerId = 0; return; } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + else { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) + { + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } } - } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; + if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) + { + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } } - } - for (i = 0; i < gBattlersCount - 1; i++) - { - for (j = i + 1; j < gBattlersCount; j++) + for (i = 0; i < gBattlersCount - 1; i++) { - u8 battler1 = gBattlerByTurnOrder[i]; - u8 battler2 = gBattlerByTurnOrder[j]; - - if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[i] != B_ACTION_SWITCH - && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + for (j = i + 1; j < gBattlersCount; j++) { - if (GetWhoStrikesFirst(battler1, battler2, FALSE)) - SwapTurnOrder(i, j); + u8 battler1 = gBattlerByTurnOrder[i]; + u8 battler2 = gBattlerByTurnOrder[j]; + if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[i] != B_ACTION_SWITCH + && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + { + if (GetWhoStrikesFirst(battler1, battler2, FALSE)) + SwapTurnOrder(i, j); + } } } } @@ -4841,8 +4854,8 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) } TryClearRageStatuses(); - gCurrentTurnActionNumber = 0; //See comment underneath - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; //Should be gActionsByTurnOrder[(gCurrentTurnActionNumber = 0)], but that doesn't match + gCurrentTurnActionNumber = 0; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; @@ -4865,10 +4878,13 @@ static void RunTurnActionsFunctions(void) gHitMarker &= ~(HITMARKER_x100000); gBattleMainFunc = sEndTurnFuncsTable[gBattleOutcome & 0x7F]; } - else if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + else { - gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); - gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + { + gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); + gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + } } } @@ -4985,15 +5001,15 @@ static void HandleEndTurn_RanFromBattle(void) { switch (gProtectStructs[gBattlerAttacker].fleeFlag) { + default: + gBattlescriptCurrInstr = BattleScript_GotAwaySafely; + break; case 1: gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; break; case 2: gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; break; - default: - gBattlescriptCurrInstr = BattleScript_GotAwaySafely; - break; } } @@ -5077,7 +5093,10 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gBattleMainFunc = ReturnFromBattleToOverworld; return; } - gBattleMainFunc = TryEvolvePokemon; + else + { + gBattleMainFunc = TryEvolvePokemon; + } } FreeAllWindowBuffers(); @@ -5172,4 +5191,3 @@ void RunBattleScriptCommands(void) if (gBattleControllerExecFlags == 0) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } - diff --git a/src/battle_message.c b/src/battle_message.c index c004665d7..59ad0cee4 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2995,7 +2995,7 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) printerTemplate.currentY = printerTemplate.y; printerTemplate.letterSpacing = textInfo[windowId].letterSpacing; printerTemplate.lineSpacing = textInfo[windowId].lineSpacing; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = textInfo[windowId].fgColor; printerTemplate.bgColor = textInfo[windowId].bgColor; printerTemplate.shadowColor = textInfo[windowId].shadowColor; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 203b572eb..1b220f145 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -522,19 +522,6 @@ static const u8 sTrainerTextGroups[50][2] = {FACILITY_CLASS_HIKER, 4}, }; -enum -{ - HINT_EXIT_DIRECTION, - HINT_REMAINING_ITEMS, - HINT_REMAINING_TRAINERS, - HINT_EXIT_SHORT_REMAINING_TRAINERS, - HINT_EXIT_SHORT_REMAINING_ITEMS, - HINT_EXIT_MEDIUM_REMAINING_TRAINERS, - HINT_EXIT_MEDIUM_REMAINING_ITEMS, - HINT_EXIT_FAR_REMAINING_TRAINERS, - HINT_EXIT_FAR_REMAINING_ITEMS, -}; - static const u8 *const sExitDirectionHintTexts1[] = { BattlePyramid_Text_ExitHintUp1, diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 8fee57855..e038e71e1 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -839,7 +839,7 @@ static void Task_HandlePyramidBagInput(u8 taskId) s16 *data = gTasks[taskId].data; if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { if (gPyramidBagCursorData.unk4 != 2) { @@ -965,7 +965,7 @@ static void HandleMenuActionInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { s8 id = Menu_GetCursorPos(); - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (id > 0 && IsValidMenuAction(id - 2)) { @@ -973,7 +973,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (id < gPyramidBagResources->menuActionsCount - 2 && IsValidMenuAction(id + 2)) { @@ -981,7 +981,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); } } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (id & 1 && IsValidMenuAction(id - 1)) { @@ -989,7 +989,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (!(id & 1) && IsValidMenuAction(id + 1)) { @@ -997,13 +997,13 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8 != NULL) sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sMenuActions[ACTION_CANCEL].func.void_u8(taskId); @@ -1143,7 +1143,7 @@ static void sub_81C64B4(u8 taskId) { sub_81C645C(data[8]); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(3, 0); @@ -1151,7 +1151,7 @@ static void sub_81C64B4(u8 taskId) ScheduleBgCopyTilemapToVram(1); sub_81C6350(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(3, 0); @@ -1179,7 +1179,7 @@ static void sub_81C65CC(u8 taskId) u16 *scrollOffset = &gPyramidBagCursorData.scrollPosition; u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemovePyramidBagItem(gSpecialVar_ItemId, data[8]); @@ -1220,7 +1220,7 @@ static void sub_81C66AC(u8 taskId) static void sub_81C66EC(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); Task_CloseBattlePyramidBagMessage(taskId); @@ -1277,7 +1277,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) s16 *data = gTasks[taskId].data; if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); @@ -1295,7 +1295,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) break; case LIST_CANCEL: PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) PerformItemSwap(taskId); else sub_81C6A14(taskId); diff --git a/src/battle_records.c b/src/battle_records.c index a8b9ead14..c6363a6ed 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -356,7 +356,7 @@ static void Task_CloseTrainerHillRecordsOnButton(u8 taskId) { struct Task *task = &gTasks[taskId]; - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); task->func = Task_BeginPaletteFade; @@ -485,7 +485,7 @@ static void CB2_ShowTrainerHillRecords(void) gMain.state++; break; case 2: - sTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); + sTilemapBuffer = AllocZeroed(0x800); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sTrainerHillRecordsBgTemplates, ARRAY_COUNT(sTrainerHillRecordsBgTemplates)); SetBgTilemapBuffer(3, sTilemapBuffer); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 3b77df294..690b26d49 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3518,7 +3518,7 @@ static void Cmd_unknown_24(void) if (HP_count == 0) gBattleOutcome |= B_OUTCOME_LOST; - + HP_count = 0; for (i = 0; i < PARTY_SIZE; i++) @@ -3535,14 +3535,17 @@ static void Cmd_unknown_24(void) if (gBattleOutcome == 0 && (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) { - s32 foundPlayer = 0, foundOpponent; + s32 foundPlayer = 0; + s32 foundOpponent; + for (i = 0; i < gBattlersCount; i += 2) { if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) foundPlayer++; } - + foundOpponent = 0; + for (i = 1; i < gBattlersCount; i += 2) { if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) @@ -3552,14 +3555,14 @@ static void Cmd_unknown_24(void) if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { if (foundOpponent + foundPlayer > 1) - gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1); + gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; } else { if (foundOpponent != 0 && foundPlayer != 0) - gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1); + gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; } @@ -4660,10 +4663,8 @@ static void Cmd_jumpifcantswitch(void) || (gStatuses3[gActiveBattler] & STATUS3_ROOTED))) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - return; } - - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { #ifndef NONMATCHING asm("":::"r5"); @@ -5361,21 +5362,21 @@ static void Cmd_yesnoboxlearnmove(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[1] == 0) @@ -5389,7 +5390,7 @@ static void Cmd_yesnoboxlearnmove(void) gBattleScripting.learnMoveState = 5; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleScripting.learnMoveState = 5; @@ -5478,21 +5479,21 @@ static void Cmd_yesnoboxstoplearningmove(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -5503,7 +5504,7 @@ static void Cmd_yesnoboxstoplearningmove(void) HandleBattleWindow(0x18, 0x8, 0x1D, 0xD, WINDOW_CLEAR); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); @@ -5536,8 +5537,8 @@ static void Cmd_hitanimation(void) static u32 GetTrainerMoneyToGive(u16 trainerId) { u32 i = 0; + u32 lastMonLevel = 0; u32 moneyReward; - u8 lastMonLevel = 0; if (trainerId == TRAINER_SECRET_BASE) { @@ -5773,28 +5774,28 @@ static void Cmd_yesnobox(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gBattleCommunication[CURSOR_POSITION] = 1; PlaySE(SE_SELECT); HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); gBattlescriptCurrInstr++; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); @@ -6037,7 +6038,7 @@ static void PutLevelAndGenderOnLvlUpBox(void) printerTemplate.currentY = 0; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = TEXT_COLOR_WHITE; printerTemplate.bgColor = TEXT_COLOR_TRANSPARENT; printerTemplate.shadowColor = TEXT_COLOR_DARK_GREY; @@ -7128,6 +7129,7 @@ static void Cmd_forcerandomswitch(void) s32 i; s32 battler1PartyId = 0; s32 battler2PartyId = 0; + s32 firstMonId; s32 lastMonId = 0; // + 1 s32 monsCount; @@ -7249,10 +7251,11 @@ static void Cmd_forcerandomswitch(void) { i = Random() % monsCount; i += firstMonId; - } while (i == battler2PartyId || i == battler1PartyId); + } + while (i == battler2PartyId || i == battler1PartyId); } while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE - || GetMonData(&party[i], MON_DATA_HP) == 0); // Should be one while loop, conjoined by an ||, but that doesn't match. Equivalent logic though + || GetMonData(&party[i], MON_DATA_HP) == 0); //should be one while loop, but that doesn't match. } *(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i; @@ -10071,21 +10074,21 @@ static void Cmd_trygivecaughtmonnick(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -10098,7 +10101,7 @@ static void Cmd_trygivecaughtmonnick(void) gBattleCommunication[MULTIUSE_STATE] = 4; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE] = 4; diff --git a/src/battle_tower.c b/src/battle_tower.c index 046362105..b7d03a5bc 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1446,7 +1446,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) } else if (trainerId == TRAINER_FRONTIER_BRAIN) { - return GetFrontierBrainTrainerClass(); // This sticks out like a sore thumb, but this is the only other way that matches. Maybe it SHOULD be assigned to ret, or all early returns. I don't know. + return GetFrontierBrainTrainerClass(); } else if (trainerId == TRAINER_STEVEN_PARTNER) { diff --git a/src/battle_transition.c b/src/battle_transition.c index 4a9d26303..496cc9e09 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -3973,7 +3973,7 @@ static bool8 Phase2_FrontierLogoWave_Func4(struct Task *task) for (i = 0; i < 160; i++, var6 += var8) { - const u16 index = var6 >> 8; + s16 index = var6 / 256; gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(index & 0xff, amplitude); } diff --git a/src/battle_tv.c b/src/battle_tv.c index dea711609..7e311fdab 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -714,15 +714,16 @@ void BattleTv_SetDataBasedOnAnimation(u8 animationId) void TryPutLinkBattleTvShowOnAir(void) { - u16 playerBestSpecies = 0, opponentBestSpecies = 0, moveId = 0; - s16 sum = 0, playerBestSum = 0, opponentBestSum = SHRT_MAX; + u16 playerBestSpecies = 0, opponentBestSpecies = 0; + s16 playerBestSum = 0, opponentBestSum = SHRT_MAX; u8 playerBestMonId = 0, opponentBestMonId = 0; struct BattleTvMovePoints *movePoints = NULL; u8 countPlayer = 0, countOpponent = 0; - u16 species; + s16 sum = 0; + u16 species = 0; + u16 moveId = 0; s32 i, j; - - int zero = 0, one = 1; // stupid variables needed to match. Feel free to get rid of them. + int zero = 0, one = 1; //needed for matching if (gBattleStruct->anyMonHasTransformed) return; diff --git a/src/battle_util.c b/src/battle_util.c index f98b088e0..7025f0e3f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1,19 +1,31 @@ #include "global.h" #include "battle.h" -#include "battle_util.h" #include "battle_anim.h" +#include "battle_arena.h" +#include "battle_pyramid.h" +#include "battle_util.h" #include "pokemon.h" +#include "international_string_util.h" #include "item.h" #include "util.h" #include "battle_scripts.h" #include "random.h" +#include "text.h" +#include "safari_zone.h" +#include "sound.h" +#include "sprite.h" #include "string_util.h" +#include "task.h" +#include "trig.h" +#include "window.h" +#include "battle_message.h" #include "battle_ai_script_commands.h" #include "battle_controllers.h" #include "event_data.h" #include "link.h" #include "field_weather.h" #include "constants/abilities.h" +#include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_script_commands.h" #include "constants/battle_string_ids.h" @@ -21,16 +33,16 @@ #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/moves.h" -#include "constants/weather.h" -#include "battle_arena.h" -#include "battle_pyramid.h" -#include "international_string_util.h" -#include "safari_zone.h" -#include "sound.h" -#include "task.h" -#include "trig.h" -#include "window.h" #include "constants/songs.h" +#include "constants/species.h" +#include "constants/weather.h" + +/* +NOTE: The data and functions in this file up until (but not including) sSoundMovesTable +are actually part of battle_main.c. They needed to be moved to this file in order to +match the ROM; this is also why sSoundMovesTable's declaration is in the middle of +functions instead of at the top of the file with the other declarations. +*/ extern const u8 *const gBattleScriptsForMoveEffects[]; extern const u8 *const gBattlescriptsForBallThrow[]; @@ -282,9 +294,7 @@ void HandleAction_UseItem(void) gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; gBattle_BG0_X = 0; gBattle_BG0_Y = 0; - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); if (gLastUsedItem <= LAST_BALL) // is ball @@ -310,18 +320,18 @@ void HandleAction_UseItem(void) break; case AI_ITEM_CURE_CONDITION: gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1) + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) { - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x3E) + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) gBattleCommunication[MULTISTRING_CHOOSER] = 5; } else { - do + while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; - } while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)); + } } break; case AI_ITEM_X_STAT: @@ -337,7 +347,7 @@ void HandleAction_UseItem(void) while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; gBattleTextBuff1[2]++; } @@ -353,7 +363,7 @@ void HandleAction_UseItem(void) break; } - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))]; + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; } gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } diff --git a/src/berry.c b/src/berry.c index d70e8c353..98264f37b 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1331,7 +1331,7 @@ void ResetBerryTreeSparkleFlags(void) s16 bottom; int i; - GetCameraCoords((u16*)&cam_left, (u16*)&cam_top); + GetCameraCoords(&cam_left, &cam_top); left = cam_left; top = cam_top + 3; right = cam_left + 14; diff --git a/src/berry_blender.c b/src/berry_blender.c index 2cdb841ee..16ba42bd7 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -168,8 +168,8 @@ struct BerryBlender u16 progressBarValue; u16 maxProgressBarValue; u16 centerScale; - s16 bg_X; - s16 bg_Y; + u16 bg_X; + u16 bg_Y; u8 opponentTaskIds[BLENDER_MAX_PLAYERS - 1]; u8 perfectOpponents; // for debugging, NPCs will always hit Best u16 scores[BLENDER_MAX_PLAYERS][NUM_SCORE_TYPES]; @@ -3387,13 +3387,13 @@ static void RestoreBgCoord(s16* coord) // For "unshaking" the screen after ShakeBgCoordForHit is called static void RestoreBgCoords(void) { - RestoreBgCoord((s16 *)&sBerryBlender->bg_X); - RestoreBgCoord((s16 *)&sBerryBlender->bg_Y); + RestoreBgCoord(&sBerryBlender->bg_X); + RestoreBgCoord(&sBerryBlender->bg_Y); } static void BlenderLandShakeBgCoord(s16* coord, u16 timer) { - u8 strength; + s32 strength; if (timer < 10) strength = 16; diff --git a/src/berry_crush.c b/src/berry_crush.c index 2175d2abb..76d2d7450 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -146,49 +146,38 @@ struct BerryCrushGame { MainCallback unk0; u32 (* unk4)(struct BerryCrushGame *, u8 *); - u8 unk8; u8 unk9; u8 unkA; u8 unkB; - u8 unkC; u8 unkD; - u8 unkE; u8 unkF; - u16 unk10; u16 unk12; u16 unk14; - u16 unk16; s16 unk18; s16 unk1A; - s32 unk1C; + int unk1C; s32 unk20; u8 unk24; - u8 unk25_0:1; u8 unk25_1:1; u8 unk25_2:1; u8 unk25_3:1; u8 unk25_4:1; u8 unk25_5:3; - u16 unk26; - u16 unk28; s16 unk2A; s16 unk2C; - s16 unk2E; s16 unk30; s16 unk32; s16 unk34; - u8 unk36[0xA]; - struct BerryCrushGame_40 unk40; struct BerryCrushGame_5C unk5C; union BerryCrushGame_68 unk68; @@ -215,7 +204,7 @@ void sub_8022524(struct BerryCrushGame_138 *, u16); void sub_8022B28(struct Sprite *); void sub_8022554(struct BerryCrushGame_138 *r0); void sub_8024578(struct BerryCrushGame *); -void sub_8024644(u8 *, u8, u8, u16, u8); +void sub_8024644(u8 *, u32, u32, u32, u32); static void sub_8022A20(struct Sprite *sprite); static u32 BerryCrushCommand_BeginNormalPaletteFade(struct BerryCrushGame *r6, u8 *r1); static u32 sub_8022CB0(struct BerryCrushGame *r4, u8 *r5); @@ -1676,7 +1665,7 @@ static void Task_ShowBerryCrushRankings(u8 taskId) CopyWindowToVram(data[1], 3); break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) break; else return; @@ -2401,7 +2390,7 @@ void sub_802339C(struct BerryCrushGame *r4) } } } - if (r8 >= 2) + if (r8 > 1) { for (r7 = 0; r7 < r4->unk9; ++r7) { @@ -2509,9 +2498,9 @@ void sub_8023558(struct BerryCrushGame *r3) void sub_80236B8(struct BerryCrushGame *r5) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) r5->unk5C.unk02_2 = 1; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { if (r5->unk68.as_four_players.others[r5->unk8].unk4.as_hwords[5] < r5->unk28) ++r5->unk68.as_four_players.others[r5->unk8].unk4.as_hwords[5]; @@ -2591,7 +2580,6 @@ void sub_802385C(struct BerryCrushGame *r5) for (r4 = 0; r4 < r5->unk9; ++r4) r5->unk68.as_four_players.others[r4].unk4.as_2d_bytes[1][5] = 0; #endif - if ((gRecvCmds[0][0] & 0xFF00) != RFUCMD_SEND_PACKET || gRecvCmds[0][1] != 2) { @@ -2978,7 +2966,7 @@ static u32 sub_8024048(struct BerryCrushGame *r5, u8 *r6) --r5->unk138.unk0; return 0; } - if (!(JOY_NEW(A_BUTTON))) + if (!(gMain.newKeys & A_BUTTON)) return 0; PlaySE(SE_SELECT); sub_802222C(r5); @@ -3281,11 +3269,14 @@ static void BerryCrush_SetPaletteFadeParams(u8 *params, bool8 communicateAfter, params[9] = communicateAfter; } -void sub_8024644(u8 *r0, u8 r1, u8 r2, u16 r3, u8 r5) +void sub_8024644(u8 *r0, u32 r1, u32 r2, u32 r3, u32 r5) { + u8 sp[4]; + + 0[(u16 *)sp] = r3; r0[0] = r1; r0[1] = r2; - r0[2] = ((u8 *)&r3)[0]; - r0[3] = ((u8 *)&r3)[1]; + r0[2] = sp[0]; + r0[3] = sp[1]; r0[4] = r5; } diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index 4c4a010b2..dcc21d036 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -190,13 +190,13 @@ static void berry_fix_main(void) berry_fix_mb_manager->state = 1; break; case 1: - if (berry_fix_text_update(5) == 5 && (JOY_NEW(A_BUTTON))) + if (berry_fix_text_update(5) == 5 && (gMain.newKeys & A_BUTTON)) { berry_fix_mb_manager->state = 2; } break; case 2: - if (berry_fix_text_update(0) == 0 && (JOY_NEW(A_BUTTON))) + if (berry_fix_text_update(0) == 0 && (gMain.newKeys & A_BUTTON)) { berry_fix_mb_manager->state = 3; } @@ -235,13 +235,13 @@ static void berry_fix_main(void) } break; case 6: - if (berry_fix_text_update(3) == 3 && JOY_NEW(A_BUTTON)) + if (berry_fix_text_update(3) == 3 && gMain.newKeys & A_BUTTON) { DoSoftReset(); } break; case 7: - if (berry_fix_text_update(4) == 4 && JOY_NEW(A_BUTTON)) + if (berry_fix_text_update(4) == 4 && gMain.newKeys & A_BUTTON) { berry_fix_mb_manager->state = 1; } diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c index 089228b17..e5c89bdb7 100644 --- a/src/berry_tag_screen.c +++ b/src/berry_tag_screen.c @@ -536,12 +536,12 @@ static void Task_HandleInput(u8 taskId) { if (!gPaletteFade.active) { - u16 arrowKeys = JOY_REPEAT(DPAD_ANY); + u16 arrowKeys = gMain.newAndRepeatedKeys & DPAD_ANY; if (arrowKeys == DPAD_UP) TryChangeDisplayedBerry(taskId, -1); else if (arrowKeys == DPAD_DOWN) TryChangeDisplayedBerry(taskId, 1); - else if (JOY_NEW(A_BUTTON | B_BUTTON)) + else if (gMain.newKeys & (A_BUTTON | B_BUTTON)) PrepareToCloseBerryTagScreen(taskId); } } diff --git a/src/cable_club.c b/src/cable_club.c index f02683c9d..93f87ec9b 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -163,7 +163,7 @@ static bool32 CheckLinkErrored(u8 taskId) static bool32 CheckLinkCanceledBeforeConnection(u8 taskId) { - if ((JOY_NEW(B_BUTTON)) + if ((gMain.newKeys & B_BUTTON) && IsLinkConnectionEstablished() == FALSE) { gLinkType = 0; @@ -178,7 +178,7 @@ static bool32 CheckLinkCanceled(u8 taskId) if (IsLinkConnectionEstablished()) SetSuppressLinkErrorMessage(TRUE); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gLinkType = 0; gTasks[taskId].func = Task_LinkupFailed; @@ -277,7 +277,7 @@ static void Task_LinkupAwaitConfirmation(u8 taskId) UpdateLinkPlayerCountDisplay(taskId, linkPlayerCount); - if (!(JOY_NEW(A_BUTTON))) + if (!(gMain.newKeys & A_BUTTON)) return; if (linkPlayerCount < tMinPlayers) @@ -304,12 +304,12 @@ static void Task_LinkupTryConfirmation(u8 taskId) ShowFieldAutoScrollMessage(gText_ConfirmLinkWhenPlayersReady); gTasks[taskId].func = Task_LinkupConfirmWhenReady; } - else if (JOY_HELD(B_BUTTON)) + else if (gMain.heldKeys & B_BUTTON) { ShowFieldAutoScrollMessage(gText_ConfirmLinkWhenPlayersReady); gTasks[taskId].func = Task_LinkupConfirmWhenReady; } - else if (JOY_HELD(A_BUTTON)) + else if (gMain.heldKeys & A_BUTTON) { PlaySE(SE_SELECT); CheckShouldAdvanceLinkState(); diff --git a/src/confetti_util.c b/src/confetti_util.c index 6d4770056..3bda3ab53 100644 --- a/src/confetti_util.c +++ b/src/confetti_util.c @@ -30,8 +30,10 @@ static void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 hei static void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. { - u8 i, j; - u8 x, y; + u8 i; + u8 j; + u8 x; + u8 y; const u16 *_src; for (i = 0, _src = src, y = top; i < height; i++) diff --git a/src/contest.c b/src/contest.c index 841224577..a4f73ef90 100644 --- a/src/contest.c +++ b/src/contest.c @@ -998,6 +998,8 @@ void ResetLinkContestBoolean(void) static void SetupContestGpuRegs(void) { + u16 savedIme; + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP); SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); @@ -1492,7 +1494,7 @@ static void Task_DisplayAppealNumberText(u8 taskId) static void Task_TryShowMoveSelectScreen(u8 taskId) { // Wait for button press to show move select screen - if ((JOY_NEW(A_BUTTON)) || (gMain.newKeys == B_BUTTON)) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys == B_BUTTON)) { PlaySE(SE_SELECT); if (!Contest_IsMonsTurnDisabled(gContestPlayerMonIndex)) @@ -1558,7 +1560,7 @@ static void Task_HandleMoveSelectInput(u8 taskId) numMoves++; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gTasks[taskId].func = Task_SelectedMove; @@ -3407,7 +3409,8 @@ static void GetAllChosenMoves(void) static void RankContestants(void) { - s32 i, j; + s32 i; + s32 j; s16 arr[CONTESTANT_COUNT]; for (i = 0; i < CONTESTANT_COUNT; i++) @@ -3482,7 +3485,8 @@ static bool8 ContestantCanUseTurn(u8 contestant) { if (eContestantStatus[contestant].numTurnsSkipped != 0 || eContestantStatus[contestant].noMoreTurns) return FALSE; - return TRUE; + else + return TRUE; } static void SetContestantStatusesForNextRound(void) @@ -3536,7 +3540,8 @@ bool8 Contest_IsMonsTurnDisabled(u8 contestant) { if (eContestantStatus[contestant].numTurnsSkipped != 0 || eContestantStatus[contestant].noMoreTurns) return TRUE; - return FALSE; + else + return FALSE; } static void CalculateTotalPointsForContestant(u8 contestant) @@ -4136,12 +4141,12 @@ static u8 CreateContestantBoxBlinkSprites(u8 contestant) CpuFill32(0, gContestResources->boxBlinkTiles2 + 0x500, 0x300); RequestDma3Copy(gContestResources->boxBlinkTiles1, - (u8 *)(OBJ_VRAM0 + gSprites[spriteId1].oam.tileNum * 32), + (u8 *)(VRAM + 0x10000 + gSprites[spriteId1].oam.tileNum * 32), 0x800, 1); RequestDma3Copy(gContestResources->boxBlinkTiles2, - (u8 *)(OBJ_VRAM0 + gSprites[spriteId2].oam.tileNum * 32), + (u8 *)(VRAM + 0x10000 + gSprites[spriteId2].oam.tileNum * 32), 0x800, 1); @@ -4479,14 +4484,17 @@ static void CalculateAppealMoveImpact(u8 contestant) eContestantStatus[contestant].comboAppealBonus = eContestantStatus[contestant].baseAppeal * eContestantStatus[contestant].completedCombo; eContestantStatus[contestant].completedComboFlag = TRUE; // Redundant with completedCombo, used by AI } - else if (gContestMoves[eContestantStatus[contestant].currMove].comboStarterId != 0) - { - eContestantStatus[contestant].hasJudgesAttention = TRUE; - eContestantStatus[contestant].usedComboMove = TRUE; - } else { - eContestantStatus[contestant].hasJudgesAttention = FALSE; + if (gContestMoves[eContestantStatus[contestant].currMove].comboStarterId != 0) + { + eContestantStatus[contestant].hasJudgesAttention = TRUE; + eContestantStatus[contestant].usedComboMove = TRUE; + } + else + { + eContestantStatus[contestant].hasJudgesAttention = FALSE; + } } } if (eContestantStatus[contestant].repeatedMove) @@ -4727,8 +4735,8 @@ static void UpdateApplauseMeter(void) src = &gContestApplauseMeterGfx[64]; else src = gContestApplauseMeterGfx; - CpuCopy32(src, (void *)(OBJ_VRAM0 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 17 + i) * 32), 32); - CpuCopy32(src + 32, (void *)(OBJ_VRAM0 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 25 + i) * 32), 32); + CpuCopy32(src, (void *)(VRAM + 0x10000 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 17 + i) * 32), 32); + CpuCopy32(src + 32, (void *)(VRAM + 0x10000 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 25 + i) * 32), 32); if (eContest.applauseLevel > 4) StartApplauseOverflowAnimation(); @@ -5410,7 +5418,7 @@ static void Contest_PrintTextToBg0WindowStd(u32 windowId, const u8 *b) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 15; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; @@ -5433,7 +5441,7 @@ void Contest_PrintTextToBg0WindowAt(u32 windowId, u8 *currChar, s32 x, s32 y, s3 printerTemplate.currentY = y; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 15; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; @@ -5457,7 +5465,7 @@ static void Contest_StartTextPrinter(const u8 *currChar, bool32 b) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 1; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; diff --git a/src/contest_painting.c b/src/contest_painting.c index ceef8a902..ccf97c460 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -248,7 +248,7 @@ static void HoldContestPainting(void) gContestPaintingFadeCounter--; break; case 1: - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { gContestPaintingState++; BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB(0, 0, 0)); @@ -397,16 +397,16 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) { for (pixelX = 0; pixelX < 8; pixelX++) { - colorIndex = spriteGfx[((tileY * 8) + tileX) * 32 + (pixelY << 2) + (pixelX >> 1)]; + colorIndex = spriteGfx[32 * (tileY * 8 + tileX) + (pixelY << 2) + (pixelX >> 1)]; if (pixelX & 1) colorIndex >>= 4; else - colorIndex &= 0xF; // %=16 works here too. Both match + colorIndex &= 0xF; - if (colorIndex == 0) // transparent pixel - (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = 0x8000; + if (colorIndex == 0) // transparent pixel + (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = 0x8000; else - (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; + (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; } } } @@ -501,7 +501,6 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) static void InitPaintingMonOamData(u8 contestWinnerId) { - gMain.oamBuffer[0] = sContestPaintingMonOamData; gMain.oamBuffer[0].tileNum = 0; @@ -512,7 +511,7 @@ static void InitPaintingMonOamData(u8 contestWinnerId) } else { - gMain.oamBuffer[0].x = 88; // Duplicated Code + gMain.oamBuffer[0].x = 88; // Duplicated code gMain.oamBuffer[0].y = 24; } } diff --git a/src/contest_util.c b/src/contest_util.c index ae76eda6b..7f9468146 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -1151,12 +1151,12 @@ static void TryCreateWirelessSprites(void) static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) { u16 windowId; - s32 origWidth, strWidth; + int origWidth; + int strWidth; u8 *spriteTilePtrs[4]; u8 *dst; - { - struct WindowTemplate windowTemplate; //It's important the lifetime of this struct ends after the clear + struct WindowTemplate windowTemplate; memset(&windowTemplate, 0, sizeof(windowTemplate)); windowTemplate.width = 30; windowTemplate.height = 2; @@ -1165,33 +1165,33 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) } origWidth = GetStringWidth(1, text, 0); - if ((strWidth = (origWidth + 9) / 8) > 30) - strWidth = 30; + strWidth = (origWidth + 9) / 8; + if (strWidth > 30) + strWidth = 30; AddTextPrinterParameterized3(windowId, 1, (strWidth * 8 - origWidth) / 2, 1, sContestLinkTextColors, -1, text); - { s32 i; struct Sprite *sprite; const u8 *src, *windowTilesPtr; - windowTilesPtr = (const u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); - src = sUnknown_0858D6D0; + windowTilesPtr = (u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); + src = (u8 *)(sUnknown_0858D6D0); sprite = &gSprites[spriteId]; - spriteTilePtrs[0] = (u8 *)((OBJ_VRAM0) + sprite->oam.tileNum * 32); + spriteTilePtrs[0] = (u8 *)(sprite->oam.tileNum * 32 + VRAM + 0x10000); for (i = 1; i < 4; i++) - spriteTilePtrs[i] = (u8 *)((OBJ_VRAM0) + gSprites[sprite->data[i - 1]].oam.tileNum * 32); - + spriteTilePtrs[i] = (void*)(gSprites[sprite->data[i - 1]].oam.tileNum * 32 + VRAM + 0x10000); + for (i = 0; i < 4; i++) CpuFill32(0, spriteTilePtrs[i], 0x400); - + dst = spriteTilePtrs[0]; CpuCopy32(src, dst, 0x20); CpuCopy32(src + 128, dst + 0x100, 0x20); CpuCopy32(src + 128, dst + 0x200, 0x20); - CpuCopy32(src + 64, dst + 0x300, 0x20); - + CpuCopy32(src + 64, dst + 0x300, 0x20); + for (i = 0; i < strWidth; i++) { dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; @@ -1203,10 +1203,10 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) } dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; - CpuCopy32(src + 32, dst, 0x20); + CpuCopy32(src + 32, dst, 0x20); CpuCopy32(src + 160, dst + 0x100, 0x20); CpuCopy32(src + 160, dst + 0x200, 0x20); - CpuCopy32(src + 96, dst + 0x300, 0x20); + CpuCopy32(src + 96, dst + 0x300, 0x20); } RemoveWindow(windowId); @@ -1922,7 +1922,7 @@ static void AddContestTextPrinter(int windowId, u8 *str, int x) textPrinter.currentY = 2; textPrinter.letterSpacing = 0; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = 1; textPrinter.bgColor = 0; textPrinter.shadowColor = 8; diff --git a/src/credits.c b/src/credits.c index 41d1c1686..90cd7ebf3 100644 --- a/src/credits.c +++ b/src/credits.c @@ -1142,7 +1142,7 @@ static void CB2_RunCreditsSequence(void) RunTasks(); AnimateSprites(); - if ((JOY_HELD(B_BUTTON)) + if ((gMain.heldKeys & B_BUTTON) && gHasHallOfFameRecords != 0 && gTasks[gUnknown_0203BCE2].func == Task_ProgressCreditTasks) { @@ -1159,7 +1159,7 @@ static void sub_8175548(void) { ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sBackgroundTemplates, 1); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); LoadPalette(gUnknown_085E56F0, 0x80, 0x40); InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); diff --git a/src/daycare.c b/src/daycare.c index 31014bf7f..d6b2e207f 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1185,7 +1185,7 @@ static void DaycareAddTextPrinter(u8 windowId, const u8 *text, u32 x, u32 y) printer.y = y; printer.currentX = x; printer.currentY = y; - printer.style = 0; + printer.unk = 0; gTextFlags.useAlternateDownArrow = 0; printer.letterSpacing = 0; printer.lineSpacing = 1; @@ -1236,7 +1236,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) { u32 input = ListMenu_ProcessInput(gTasks[taskId].tMenuListTaskId); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (input) { @@ -1254,7 +1254,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) DestroyTask(taskId); EnableBothScriptContexts(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { gSpecialVar_Result = DAYCARE_EXITED_LEVEL_MENU; DestroyListMenuTask(gTasks[taskId].tMenuListTaskId, NULL, NULL); diff --git a/src/decoration.c b/src/decoration.c index 22ae327f9..40cccbe5e 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1147,7 +1147,7 @@ static void DontTossDecoration(u8 taskId) static void ReturnToDecorationItemsAfterInvalidSelection(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearDialogWindowAndFrame(0, 0); AddDecorationWindow(WINDOW_DECORATION_CATEGORIES); @@ -1803,7 +1803,7 @@ static bool8 ApplyCursorMovement_IsInvalid(u8 taskId) static bool8 IsHoldingDirection(void) { - u16 heldKeys = JOY_HELD(DPAD_ANY); + u16 heldKeys = gMain.heldKeys & DPAD_ANY; if (heldKeys != DPAD_UP && heldKeys != DPAD_DOWN && heldKeys != DPAD_LEFT && heldKeys != DPAD_RIGHT) return FALSE; @@ -1827,14 +1827,13 @@ static void Task_SelectLocation(u8 taskId) sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].yesFunc(taskId); return; } - - if (tButton == B_BUTTON) + else if (tButton == B_BUTTON) { sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].noFunc(taskId); return; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_UP) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_UP) { sDecorationLastDirectionMoved = DIR_SOUTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; @@ -1842,7 +1841,7 @@ static void Task_SelectLocation(u8 taskId) tCursorY--; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_DOWN) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_DOWN) { sDecorationLastDirectionMoved = DIR_NORTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; @@ -1850,7 +1849,7 @@ static void Task_SelectLocation(u8 taskId) tCursorY++; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_LEFT) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_LEFT) { sDecorationLastDirectionMoved = DIR_WEST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = -2; @@ -1858,7 +1857,7 @@ static void Task_SelectLocation(u8 taskId) tCursorX--; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_RIGHT) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_RIGHT) { sDecorationLastDirectionMoved = DIR_EAST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 2; @@ -1878,10 +1877,10 @@ static void Task_SelectLocation(u8 taskId) if (!tButton) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) tButton = A_BUTTON; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) tButton = B_BUTTON; } } @@ -1896,7 +1895,7 @@ static void ContinueDecorating(u8 taskId) static void CantPlaceDecorationPrompt(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) ContinueDecorating(taskId); } @@ -1929,7 +1928,7 @@ static void CopyTile(u8 *dest, u16 tile) case BG_TILE_H_FLIP(0) >> 10: for (i = 0; i < 8; i++) { - dest[4 * i + 0] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); + dest[4 * i] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); dest[4 * i + 1] = (buffer[4 * (i + 1) - 2] >> 4) + ((buffer[4 * (i + 1) - 2] & 0x0F) << 4); dest[4 * i + 2] = (buffer[4 * (i + 1) - 3] >> 4) + ((buffer[4 * (i + 1) - 3] & 0x0F) << 4); dest[4 * i + 3] = (buffer[4 * (i + 1) - 4] >> 4) + ((buffer[4 * (i + 1) - 4] & 0x0F) << 4); @@ -1938,7 +1937,7 @@ static void CopyTile(u8 *dest, u16 tile) case BG_TILE_V_FLIP(0) >> 10: for (i = 0; i < 8; i++) { - dest[4 * i + 0] = buffer[4 * (7 - i) + 0]; + dest[4 * i] = buffer[4 * (7 - i)]; dest[4 * i + 1] = buffer[4 * (7 - i) + 1]; dest[4 * i + 2] = buffer[4 * (7 - i) + 2]; dest[4 * i + 3] = buffer[4 * (7 - i) + 3]; @@ -2387,7 +2386,7 @@ static void AttemptPutAwayDecoration_(u8 taskId) static void ContinuePuttingAwayDecorationsPrompt(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) ContinuePuttingAwayDecorations(taskId); } diff --git a/src/dewford_trend.c b/src/dewford_trend.c index e0063ec1b..5c7e50f16 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -219,11 +219,10 @@ void BufferTrendyPhraseString(void) ConvertEasyChatWordsToString(gStringVar1, s->words, 2, 1); } - void TrendyPhraseIsOld(void) { - u8 result = 0; - + u16 result = 0; + do { if (gSaveBlock1Ptr->easyChatPairs[0].unk0_0 - gSaveBlock1Ptr->easyChatPairs[1].unk0_0 > 1) @@ -234,7 +233,7 @@ void TrendyPhraseIsOld(void) break; result = 1; } while (0); - + gSpecialVar_Result = result; } @@ -249,46 +248,46 @@ static bool8 sub_8122A58(struct EasyChatPair *a, struct EasyChatPair *b, u8 c) { case 0: if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; break; case 1: if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; break; case 2: if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; if (a->unk2 > b->unk2) - return TRUE; + return 1; if (a->unk2 < b->unk2) - return FALSE; + return 0; if (a->words[0] > b->words[0]) - return TRUE; + return 1; if (a->words[0] < b->words[0]) - return FALSE; + return 0; if (a->words[1] > b->words[1]) - return TRUE; + return 1; if (a->words[1] < b->words[1]) - return FALSE; - return TRUE; + return 0; + return 1; } return Random() & 1; } diff --git a/src/digit_obj_util.c b/src/digit_obj_util.c index f887dafb9..fe5d49e69 100644 --- a/src/digit_obj_util.c +++ b/src/digit_obj_util.c @@ -33,7 +33,7 @@ struct DigitPrinterAlloc }; // this file's functions -static u8 GetFirstOamId(u8 oamCount); +static u8 GetFirstOamId(u8 oamCount);; static void CopyWorkToOam(struct DigitPrinter *objWork); static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign); static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign); diff --git a/src/diploma.c b/src/diploma.c index f243d09f9..7eb3b0e81 100644 --- a/src/diploma.c +++ b/src/diploma.c @@ -107,7 +107,7 @@ static void Task_DiplomaFadeIn(u8 taskId) static void Task_DiplomaWaitForKeyPress(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_DiplomaFadeOut; diff --git a/src/dodrio_berry_picking.c b/src/dodrio_berry_picking.c index 66eacc5f9..1e274a4a1 100644 --- a/src/dodrio_berry_picking.c +++ b/src/dodrio_berry_picking.c @@ -2354,19 +2354,19 @@ static void sub_8027554(void) { if (gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] == 0) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 2; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; PlaySE(SE_M_CHARM); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 3; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; PlaySE(SE_M_CHARM); } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 1; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; @@ -2652,7 +2652,7 @@ static void Task_ShowDodrioBerryPickingRecords(u8 taskId) data[0]++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { rbox_fill_rectangle(data[1]); CopyWindowToVram(data[1], 1); @@ -4265,7 +4265,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 4: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4297,7 +4297,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 8: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4357,7 +4357,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 11: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4423,14 +4423,14 @@ static void sub_802A010(void) AddTextPrinterParameterized(gUnknown_02022CF8->unk3008[1], 1, gText_SelectorArrow2, 0, ((y - 1) * 16) + 1, -1, NULL); CopyWindowToVram(gUnknown_02022CF8->unk3008[1], 3); // Increment state only if A or B button have been pressed. - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gUnknown_02022CF8->unk3020 == 0) gUnknown_02022CF8->unk3020 = 1; gUnknown_02022CF8->state++; } - else if (JOY_NEW(DPAD_UP | DPAD_DOWN)) + else if (gMain.newKeys & (DPAD_UP | DPAD_DOWN)) { PlaySE(SE_SELECT); switch (gUnknown_02022CF8->unk3020) @@ -4446,7 +4446,7 @@ static void sub_802A010(void) break; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gUnknown_02022CF8->unk3020 = 2; diff --git a/src/easy_chat.c b/src/easy_chat.c index 2e58dec0d..6dca3f56a 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1522,7 +1522,7 @@ static u16 sub_811AB68(void) { do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_811BF78(); sEasyChatScreen->state = 2; @@ -1531,30 +1531,30 @@ static u16 sub_811AB68(void) sEasyChatScreen->unk_0c = 0; return 9; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return sub_811B150(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { return sub_811B1B4(); } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { sEasyChatScreen->mainCursorRow--; break; } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { sEasyChatScreen->mainCursorColumn--; break; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { sEasyChatScreen->mainCursorRow++; break; } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { sEasyChatScreen->mainCursorColumn++; break; @@ -1594,7 +1594,7 @@ static u16 sub_811ACDC(void) { do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sEasyChatScreen->mainCursorColumn) { @@ -1609,30 +1609,30 @@ static u16 sub_811ACDC(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { return sub_811B150(); } - if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { return sub_811B1B4(); } - if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { sEasyChatScreen->mainCursorRow--; break; } - if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { sEasyChatScreen->mainCursorColumn--; break; } - if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { sEasyChatScreen->mainCursorRow = 0; break; } - if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { sEasyChatScreen->mainCursorColumn++; break; @@ -1665,10 +1665,10 @@ static u16 sub_811ACDC(void) static u16 sub_811AE44(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return sub_811B32C(); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sEasyChatScreen->unk_0a != -1) return sub_811B2B0(); @@ -1684,19 +1684,19 @@ static u16 sub_811AE44(void) } } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) return sub_811B33C(); - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return sub_811B528(2); - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return sub_811B528(3); - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return sub_811B528(1); - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return sub_811B528(0); return 0; @@ -1704,31 +1704,31 @@ static u16 sub_811AE44(void) static u16 sub_811AF00(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { sEasyChatScreen->state = 2; return 14; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return sub_811B394(); - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) return sub_811B794(4); - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) return sub_811B794(5); - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return sub_811B794(2); - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return sub_811B794(3); - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return sub_811B794(1); - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return sub_811B794(0); return 0; @@ -1793,10 +1793,10 @@ static u16 sub_811B040(void) static u16 sub_811B08C(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return 26; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return sub_811B150(); return 0; @@ -1804,7 +1804,7 @@ static u16 sub_811B08C(void) static u16 sub_811B0BC(void) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { sEasyChatScreen->state = sub_811B2A4(); return 7; @@ -2536,7 +2536,7 @@ u8 sub_811BBBC(void) return sEasyChatScreen->unk_0c; } -static void sub_811BBC8(s8 *arg0, s8 *arg1) +void sub_811BBC8(u8 *arg0, u8 *arg1) { *arg0 = sEasyChatScreen->unk_10; *arg1 = sEasyChatScreen->unk_11; @@ -4528,18 +4528,18 @@ static void sub_811E30C(void) x = var0 * 13; x = x * 8 + 28; y = var1 * 16 + 96; - sub_811E34C((u8)x, (u8)y); + sub_811E34C(x, y); } static void sub_811E34C(u8 x, u8 y) { - if (!sUnknown_0203A11C->unk2E4) - return; - - sUnknown_0203A11C->unk2E4->pos1.x = (s16)x; - sUnknown_0203A11C->unk2E4->pos1.y = (s16)y; - sUnknown_0203A11C->unk2E4->pos2.x = 0; - sUnknown_0203A11C->unk2E4->data[0] = 0; + if (sUnknown_0203A11C->unk2E4) + { + sUnknown_0203A11C->unk2E4->pos1.x = x; + sUnknown_0203A11C->unk2E4->pos1.y = y; + sUnknown_0203A11C->unk2E4->pos2.x = 0; + sUnknown_0203A11C->unk2E4->data[0] = 0; + } } static void sub_811E380(void) diff --git a/src/ereader_screen.c b/src/ereader_screen.c index 3f2cf3217..b4a9164b3 100755 --- a/src/ereader_screen.c +++ b/src/ereader_screen.c @@ -137,7 +137,7 @@ static u32 sub_81D4EE4(u8 *arg0, u16 *arg1) { *arg0 = 1; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { *arg0 = 0; return 1; @@ -158,7 +158,7 @@ static u32 sub_81D4EE4(u8 *arg0, u16 *arg1) *arg1 = 0; *arg0 = 3; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { *arg0 = 0; return 1; @@ -288,7 +288,7 @@ static void sub_81D5084(u8 taskId) OpenEReaderLink(); data->unk8 = 6; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { sub_81D505C(&data->unk0); PlaySE(SE_SELECT); @@ -296,7 +296,7 @@ static void sub_81D5084(u8 taskId) } break; case 6: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -436,7 +436,7 @@ static void sub_81D5084(u8 taskId) } break; case 19: - if (IsFanfareTaskInactive() && (JOY_NEW(A_BUTTON | B_BUTTON))) + if (IsFanfareTaskInactive() && (gMain.newKeys & (A_BUTTON | B_BUTTON))) data->unk8 = 26; break; case 23: diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 68f873446..38a4b3240 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1235,7 +1235,7 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->range.as_nybbles.x = template->movementRangeX; objectEvent->range.as_nybbles.y = template->movementRangeY; objectEvent->trainerType = template->trainerType; - objectEvent->mapNum = mapNum; //redundant, but needed to match + objectEvent->mapNum = mapNum; objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId; objectEvent->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType]; SetObjectEventDirection(objectEvent, objectEvent->previousMovementDirection); @@ -8216,13 +8216,15 @@ bool8 FreezeObjectEvent(struct ObjectEvent *objectEvent) { return TRUE; } - - objectEvent->frozen = 1; - objectEvent->spriteAnimPausedBackup = gSprites[objectEvent->spriteId].animPaused; - objectEvent->spriteAffineAnimPausedBackup = gSprites[objectEvent->spriteId].affineAnimPaused; - gSprites[objectEvent->spriteId].animPaused = 1; - gSprites[objectEvent->spriteId].affineAnimPaused = 1; - return FALSE; + else + { + objectEvent->frozen = 1; + objectEvent->spriteAnimPausedBackup = gSprites[objectEvent->spriteId].animPaused; + objectEvent->spriteAffineAnimPausedBackup = gSprites[objectEvent->spriteId].affineAnimPaused; + gSprites[objectEvent->spriteId].animPaused = 1; + gSprites[objectEvent->spriteId].affineAnimPaused = 1; + return FALSE; + } } void FreezeObjectEvents(void) @@ -8395,8 +8397,8 @@ bool8 sub_80976EC(struct Sprite *sprite) if (sprite->data[5] > 15) return TRUE; - - return FALSE; + else + return FALSE; } static const s8 sFigure8XOffsets[FIGURE_8_LENGTH] = { @@ -8476,15 +8478,15 @@ static bool8 AnimateSpriteInFigure8(struct Sprite *sprite) return finished; } -static const s8 gUnknown_0850E802[16] = { +static const s8 gUnknown_0850E802[] = { -4, -6, -8, -10, -11, -12, -12, -12, -11, -10, -9, -8, -6, -4, 0, 0 }; -static const s8 gUnknown_0850E812[16] = { +static const s8 gUnknown_0850E812[] = { 0, -2, -3, -4, -5, -6, -6, -6, -5, -5, -4, -3, -2, 0, 0, 0 }; -static const s8 gUnknown_0850E822[16] = { +static const s8 gUnknown_0850E822[] = { -2, -4, -6, -8, -9, -10, -10, -10, -9, -8, -6, -5, -3, -2, 0, 0 }; @@ -8507,11 +8509,23 @@ void sub_809783C(struct Sprite *sprite, u8 a2, u8 a3, u8 a4) sprite->data[6] = 0; } +static const s16 gUnknown_0850E840[] = { + 16, 16, 32, +}; + +static const u8 gUnknown_0850E846[] = { + 0, 0, 1, +}; + u8 sub_809785C(struct Sprite *sprite) { - s16 v5[] = {16, 16, 32}; - u8 v6[] = {0, 0, 1}; - u8 v2 = 0; + s16 v5[3]; + u8 v6[3]; + u8 v2; + + memcpy(v5, gUnknown_0850E840, 6); // TODO: get rid of memcpy + memcpy(v6, gUnknown_0850E846, 3); + v2 = 0; if (sprite->data[4]) Step1(sprite, sprite->data[3]); @@ -8532,11 +8546,23 @@ u8 sub_809785C(struct Sprite *sprite) return v2; } +static const s16 gUnknown_0850E84A[] = { + 32, 32, 64, +}; + +static const u8 gUnknown_0850E850[] = { + 1, 1, 2, +}; + u8 sub_80978E4(struct Sprite *sprite) { - s16 v5[] = {32, 32, 64}; - u8 v6[] = {1, 1, 2}; - u8 v2 = 0; + s16 v5[3]; + u8 v6[3]; + u8 v2; + + memcpy(v5, gUnknown_0850E84A, 6); + memcpy(v6, gUnknown_0850E850, 3); + v2 = 0; if (sprite->data[4] && !(sprite->data[6] & 1)) Step1(sprite, sprite->data[3]); @@ -8564,9 +8590,12 @@ static void SetMovementDelay(struct Sprite *sprite, s16 timer) static bool8 WaitForMovementDelay(struct Sprite *sprite) { - if (--sprite->data[3] == 0) + sprite->data[3]--; + + if (sprite->data[3] == 0) return TRUE; - return FALSE; + else + return FALSE; } void SetAndStartSpriteAnim(struct Sprite *sprite, u8 animNum, u8 animCmdIndex) @@ -8580,7 +8609,8 @@ bool8 SpriteAnimEnded(struct Sprite *sprite) { if (sprite->animEnded) return TRUE; - return FALSE; + else + return FALSE; } void UpdateObjectEventSpriteVisibility(struct Sprite *sprite, bool8 invisible) @@ -8759,14 +8789,14 @@ static void UpdateObjectEventSpritePosition(struct Sprite *sprite) { switch(sprite->tAnimNum) { - case 0: - break; case UNION_ROOM_SPAWN_IN: MoveUnionRoomObjectDown(sprite); break; case UNION_ROOM_SPAWN_OUT: MoveUnionRoomObjectUp(sprite); break; + case 0: + break; default: sprite->tAnimNum = 0; break; @@ -8835,7 +8865,7 @@ u8 (*const gMovementActionFuncs_FlyDown[])(struct ObjectEvent *, struct Sprite * u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite) { - bool8 ableToStore = FALSE; + bool32 ableToStore = FALSE; if (gLockedAnimObjectEvents == NULL) { gLockedAnimObjectEvents = AllocZeroed(sizeof(struct LockedAnimObjectEvents)); @@ -8845,8 +8875,9 @@ u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct } else { - u8 i, firstFreeSlot; - bool8 found; + u8 i; + u8 firstFreeSlot; + bool32 found; for (firstFreeSlot = 16, found = FALSE, i = 0; i < 16; i++) { if (firstFreeSlot == 16 && gLockedAnimObjectEvents->objectEventIds[i] == 0) @@ -8879,7 +8910,7 @@ u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct u8 MovementAction_FreeAndUnlockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite) { - bool8 ableToStore; + bool32 ableToStore; u8 index; sprite->data[2] = 1; @@ -8923,7 +8954,7 @@ void CreateLevitateMovementTask(struct ObjectEvent *objectEvent) u8 taskId = CreateTask(ApplyLevitateMovement, 0xFF); struct Task *task = &gTasks[taskId]; - StoreWordInTwoHalfwords((u16 *)&task->data[0], (u32)objectEvent); + StoreWordInTwoHalfwords(&task->data[0], (u32)objectEvent); objectEvent->warpArrowSpriteId = taskId; task->data[3] = 0xFFFF; } @@ -8934,7 +8965,7 @@ static void ApplyLevitateMovement(u8 taskId) struct Sprite *sprite; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // load the map object pointer. + LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // load the map object pointer. sprite = &gSprites[objectEvent->spriteId]; if(!(task->data[2] & 0x3)) @@ -8951,7 +8982,7 @@ void DestroyExtraMovementTask(u8 taskId) struct ObjectEvent *objectEvent; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // unused objectEvent + LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // unused objectEvent DestroyTask(taskId); } diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 22376a478..47074cf26 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -858,21 +858,21 @@ static void Task_EvolutionScene(u8 taskID) } break; case 4: - if (JOY_NEW(DPAD_UP) && sEvoCursorPos != 0) + if (gMain.newKeys & DPAD_UP && sEvoCursorPos != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(sEvoCursorPos); sEvoCursorPos = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && sEvoCursorPos == 0) + if (gMain.newKeys & DPAD_DOWN && sEvoCursorPos == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(sEvoCursorPos); sEvoCursorPos = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); @@ -888,7 +888,7 @@ static void Task_EvolutionScene(u8 taskID) BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); diff --git a/src/faraway_island.c b/src/faraway_island.c index 6bfa066c2..e3d8444c9 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -181,36 +181,40 @@ u32 GetMewMoveDirection(void) { if (ShouldMewMoveEast(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveWest(mew, 1)) + else if (ShouldMewMoveWest(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_NORTH; + else + return DIR_NORTH; } if (ShouldMewMoveSouth(mew, 0)) { if (ShouldMewMoveEast(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveWest(mew, 1)) + else if (ShouldMewMoveWest(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_SOUTH; + else + return DIR_SOUTH; } if (ShouldMewMoveEast(mew, 0)) { if (ShouldMewMoveNorth(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveSouth(mew, 1)) + else if (ShouldMewMoveSouth(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_EAST; + else + return DIR_EAST; } if (ShouldMewMoveWest(mew, 0)) { if (ShouldMewMoveNorth(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveSouth(mew, 1)) + else if (ShouldMewMoveSouth(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_WEST; + else + return DIR_WEST; } // If this point is reached, Mew cannot move without getting closer to the player @@ -311,7 +315,8 @@ static u8 GetValidMewMoveDirection(u8 ignoredDir) if (count > 1) return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count]; - return sMewDirectionCandidates[0]; + else + return sMewDirectionCandidates[0]; } void UpdateFarawayIslandStepCounter(void) diff --git a/src/field_effect.c b/src/field_effect.c index b64902c0e..41f1a899c 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -2597,7 +2597,7 @@ static void FieldMoveShowMonOutdoorsEffect_Init(struct Task *task) { task->data[11] = REG_WININ; task->data[12] = REG_WINOUT; - StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); + StoreWordInTwoHalfwords(&task->data[13], (u32)gMain.vblankCallback); task->tWinHoriz = WIN_RANGE(DISPLAY_WIDTH, DISPLAY_WIDTH + 1); task->tWinVert = WIN_RANGE(DISPLAY_HEIGHT / 2, DISPLAY_HEIGHT / 2 + 1); task->tWinIn = WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR; diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index f8c4e79f1..194f110d8 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -1788,7 +1788,7 @@ static bool8 Fishing_ShowDots(struct Task *task) AlignFishingAnimationFrames(); task->tFrameCounter++; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { task->tStep = FISHING_NO_BITE; if (task->tRoundsPlayed != 0) @@ -1877,7 +1877,7 @@ static bool8 Fishing_WaitForA(struct Task *task) task->tFrameCounter++; if (task->tFrameCounter >= reelTimeouts[task->tFishingRod]) task->tStep = FISHING_GOT_AWAY; - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) task->tStep++; return FALSE; } diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 6b41c5423..bd6c833af 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -280,7 +280,7 @@ void Task_HandlePorthole(u8 taskId) } break; case IDLE_CHECK: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) data[1] = 1; if (!ScriptMovement_IsObjectMovementFinished(OBJ_EVENT_ID_PLAYER, location->mapNum, location->mapGroup)) return; diff --git a/src/fldeff_cut.c b/src/fldeff_cut.c index 991617713..785f7b426 100644 --- a/src/fldeff_cut.c +++ b/src/fldeff_cut.c @@ -227,7 +227,9 @@ bool8 SetUpFieldMove_Cut(void) y = gPlayerFacingPosition.y + sHyperCutStruct[i].y; tileCuttable = TRUE; - for (j = 0; j < 2; ++j) { + j = 0; + do + { if (sHyperCutStruct[i].unk2[j] == 0) break; if (cutTiles[(u8)(sHyperCutStruct[i].unk2[j] - 1)] == FALSE) @@ -235,7 +237,7 @@ bool8 SetUpFieldMove_Cut(void) tileCuttable = FALSE; break; } - } + } while (++j <= 1); if (tileCuttable == TRUE) { @@ -251,8 +253,11 @@ bool8 SetUpFieldMove_Cut(void) sHyperCutTiles[tileArrayId] = TRUE; ret = TRUE; } - else if (MetatileBehavior_IsCuttableGrass(tileBehavior) == TRUE) - sHyperCutTiles[tileArrayId] = TRUE; + else + { + if (MetatileBehavior_IsCuttableGrass(tileBehavior) == TRUE) + sHyperCutTiles[tileArrayId] = TRUE; + } } } } diff --git a/src/frontier_pass.c b/src/frontier_pass.c index ac81c51e0..dfd5c0f2d 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -937,14 +937,14 @@ static void Task_HandleFrontierPassInput(u8 taskId) { u8 var = FALSE; // Reused, first informs whether the cursor moves, then used as the new cursor area. - if (JOY_HELD(DPAD_UP) && sPassGfx->cursorSprite->pos1.y >= 9) + if (gMain.heldKeys & DPAD_UP && sPassGfx->cursorSprite->pos1.y >= 9) { sPassGfx->cursorSprite->pos1.y -= 2; if (sPassGfx->cursorSprite->pos1.y <= 7) sPassGfx->cursorSprite->pos1.y = 2; var = TRUE; } - if (JOY_HELD(DPAD_DOWN) && sPassGfx->cursorSprite->pos1.y <= 135) + if (gMain.heldKeys & DPAD_DOWN && sPassGfx->cursorSprite->pos1.y <= 135) { sPassGfx->cursorSprite->pos1.y += 2; if (sPassGfx->cursorSprite->pos1.y >= 137) @@ -952,14 +952,14 @@ static void Task_HandleFrontierPassInput(u8 taskId) var = TRUE; } - if (JOY_HELD(DPAD_LEFT) && sPassGfx->cursorSprite->pos1.x >= 6) + if (gMain.heldKeys & DPAD_LEFT && sPassGfx->cursorSprite->pos1.x >= 6) { sPassGfx->cursorSprite->pos1.x -= 2; if (sPassGfx->cursorSprite->pos1.x <= 4) sPassGfx->cursorSprite->pos1.x = 5; var = TRUE; } - if (JOY_HELD(DPAD_RIGHT) && sPassGfx->cursorSprite->pos1.x <= 231) + if (gMain.heldKeys & DPAD_RIGHT && sPassGfx->cursorSprite->pos1.x <= 231) { sPassGfx->cursorSprite->pos1.x += 2; if (sPassGfx->cursorSprite->pos1.x >= 233) @@ -969,7 +969,7 @@ static void Task_HandleFrontierPassInput(u8 taskId) if (!var) // Cursor did not change. { - if (sPassData->cursorArea != CURSOR_AREA_NOTHING && JOY_NEW(A_BUTTON)) + if (sPassData->cursorArea != CURSOR_AREA_NOTHING && gMain.newKeys & A_BUTTON) { if (sPassData->cursorArea <= CURSOR_AREA_RECORD) // Map, Card, Record { @@ -986,7 +986,7 @@ static void Task_HandleFrontierPassInput(u8 taskId) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); SetMainCallback2(CB2_HideFrontierPass); @@ -1195,7 +1195,7 @@ static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) return; break; } - + switch (cursorArea) { case CURSOR_AREA_MAP: @@ -1209,7 +1209,7 @@ static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); else return; - break; // needed + break; //needed to match case CURSOR_AREA_CANCEL: CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); break; @@ -1443,19 +1443,19 @@ static void Task_HandleFrontierMap(u8 taskId) break; return; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); data[0] = 4; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (sMapData->cursorPos >= NUM_FRONTIER_FACILITIES - 1) HandleFrontierMapCursorMove(0); else data[0] = 2; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (sMapData->cursorPos == 0) HandleFrontierMapCursorMove(1); diff --git a/src/frontier_util.c b/src/frontier_util.c index d0dfa61f3..83c9341d5 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2507,11 +2507,12 @@ void CreateFrontierBrainPokemon(void) { if (!(selectedMonBits & 1)) continue; + do { do { - j = Random32(); //Should be one while loop, but that doesn't match + j = Random32(); //should just be one while loop, but that doesn't match } while (IsShinyOtIdPersonality(FRONTIER_BRAIN_OTID, j)); } while (sFrontierBrainsMons[facility][symbol][i].nature != GetNatureFromPersonality(j)); CreateMon(&gEnemyParty[monPartyId], diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index 7b63950d1..1cfa794ae 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -729,7 +729,7 @@ static void Task_Hof_WaitAndPrintPlayerInfo(u8 taskId) static void Task_Hof_ExitOnKeyPressed(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FadeOutBGM(4); gTasks[taskId].func = Task_Hof_HandlePaletteOnExit; @@ -991,7 +991,7 @@ static void Task_HofPC_HandleInput(u8 taskId) { u16 i; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].tCurrTeamNo != 0) // prepare another team to view { @@ -1019,7 +1019,7 @@ static void Task_HofPC_HandleInput(u8 taskId) gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } } - else if (JOY_NEW(B_BUTTON)) // turn off hall of fame PC + else if (gMain.newKeys & B_BUTTON) // turn off hall of fame PC { if (IsCryPlayingOrClearCrySongs()) { @@ -1028,12 +1028,12 @@ static void Task_HofPC_HandleInput(u8 taskId) } gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } - else if (JOY_NEW(DPAD_UP) && gTasks[taskId].tCurrMonId != 0) // change mon -1 + else if (gMain.newKeys & DPAD_UP && gTasks[taskId].tCurrMonId != 0) // change mon -1 { gTasks[taskId].tCurrMonId--; gTasks[taskId].func = Task_HofPC_PrintMonInfo; } - else if (JOY_NEW(DPAD_DOWN) && gTasks[taskId].tCurrMonId < gTasks[taskId].tMonNo - 1) // change mon +1 + else if (gMain.newKeys & DPAD_DOWN && gTasks[taskId].tCurrMonId < gTasks[taskId].tMonNo - 1) // change mon +1 { gTasks[taskId].tCurrMonId++; gTasks[taskId].func = Task_HofPC_PrintMonInfo; @@ -1097,7 +1097,7 @@ static void Task_HofPC_PrintDataIsCorrupted(u8 taskId) static void Task_HofPC_ExitOnButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } diff --git a/src/intro_credits_graphics.c b/src/intro_credits_graphics.c index 45cc24e5c..04e2216f6 100644 --- a/src/intro_credits_graphics.c +++ b/src/intro_credits_graphics.c @@ -824,7 +824,7 @@ void sub_817B1C8(u8 a) LZ77UnCompVram(gUnknown_085F1398, (void *)(BG_SCREEN_ADDR(6))); LoadPalette(&gUnknown_085F0CFC, 0, 96); LoadCompressedSpriteSheet(gUnknown_085F5064); - LZ77UnCompVram(gUnknown_085F16A8, (void *)(OBJ_VRAM0)); + LZ77UnCompVram(gUnknown_085F16A8, (void *)(VRAM + 0x10000)); LoadPalette(&gUnknown_085F1668, 256, 32); sub_817B76C(); break; @@ -834,7 +834,7 @@ void sub_817B1C8(u8 a) LZ77UnCompVram(gUnknown_085F1398, (void *)(BG_SCREEN_ADDR(6))); LoadPalette(&gUnknown_085F0D5C, 0, 96); LoadCompressedSpriteSheet(gUnknown_085F5064); - LZ77UnCompVram(gUnknown_085F16A8, (void *)(OBJ_VRAM0)); + LZ77UnCompVram(gUnknown_085F16A8, (void *)(VRAM + 0x10000)); LoadPalette(&gUnknown_085F1688, 256, 32); sub_817B76C(); break; diff --git a/src/item.c b/src/item.c index 290e7177c..0b6366048 100644 --- a/src/item.c +++ b/src/item.c @@ -183,13 +183,15 @@ bool8 HasAtLeastOneBerry(void) bool8 CheckBagHasSpace(u16 itemId, u16 count) { - u8 i, pocket; - u16 slotCapacity, ownedCount; + u8 i; + u8 pocket; + u16 slotCapacity; + u16 ownedCount; if (ItemId_GetPocket(itemId) == POCKET_NONE) return FALSE; - if (InBattlePyramid() || (FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE)) + if (InBattlePyramid() || FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE) { return CheckPyramidBagHasSpace(itemId, count); } @@ -212,12 +214,12 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count) return FALSE; count -= (slotCapacity - ownedCount); if (count == 0) - break; //Should just be "return TRUE", since setting count to 0 means all the remaining checks until return will be false anyway, but that doesn't match + break; //should be return TRUE, but that doesn't match } } // Check space in empty item slots - if (count > 0) //if (count !=0) also works here; both match + if (count > 0) { for (i = 0; i < gBagPockets[pocket].capacity; i++) { @@ -231,12 +233,12 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count) } else { - count = 0; //Should just be "return TRUE", since setting count to 0 means all the remaining checks until return will be false anyway, but that doesn't match + count = 0; //should be return TRUE, but that doesn't match break; } } } - if (count > 0) //if (count !=0) also works here; both match + if (count > 0) return FALSE; // No more item slots. The bag is full } diff --git a/src/item_menu.c b/src/item_menu.c index d5e50fc2d..394bd1058 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -628,6 +628,7 @@ void CB2_Bag(void) bool8 SetupBagMenu(void) { + u32 index; u8 taskId; switch (gMain.state) @@ -1166,7 +1167,7 @@ void Task_BagMenu_HandleInput(u8 taskId) SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, 0); return; default: - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { if (CanSwapItems() == TRUE) { @@ -1228,12 +1229,12 @@ static u8 GetSwitchBagPocketDirection(void) if (gBagMenu->pocketSwitchDisabled) return SWITCH_POCKET_NONE; LRKeys = GetLRKeysPressed(); - if (JOY_NEW(DPAD_LEFT) || LRKeys == MENU_L_PRESSED) + if ((gMain.newKeys & DPAD_LEFT) || LRKeys == MENU_L_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_LEFT; } - if (JOY_NEW(DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) + if ((gMain.newKeys & DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_RIGHT; @@ -1387,7 +1388,7 @@ static void Task_HandleSwappingItemsInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); @@ -1405,7 +1406,7 @@ static void Task_HandleSwappingItemsInput(u8 taskId) break; case LIST_CANCEL: PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) sub_81AC498(taskId); else sub_81AC590(taskId); @@ -1644,7 +1645,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { s8 cursorPos = Menu_GetCursorPos(); - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (cursorPos > 0 && sub_81ACDFC(cursorPos - 2)) { @@ -1652,7 +1653,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (cursorPos < (gBagMenu->contextMenuNumItems - 2) && sub_81ACDFC(cursorPos + 2)) { @@ -1660,7 +1661,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); } } - else if ((JOY_NEW(DPAD_LEFT)) || GetLRKeysPressed() == MENU_L_PRESSED) + else if ((gMain.newKeys & DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) { if ((cursorPos & 1) && sub_81ACDFC(cursorPos - 1)) { @@ -1668,7 +1669,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if ((gMain.newKeys & DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) { if (!(cursorPos & 1) && sub_81ACDFC(cursorPos + 1)) { @@ -1676,12 +1677,12 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sItemMenuActions[gBagMenu->contextMenuItemsPtr[cursorPos]].func.void_u8(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sItemMenuActions[ITEMMENUACTION_CANCEL].func.void_u8(taskId); @@ -1785,13 +1786,13 @@ void Task_ChooseHowManyToToss(u8 taskId) { PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); BagMenu_TossItems(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); @@ -1817,7 +1818,7 @@ void Task_ActuallyToss(u8 taskId) u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveBagItem(gSpecialVar_ItemId, tItemCount); @@ -1885,7 +1886,7 @@ static void BagMenu_PrintItemCantBeHeld(u8 taskId) void sub_81AD350(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_InitListsMenu(taskId); @@ -2059,13 +2060,13 @@ static void Task_SellHowManyDialogueHandleInput(u8 taskId) { PrintItemSoldAmount(gBagMenu->windowPointers[8], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(8); DisplaySellItemPriceAndConfirm(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_PrintCursor_(data[0], 0); @@ -2107,7 +2108,7 @@ static void BagMenu_Sell_UpdateItemListAndMoney(u8 taskId) static void BagMenu_Sell_WaitForABPress(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveMoneyWindow(); @@ -2143,13 +2144,13 @@ static void Task_ChooseHowManyToDeposit(u8 taskId) { PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); BagMenu_TryDepositItem(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_PrintDescription(data[1]); @@ -2188,7 +2189,7 @@ static void BagMenu_Deposit_WaitForABPress(u8 taskId) { s16* data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BagMenu_PrintDescription(data[1]); diff --git a/src/item_use.c b/src/item_use.c index f9d1ff824..b1b90f3d5 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -721,7 +721,7 @@ static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId) static bool8 TryToWaterSudowoodo(void) { - s16 x, y; + u16 x, y; u8 z; u8 objId; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); @@ -792,7 +792,7 @@ static void BootUpSoundTMHM(u8 taskId) static void Task_ShowTMHMContainedMessage(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { StringCopy(gStringVar1, gMoveNames[ItemIdToBattleMoveId(gSpecialVar_ItemId)]); StringExpandPlaceholders(gStringVar4, gText_TMHMContainedVar1); @@ -956,7 +956,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) static void Task_CloseStatIncreaseMessage(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { if (!InBattlePyramid()) Task_FadeAndCloseBagMenu(taskId); diff --git a/src/link.c b/src/link.c index 9fd35a10b..cdaf58469 100644 --- a/src/link.c +++ b/src/link.c @@ -445,27 +445,27 @@ static void TestBlockTransfer(u8 nothing, u8 is, u8 used) static void LinkTestProcessKeyInput(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gShouldAdvanceLinkState = 1; } - if (JOY_HELD(B_BUTTON)) + if (gMain.heldKeys & B_BUTTON) { InitBlockSend(gHeap + 0x4000, 0x00002004); } - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB(2, 0, 0)); } - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) { SetSuppressLinkErrorMessage(TRUE); } - if (JOY_NEW(R_BUTTON)) + if (gMain.newKeys & R_BUTTON) { TrySavingData(SAVE_LINK); } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { SetCloseLinkCallback(); } @@ -1754,7 +1754,7 @@ static void CB2_PrintErrorMessage(void) { if (gWirelessCommType == 1) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_PIN); gWirelessCommType = 0; @@ -1764,7 +1764,7 @@ static void CB2_PrintErrorMessage(void) } else if (gWirelessCommType == 2) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { rfu_REQ_stopMode(); rfu_waitREQComplete(); diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 3db24aaec..5e0ef0aa4 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -875,7 +875,8 @@ static void sub_800F498(u16 *a0, u8 *a1) static bool32 RfuProcessEnqueuedRecvBlock(void) { - u8 i, j; + u8 i; + u8 j; u8 sp00[MAX_RFU_PLAYERS * (2 * (CMD_LENGTH - 1))]; u8 sp48[2 * (CMD_LENGTH - 1)]; u8 status; @@ -932,14 +933,13 @@ static void HandleSendFailure(u8 unused, u32 flags) for (j = 0; j < 7; j++) { temp = j << 1; - sResendBlock16[j + 1] = (r10[i * 12 + temp + 1] << 8) | r10[i * 12 + temp]; + sResendBlock16[j + 1] = (r10[12 * i + temp + 1] << 8) | r10[12 * i + temp + 0]; } - for (j = 0; j < 7; j++) { temp = j << 1; sResendBlock8[temp + 1] = sResendBlock16[j] >> 8; - sResendBlock8[temp + 0] = sResendBlock16[j] & 0xff; + sResendBlock8[temp + 0] = sResendBlock16[j]; } RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); Rfu.sendBlock.failedFlags |= (1 << i); @@ -1023,7 +1023,8 @@ void Rfu_SetBerryBlenderLinkCallback(void) static void RfuHandleReceiveCommand(u8 unused) { - u16 i, j; + u16 i; + u16 j; for (i = 0; i < MAX_RFU_PLAYERS; i++) { @@ -1037,7 +1038,7 @@ static void RfuHandleReceiveCommand(u8 unused) if (gRfuLinkStatus->parentChild == MODE_CHILD) { Rfu.playerCount = gRecvCmds[i][1]; - Rfu.multiplayerId = sub_800F74C((u8 *)(&gRecvCmds[i][2])); + Rfu.multiplayerId = sub_800F74C((u8 *)(gRecvCmds[i] + 2)); } break; case RFUCMD_0x8800: @@ -1236,9 +1237,10 @@ void Rfu_SendPacket(void *data) bool32 Rfu_InitBlockSend(const u8 *src, size_t size) { bool8 r4; - if (Rfu.callback != NULL || gSendCmd[0] != 0) + if (Rfu.callback != NULL) + return FALSE; + if (gSendCmd[0] != 0) return FALSE; - if (Rfu.sendBlock.sending) { sRfuDebug.unk_83++; @@ -1416,12 +1418,16 @@ void Rfu_SetCloseLinkCallback(void) static void SendReadyExitStandbyUntilAllReady(void) { - u8 i, playerCount; + u8 playerCount; + u8 i; - if (GetMultiplayerId() != 0 && Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) + if (GetMultiplayerId() != 0) { - RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.resendExitStandbyTimer = 0; + if (Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) + { + RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); + Rfu.resendExitStandbyTimer = 0; + } } playerCount = GetLinkPlayerCount(); for (i = 0; i < playerCount; i++) @@ -1451,7 +1457,8 @@ static void LinkLeaderReadyToExitStandby(void) // RFU equivalent of LinkCB_Standby and LinkCB_StandbyForAll static void Rfu_LinkStandby(void) { - u8 i, playerCount; + u8 i; + u8 playerCount; if (GetMultiplayerId() != 0) { @@ -1547,28 +1554,28 @@ static bool8 CheckForLeavingGroupMembers(void) bool8 memberLeft = FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.partnerSendStatuses[i] == RFU_STATUS_JOIN_GROUP_OK - || Rfu.partnerSendStatuses[i] == RFU_STATUS_JOIN_GROUP_NO) + if (Rfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK + || Rfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO) { - continue; - } - - if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS - || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) - { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) + if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS + || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { - Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; - Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) + { + Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; + Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; + rfu_clearSlot(TYPE_NI_RECV, i); + rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); + memberLeft = TRUE; + } + + } + else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) rfu_clearSlot(TYPE_NI_RECV, i); - rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); - memberLeft = TRUE; + { + } } - else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) - { - rfu_clearSlot(TYPE_NI_RECV, i); - } } return memberLeft; } @@ -2043,7 +2050,8 @@ void sub_80110B8(u32 a0) if ((r8 >> i) & 1) { child_sprite_genders |= ((0x80 | ((gLinkPlayers[Rfu.linkPlayerIdx[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.linkPlayerIdx[i]].trainerId & 7)) << (numConnectedChildren << 3)); - if (++numConnectedChildren == a0 - 1) + numConnectedChildren++; + if (numConnectedChildren == a0 - 1) break; } } @@ -2088,7 +2096,8 @@ static void sub_80111FC(void) static void sub_801120C(u8 msg, u8 paramCount) { - u8 i, disconnectFlag = 0; + u8 i; + u8 disconnectFlag = 0; switch (msg) { case LMAN_MSG_INITIALIZE_COMPLETED: diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index 821b2d118..c6344f503 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -309,7 +309,8 @@ static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < RECV_QUEUE_NUM_SLOTS; i++) { @@ -326,7 +327,8 @@ void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) void RfuSendQueue_Reset(struct RfuSendQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < SEND_QUEUE_NUM_SLOTS; i++) { @@ -343,7 +345,8 @@ void RfuSendQueue_Reset(struct RfuSendQueue *queue) static void RfuUnusedQueue_Reset(struct RfuUnusedQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < UNUSED_QUEUE_NUM_SLOTS; i++) { @@ -623,32 +626,30 @@ static void ASCIIToPkmnStr(u8 *pkmnStr, const u8 *asciiStr) static u8 GetConnectedChildStrength(u8 maxFlags) { u8 flagCount = 0; - u8 flags = gRfuLinkStatus->connSlotFlag; + u32 flags = gRfuLinkStatus->connSlotFlag; u8 i; if (gRfuLinkStatus->parentChild == MODE_PARENT) { - for (i = 0; i < RFU_CHILD_MAX; i++) + for (i = 0; i < 4; flags >>= 1, i++) { if (flags & 1) { if (maxFlags == flagCount + 1) { return gRfuLinkStatus->strength[i]; - break; // This break is needed to match + break; } flagCount++; } - flags >>= 1; } } else { - for (i = 0; i < 4; i++) + for (i = 0; i < 4; flags >>= 1, i++) { if (flags & 1) return gRfuLinkStatus->strength[i]; - flags >>= 1; } } return 0; @@ -922,7 +923,8 @@ void RecordMixTrainerNames(void) { if (gWirelessCommType != 0) { - s32 i, j; + s32 i; + s32 j; s32 nextSpace; s32 connectedTrainerRecordIndices[5]; struct TrainerNameRecord *newRecords = calloc(ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords), sizeof(struct TrainerNameRecord)); diff --git a/src/list_menu.c b/src/list_menu.c index 7784dd338..e3c4e11d2 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -312,7 +312,7 @@ static void ListMenuDummyTask(u8 taskId) } -u32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum) +s32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum) { switch (sMysteryGiftLinkMenu.state) { @@ -335,11 +335,11 @@ u32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const str break; case 1: sMysteryGiftLinkMenu.currItemId = ListMenu_ProcessInput(sMysteryGiftLinkMenu.listTaskId); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sMysteryGiftLinkMenu.state = 2; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { sMysteryGiftLinkMenu.currItemId = LIST_CANCEL; sMysteryGiftLinkMenu.state = 2; @@ -410,20 +410,20 @@ s32 ListMenu_ProcessInput(u8 listTaskId) { struct ListMenu *list = (void*) gTasks[listTaskId].data; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { return list->template.items[list->scrollOffset + list->selectedRow].id; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return LIST_CANCEL; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { ListMenuChangeSelection(list, TRUE, 1, FALSE); return LIST_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { ListMenuChangeSelection(list, TRUE, 1, TRUE); return LIST_NOTHING_CHOSEN; @@ -439,12 +439,12 @@ s32 ListMenu_ProcessInput(u8 listTaskId) rightButton = FALSE; break; case LIST_MULTIPLE_SCROLL_DPAD: - leftButton = JOY_REPEAT(DPAD_LEFT); - rightButton = JOY_REPEAT(DPAD_RIGHT); + leftButton = gMain.newAndRepeatedKeys & DPAD_LEFT; + rightButton = gMain.newAndRepeatedKeys & DPAD_RIGHT; break; case LIST_MULTIPLE_SCROLL_L_R: - leftButton = JOY_REPEAT(L_BUTTON); - rightButton = JOY_REPEAT(R_BUTTON); + leftButton = gMain.newAndRepeatedKeys & L_BUTTON; + rightButton = gMain.newAndRepeatedKeys & R_BUTTON; break; } @@ -1257,17 +1257,17 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st s32 i, j, id = 0; subsprites[id] = sSubsprite_RedOutline1; - subsprites[id].x = -120; - subsprites[id].y = -120; + subsprites[id].x = 136; + subsprites[id].y = 136; id++; subsprites[id] = sSubsprite_RedOutline2; subsprites[id].x = rowWidth + 128; - subsprites[id].y = -120; + subsprites[id].y = 136; id++; subsprites[id] = sSubsprite_RedOutline7; - subsprites[id].x = -120; + subsprites[id].x = 136; subsprites[id].y = rowHeight + 128; id++; @@ -1297,7 +1297,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st for (j = 8; j < rowHeight - 8; j += 8) { subsprites[id] = sSubsprite_RedOutline4; - subsprites[id].x = -120; + subsprites[id].x = 136; subsprites[id].y = j - 120; id++; @@ -22,7 +22,8 @@ u8 gMPlayMemAccArea[0x10]; u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust) { - u32 val1, val2; + u32 val1; + u32 val2; u32 fineAdjustShifted = fineAdjust << 24; if (key > 178) @@ -314,7 +315,7 @@ void MPlayExtender(struct CgbChannel *cgbChans) void MusicPlayerJumpTableCopy(void) { - asm("svc 0x2A"); + asm("swi 0x2A"); } void ClearChain(void *x) @@ -351,25 +352,25 @@ void SoundInit(struct SoundInfo *soundInfo) | SOUND_ALL_MIX_FULL; REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40; - REG_DMA1SAD = (u32)soundInfo->pcmBuffer; - REG_DMA1DAD = (u32)®_FIFO_A; - REG_DMA2SAD = (u32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; - REG_DMA2DAD = (u32)®_FIFO_B; + REG_DMA1SAD = (s32)soundInfo->pcmBuffer; + REG_DMA1DAD = (s32)®_FIFO_A; + REG_DMA2SAD = (s32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; + REG_DMA2DAD = (s32)®_FIFO_B; SOUND_INFO_PTR = soundInfo; CpuFill32(0, soundInfo, sizeof(struct SoundInfo)); soundInfo->maxChans = 8; soundInfo->masterVolume = 15; - soundInfo->plynote = ply_note; + soundInfo->plynote = (u32)ply_note; soundInfo->CgbSound = DummyFunc; soundInfo->CgbOscOff = (void (*)(u8))DummyFunc; soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc; - soundInfo->ExtVolPit = (void (*)(struct MusicPlayerInfo *, struct MusicPlayerTrack *))DummyFunc; + soundInfo->ExtVolPit = (u32)DummyFunc; MPlayJumpTableCopy(gMPlayJumpTable); - soundInfo->MPlayJumpTable = (void (**)())gMPlayJumpTable; + soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable; SampleFreqSet(SOUND_MODE_FREQ_13379); @@ -380,7 +381,7 @@ void SampleFreqSet(u32 freq) { struct SoundInfo *soundInfo = SOUND_INFO_PTR; - freq = (freq & SOUND_MODE_FREQ) >> SOUND_MODE_FREQ_SHIFT; + freq = (freq & 0xF0000) >> 16; soundInfo->freq = freq; soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1]; soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank; @@ -431,9 +432,14 @@ void m4aSoundMode(u32 mode) soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT; - for (temp = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; temp != 0; temp--,chan++) + temp = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (temp != 0) { chan->status = 0; + temp--; + chan++; } } @@ -463,28 +469,37 @@ void m4aSoundMode(u32 mode) void SoundClear(void) { - s32 i; struct SoundInfo *soundInfo = SOUND_INFO_PTR; - struct SoundChannel *chan; + s32 i; + void *chan; if (soundInfo->ident != ID_NUMBER) return; soundInfo->ident++; - for (i = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; i > 0; i--,chan++) + i = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (i > 0) { - chan->status = 0; + ((struct SoundChannel *)chan)->status = 0; + i--; + chan = (void *)((s32)chan + sizeof(struct SoundChannel)); } - chan = (struct SoundChannel *)soundInfo->cgbChans; + chan = soundInfo->cgbChans; if (chan) { - for (i=1; i<=4; i++,chan++) + i = 1; + + while (i <= 4) { soundInfo->CgbOscOff(i); - chan->status = 0; + ((struct CgbChannel *)chan)->sf = 0; + i++; + chan = (void *)((s32)chan + sizeof(struct CgbChannel)); } } @@ -495,20 +510,21 @@ void m4aSoundVSyncOff(void) { struct SoundInfo *soundInfo = SOUND_INFO_PTR; - if (soundInfo->ident < ID_NUMBER || soundInfo->ident > ID_NUMBER + 1) - return; - soundInfo->ident += 10; + if (soundInfo->ident >= ID_NUMBER && soundInfo->ident <= ID_NUMBER + 1) + { + soundInfo->ident += 10; - if (REG_DMA1CNT & (DMA_REPEAT << 16)) - REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + if (REG_DMA1CNT & (DMA_REPEAT << 16)) + REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - if (REG_DMA2CNT & (DMA_REPEAT << 16)) - REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + if (REG_DMA2CNT & (DMA_REPEAT << 16)) + REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - REG_DMA1CNT_H = DMA_32BIT; - REG_DMA2CNT_H = DMA_32BIT; + REG_DMA1CNT_H = DMA_32BIT; + REG_DMA2CNT_H = DMA_32BIT; - CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); + CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); + } } void m4aSoundVSyncOn(void) @@ -564,7 +580,7 @@ void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track } soundInfo->intp = (u32)mplayInfo; - soundInfo->func = MPlayMain; + soundInfo->func = (u32)MPlayMain; soundInfo->ident = ID_NUMBER; mplayInfo->ident = ID_NUMBER; } @@ -598,21 +614,28 @@ void MPlayStart(struct MusicPlayerInfo *mplayInfo, struct SongHeader *songHeader mplayInfo->tempoC = 0; mplayInfo->fadeOI = 0; - for (i = 0, track = mplayInfo->tracks; i < songHeader->trackCount && i < mplayInfo->trackCount; i++, track++) + i = 0; + track = mplayInfo->tracks; + + while (i < songHeader->trackCount && i < mplayInfo->trackCount) { TrackStop(mplayInfo, track); track->flags = MPT_FLG_EXIST | MPT_FLG_START; track->chan = 0; track->cmdPtr = songHeader->part[i]; + i++; + track++; } - for (; i < mplayInfo->trackCount; i++, track++) + while (i < mplayInfo->trackCount) { TrackStop(mplayInfo, track); track->flags = 0; + i++; + track++; } - if (songHeader->reverb & SOUND_MODE_REVERB_SET) + if (songHeader->reverb & 0x80) m4aSoundMode(songHeader->reverb); mplayInfo->ident = ID_NUMBER; @@ -630,9 +653,14 @@ void m4aMPlayStop(struct MusicPlayerInfo *mplayInfo) mplayInfo->ident++; mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { TrackStop(mplayInfo, track); + i--; + track++; } mplayInfo->ident = ID_NUMBER; @@ -663,7 +691,10 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) { if ((s16)(mplayInfo->fadeOV -= (4 << FADE_VOL_SHIFT)) <= 0) { - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { u32 val; @@ -675,6 +706,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) if (!val) track->flags = 0; + + i--; + track++; } if (mplayInfo->fadeOV & TEMPORARY_FADE) @@ -687,7 +721,10 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) } } - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { if (track->flags & MPT_FLG_EXIST) { @@ -696,6 +733,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) track->volX = (fadeOV >> FADE_VOL_SHIFT); track->flags |= MPT_FLG_VOLCHG; } + + i--; + track++; } } @@ -703,7 +743,7 @@ void TrkVolPitSet(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tr { if (track->flags & MPT_FLG_VOLSET) { - u32 x; + s32 x; s32 y; x = (u32)(track->vol * track->volX) >> 5; diff --git a/src/m4a_1.s b/src/m4a_1.s index 290404ad0..cab4ed174 100644 --- a/src/m4a_1.s +++ b/src/m4a_1.s @@ -22,13 +22,13 @@ SoundMain: ldr r0, lt_SOUND_INFO_PTR ldr r0, [r0] ldr r2, lt_ID_NUMBER - ldr r3, [r0, #o_SoundInfo_ident] + ldr r3, [r0, o_SoundInfo_ident] cmp r2, r3 beq SoundMain_1 bx lr @ Exit the function if ident doesn't match ID_NUMBER. SoundMain_1: adds r3, 1 - str r3, [r0, #o_SoundInfo_ident] + str r3, [r0, o_SoundInfo_ident] push {r4-r7,lr} mov r1, r8 mov r2, r9 @@ -36,7 +36,7 @@ SoundMain_1: mov r4, r11 push {r0-r4} sub sp, 0x18 - ldrb r1, [r0, #o_SoundInfo_maxLines] + ldrb r1, [r0, o_SoundInfo_maxLines] cmp r1, 0 @ if maxLines is 0, there is no maximum beq SoundMain_3 ldr r2, lt_REG_VCOUNT @@ -48,24 +48,24 @@ SoundMain_2: adds r1, r2 SoundMain_3: str r1, [sp, 0x14] - ldr r3, [r0, #o_SoundInfo_func] + ldr r3, [r0, o_SoundInfo_func] cmp r3, 0 beq SoundMain_4 - ldr r0, [r0, #o_SoundInfo_intp] + ldr r0, [r0, o_SoundInfo_intp] bl _081DD25E ldr r0, [sp, 0x18] SoundMain_4: - ldr r3, [r0, #o_SoundInfo_CgbSound] + ldr r3, [r0, o_SoundInfo_CgbSound] bl _081DD25E ldr r0, [sp, 0x18] - ldr r3, [r0, #o_SoundInfo_pcmSamplesPerVBlank] + ldr r3, [r0, o_SoundInfo_pcmSamplesPerVBlank] mov r8, r3 ldr r5, lt_o_SoundInfo_pcmBuffer adds r5, r0 - ldrb r4, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r4, [r0, o_SoundInfo_pcmDmaCounter] subs r7, r4, 1 bls SoundMain_5 - ldrb r1, [r0, #o_SoundInfo_pcmDmaPeriod] + ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] subs r1, r7 mov r2, r8 muls r2, r1 @@ -87,7 +87,7 @@ lt_PCM_DMA_BUF_SIZE: .word PCM_DMA_BUF_SIZE thumb_func_start SoundMainRAM SoundMainRAM: - ldrb r3, [r0, #o_SoundInfo_reverb] + ldrb r3, [r0, o_SoundInfo_reverb] cmp r3, 0 beq SoundMainRAM_NoReverb adr r1, SoundMainRAM_Reverb @@ -95,7 +95,7 @@ SoundMainRAM: .arm SoundMainRAM_Reverb: cmp r4, 0x2 - addeq r7, r0, #o_SoundInfo_pcmBuffer + addeq r7, r0, o_SoundInfo_pcmBuffer addne r7, r5, r8 mov r4, r8 _081DCEC4: @@ -145,14 +145,14 @@ SoundMainRAM_NoReverb_Loop: bgt SoundMainRAM_NoReverb_Loop _081DCF36: ldr r4, [sp, 0x18] - ldr r0, [r4, #o_SoundInfo_divFreq] + ldr r0, [r4, o_SoundInfo_divFreq] mov r12, r0 - ldrb r0, [r4, #o_SoundInfo_maxChans] - adds r4, #o_SoundInfo_chans + ldrb r0, [r4, o_SoundInfo_maxChans] + adds r4, o_SoundInfo_chans SoundMainRAM_ChanLoop: str r0, [sp, 0x4] - ldr r3, [r4, #o_SoundChannel_wav] + ldr r3, [r4, o_SoundChannel_wav] ldr r0, [sp, 0x14] cmp r0, 0 beq _081DCF60 @@ -169,7 +169,7 @@ _081DCF54: .pool _081DCF60: - ldrb r6, [r4, #o_SoundChannel_status] + ldrb r6, [r4, o_SoundChannel_status] movs r0, 0xC7 tst r0, r6 bne _081DCF6A @@ -182,99 +182,99 @@ _081DCF6A: tst r0, r6 bne _081DCFB0 movs r6, 0x3 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] adds r0, r3, 0 adds r0, 0x10 - ldr r1, [r4, #o_SoundChannel_ct] + ldr r1, [r4, o_SoundChannel_ct] adds r0, r1 - str r0, [r4, #o_SoundChannel_cp] + str r0, [r4, o_SoundChannel_cp] ldr r0, [r3, 0xC] subs r0, r1 - str r0, [r4, #o_SoundChannel_ct] + str r0, [r4, o_SoundChannel_ct] movs r5, 0 - strb r5, [r4, #o_SoundChannel_ev] - str r5, [r4, #o_SoundChannel_fw] + strb r5, [r4, o_SoundChannel_ev] + str r5, [r4, o_SoundChannel_fw] ldrb r2, [r3, 0x3] movs r0, 0xC0 tst r0, r2 beq _081DCFF8 movs r0, 0x10 orrs r6, r0 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DCFF8 _081DCFA0: - ldrb r5, [r4, #o_SoundChannel_ev] + ldrb r5, [r4, o_SoundChannel_ev] movs r0, 0x4 tst r0, r6 beq _081DCFB6 - ldrb r0, [r4, #o_SoundChannel_iel] + ldrb r0, [r4, o_SoundChannel_iel] subs r0, 1 - strb r0, [r4, #o_SoundChannel_iel] + strb r0, [r4, o_SoundChannel_iel] bhi _081DD006 _081DCFB0: movs r0, 0 - strb r0, [r4, #o_SoundChannel_status] + strb r0, [r4, o_SoundChannel_status] b _081DD240 _081DCFB6: movs r0, 0x40 tst r0, r6 beq _081DCFD6 - ldrb r0, [r4, #o_SoundChannel_release] + ldrb r0, [r4, o_SoundChannel_release] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, #o_SoundChannel_iev] + ldrb r0, [r4, o_SoundChannel_iev] cmp r5, r0 bhi _081DD006 _081DCFC8: - ldrb r5, [r4, #o_SoundChannel_iev] + ldrb r5, [r4, o_SoundChannel_iev] cmp r5, 0 beq _081DCFB0 movs r0, 0x4 orrs r6, r0 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DD006 _081DCFD6: movs r2, 0x3 ands r2, r6 cmp r2, 0x2 bne _081DCFF4 - ldrb r0, [r4, #o_SoundChannel_decay] + ldrb r0, [r4, o_SoundChannel_decay] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, #o_SoundChannel_sustain] + ldrb r0, [r4, o_SoundChannel_sustain] cmp r5, r0 bhi _081DD006 adds r5, r0, 0 beq _081DCFC8 subs r6, 0x1 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DD006 _081DCFF4: cmp r2, 0x3 bne _081DD006 _081DCFF8: - ldrb r0, [r4, #o_SoundChannel_attack] + ldrb r0, [r4, o_SoundChannel_attack] adds r5, r0 cmp r5, 0xFF bcc _081DD006 movs r5, 0xFF subs r6, 0x1 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] _081DD006: - strb r5, [r4, #o_SoundChannel_ev] + strb r5, [r4, o_SoundChannel_ev] ldr r0, [sp, 0x18] - ldrb r0, [r0, #o_SoundChannel_release] + ldrb r0, [r0, o_SoundChannel_release] adds r0, 0x1 muls r0, r5 lsrs r5, r0, 4 - ldrb r0, [r4, #o_SoundChannel_rightVolume] + ldrb r0, [r4, o_SoundChannel_rightVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, #o_SoundChannel_er] - ldrb r0, [r4, #o_SoundChannel_leftVolume] + strb r0, [r4, o_SoundChannel_er] + ldrb r0, [r4, o_SoundChannel_leftVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, #o_SoundChannel_el] + strb r0, [r4, o_SoundChannel_el] movs r0, 0x10 ands r0, r6 str r0, [sp, 0x10] @@ -289,17 +289,17 @@ _081DD006: str r0, [sp, 0x10] _081DD03A: ldr r5, [sp, 0x8] - ldr r2, [r4, #o_SoundChannel_ct] - ldr r3, [r4, #o_SoundChannel_cp] + ldr r2, [r4, o_SoundChannel_ct] + ldr r3, [r4, o_SoundChannel_cp] adr r0, _081DD044 bx r0 .arm _081DD044: str r8, [sp] - ldr r9, [r4, #o_SoundChannel_fw] - ldrb r10, [r4, #o_SoundChannel_er] - ldrb r11, [r4, #o_SoundChannel_el] - ldrb r0, [r4, #o_SoundChannel_type] + ldr r9, [r4, o_SoundChannel_fw] + ldrb r10, [r4, o_SoundChannel_er] + ldrb r11, [r4, o_SoundChannel_el] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x30 beq _081DD068 bl sub_82DF49C @@ -307,7 +307,7 @@ _081DD044: _081DD068: mov r10, r10, lsl 16 mov r11, r11, lsl 16 - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x8 beq _081DD19C _081DD07C: @@ -383,7 +383,7 @@ _081DD164: ldrne r3, [sp, 0xC] bne _081DD118 _081DD174: - strb r2, [r4, #o_SoundChannel_status] + strb r2, [r4, o_SoundChannel_status] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 @@ -395,7 +395,7 @@ _081DD174: b _081DD234 _081DD19C: push {r4,r12} - ldr r1, [r4, #o_SoundChannel_freq] + ldr r1, [r4, o_SoundChannel_freq] mul r4, r12, r1 ldrsb r0, [r3] ldrsb r1, [r3, 0x1]! @@ -434,10 +434,10 @@ _081DD208: sub r3, r3, 0x1 pop {r4,r12} _081DD228: - str r9, [r4, #o_SoundChannel_fw] + str r9, [r4, o_SoundChannel_fw] _081DD22C: - str r2, [r4, #o_SoundChannel_ct] - str r3, [r4, #o_SoundChannel_cp] + str r2, [r4, o_SoundChannel_ct] + str r3, [r4, o_SoundChannel_cp] _081DD234: ldr r8, [sp] add r0, pc, 0x1 @@ -467,33 +467,33 @@ _081DD25E: arm_func_start sub_82DF49C sub_82DF49C: - ldr r6, [r4, #o_SoundChannel_wav] - ldrb r0, [r4, #o_SoundChannel_status] + ldr r6, [r4, o_SoundChannel_wav] + ldrb r0, [r4, o_SoundChannel_status] tst r0, 0x20 bne _081DD2B4 orr r0, r0, 0x20 - strb r0, [r4, #o_SoundChannel_status] - ldrb r0, [r4, #o_SoundChannel_type] + strb r0, [r4, o_SoundChannel_status] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 beq _081DD29C ldr r1, [r6, 0xC] add r1, r1, r6, lsl 1 add r1, r1, 0x20 sub r3, r1, r3 - str r3, [r4, #o_SoundChannel_cp] + str r3, [r4, o_SoundChannel_cp] _081DD29C: ldrh r0, [r6] cmp r0, 0 beq _081DD2B4 sub r3, r3, r6 sub r3, r3, 0x10 - str r3, [r4, #o_SoundChannel_cp] + str r3, [r4, o_SoundChannel_cp] _081DD2B4: push {r8,r12,lr} mov r10, r10, lsl 16 mov r11, r11, lsl 16 - ldr r1, [r4, #o_SoundChannel_freq] - ldrb r0, [r4, #o_SoundChannel_type] + ldr r1, [r4, o_SoundChannel_freq] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x8 movne r8, 0x800000 muleq r8, r12, r1 @@ -501,8 +501,8 @@ _081DD2B4: cmp r0, 0 beq _081DD468 mov r0, 0xFF000000 - str r0, [r4, #o_SoundChannel_xpi] - ldrb r0, [r4, #o_SoundChannel_type] + str r0, [r4, o_SoundChannel_xpi] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 bne _081DD3C0 bl sub_82DF758 @@ -555,7 +555,7 @@ _081DD398: ldr r0, [sp, 0x1C] cmp r0, 0 beq _081DD4F4 - ldr r3, [r4, #o_SoundChannel_wav] + ldr r3, [r4, o_SoundChannel_wav] ldr r3, [r3, 0x8] rsb lr, r2, 0 _081DD3B0: @@ -612,7 +612,7 @@ _081DD440: add r3, r3, 0x2 b _081DD4F0 _081DD468: - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 beq _081DD4F0 ldrsb r0, [r3, -0x1]! @@ -653,7 +653,7 @@ _081DD4F0: pop {r8,r12,pc} _081DD4F4: mov r2, 0 - strb r2, [r4, #o_SoundChannel_status] + strb r2, [r4, o_SoundChannel_status] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 @@ -669,13 +669,13 @@ _081DD4F4: sub_82DF758: push {r0,r2,r5-r7,lr} mov r0, r3, lsr 6 - ldr r1, [r4, #o_SoundChannel_xpi] + ldr r1, [r4, o_SoundChannel_xpi] cmp r0, r1 beq _081DD594 - str r0, [r4, #o_SoundChannel_xpi] + str r0, [r4, o_SoundChannel_xpi] mov r1, 0x21 mul r2, r1, r0 - ldr r1, [r4, #o_SoundChannel_wav] + ldr r1, [r4, o_SoundChannel_wav] add r2, r2, r1 add r2, r2, 0x10 ldr r5, =gUnknown_03001300 @@ -749,7 +749,7 @@ _081DD5E2: ply_fine: push {r4,r5,lr} adds r5, r1, 0 - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq ply_fine_done ply_fine_loop: @@ -830,7 +830,7 @@ _081DD64A: ply_goto: push {lr} ply_goto_1: - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r0, [r2, 0x3] lsls r0, 8 ldrb r3, [r2, 0x2] @@ -841,24 +841,24 @@ ply_goto_1: lsls r0, 8 bl ldrb_r3_r2 orrs r0, r3 - str r0, [r1, #o_MusicPlayerTrack_cmdPtr] + str r0, [r1, o_MusicPlayerTrack_cmdPtr] pop {r0} bx r0 thumb_func_end ply_goto thumb_func_start ply_patt ply_patt: - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] cmp r2, 3 bhs ply_patt_done lsls r2, 2 adds r3, r1, r2 - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] adds r2, 0x4 - str r2, [r3, #o_MusicPlayerTrack_patternStack] - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + str r2, [r3, o_MusicPlayerTrack_patternStack] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] adds r2, 1 - strb r2, [r1, #o_MusicPlayerTrack_patternLevel] + strb r2, [r1, o_MusicPlayerTrack_patternLevel] b ply_goto ply_patt_done: b ply_fine @@ -866,15 +866,15 @@ ply_patt_done: thumb_func_start ply_pend ply_pend: - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] cmp r2, 0 beq ply_pend_done subs r2, 1 - strb r2, [r1, #o_MusicPlayerTrack_patternLevel] + strb r2, [r1, o_MusicPlayerTrack_patternLevel] lsls r2, 2 adds r3, r1, r2 - ldr r2, [r3, #o_MusicPlayerTrack_patternStack] - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r3, o_MusicPlayerTrack_patternStack] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] ply_pend_done: bx lr thumb_func_end ply_pend @@ -882,17 +882,17 @@ ply_pend_done: thumb_func_start ply_rept ply_rept: push {lr} - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] cmp r3, 0 bne ply_rept_1 adds r2, 1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] b ply_goto_1 ply_rept_1: - ldrb r3, [r1, #o_MusicPlayerTrack_repN] + ldrb r3, [r1, o_MusicPlayerTrack_repN] adds r3, 1 - strb r3, [r1, #o_MusicPlayerTrack_repN] + strb r3, [r1, o_MusicPlayerTrack_repN] mov r12, r3 bl ld_r3_tp_adr_i cmp r12, r3 @@ -900,9 +900,9 @@ ply_rept_1: b ply_goto_1 ply_rept_2: movs r3, 0 - strb r3, [r1, #o_MusicPlayerTrack_repN] + strb r3, [r1, o_MusicPlayerTrack_repN] adds r2, 5 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] pop {r0} bx r0 thumb_func_end ply_rept @@ -911,7 +911,7 @@ ply_rept_2: ply_prio: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_priority] + strb r3, [r1, o_MusicPlayerTrack_priority] bx r12 thumb_func_end ply_prio @@ -920,11 +920,11 @@ ply_tempo: mov r12, lr bl ld_r3_tp_adr_i lsls r3, 1 - strh r3, [r0, #o_MusicPlayerInfo_tempoD] - ldrh r2, [r0, #o_MusicPlayerInfo_tempoU] + strh r3, [r0, o_MusicPlayerInfo_tempoD] + ldrh r2, [r0, o_MusicPlayerInfo_tempoU] muls r3, r2 lsrs r3, 8 - strh r3, [r0, #o_MusicPlayerInfo_tempoI] + strh r3, [r0, o_MusicPlayerInfo_tempoI] bx r12 thumb_func_end ply_tempo @@ -932,35 +932,35 @@ ply_tempo: ply_keysh: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_keyShift] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_keyShift] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_keysh thumb_func_start ply_voice ply_voice: mov r12, lr - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] adds r2, 1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] lsls r2, r3, 1 adds r2, r3 lsls r2, 2 - ldr r3, [r0, #o_MusicPlayerInfo_tone] + ldr r3, [r0, o_MusicPlayerInfo_tone] adds r2, r3 ldr r3, [r2] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_type] + str r3, [r1, o_MusicPlayerTrack_ToneData_type] ldr r3, [r2, 0x4] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_wav] + str r3, [r1, o_MusicPlayerTrack_ToneData_wav] ldr r3, [r2, 0x8] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_attack] + str r3, [r1, o_MusicPlayerTrack_ToneData_attack] bx r12 thumb_func_end ply_voice @@ -968,11 +968,11 @@ ply_voice: ply_vol: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_vol] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_vol] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0x3 orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_vol @@ -981,11 +981,11 @@ ply_pan: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_pan] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_pan] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0x3 orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_pan @@ -994,11 +994,11 @@ ply_bend: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_bend] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_bend] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_bend @@ -1006,11 +1006,11 @@ ply_bend: ply_bendr: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_bendRange] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_bendRange] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_bendr @@ -1018,7 +1018,7 @@ ply_bendr: ply_lfodl: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_lfoDelay] + strb r3, [r1, o_MusicPlayerTrack_lfoDelay] bx r12 thumb_func_end ply_lfodl @@ -1026,14 +1026,14 @@ ply_lfodl: ply_modt: mov r12, lr bl ld_r3_tp_adr_i - ldrb r0, [r1, #o_MusicPlayerTrack_modT] + ldrb r0, [r1, o_MusicPlayerTrack_modT] cmp r0, r3 beq _081DD7AA - strb r3, [r1, #o_MusicPlayerTrack_modT] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_modT] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xF orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] _081DD7AA: bx r12 thumb_func_end ply_modt @@ -1043,18 +1043,18 @@ ply_tune: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_tune] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_tune] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_tune thumb_func_start ply_port ply_port: mov r12, lr - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] adds r2, 1 ldr r0, =REG_SOUND1CNT_L @ sound register base address @@ -1072,20 +1072,20 @@ m4aSoundVSync: @ Exit the function if ident is not ID_NUMBER or ID_NUMBER+1. ldr r2, lt2_ID_NUMBER - ldr r3, [r0, #o_SoundInfo_ident] + ldr r3, [r0, o_SoundInfo_ident] subs r3, r2 cmp r3, 1 bhi m4aSoundVSync_Done @ Decrement the PCM DMA counter. If it reaches 0, we need to do a DMA. - ldrb r1, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r1, [r0, o_SoundInfo_pcmDmaCounter] subs r1, 1 - strb r1, [r0, #o_SoundInfo_pcmDmaCounter] + strb r1, [r0, o_SoundInfo_pcmDmaCounter] bgt m4aSoundVSync_Done @ Reload the PCM DMA counter. - ldrb r1, [r0, #o_SoundInfo_pcmDmaPeriod] - strb r1, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] + strb r1, [r0, o_SoundInfo_pcmDmaCounter] ldr r2, =REG_DMA1 @@ -1127,18 +1127,18 @@ m4aSoundVSync_Done: thumb_func_start MPlayMain MPlayMain: ldr r2, lt2_ID_NUMBER - ldr r3, [r0, #o_MusicPlayerInfo_ident] + ldr r3, [r0, o_MusicPlayerInfo_ident] cmp r2, r3 beq _081DD82E bx lr _081DD82E: adds r3, 0x1 - str r3, [r0, #o_MusicPlayerInfo_ident] + str r3, [r0, o_MusicPlayerInfo_ident] push {r0,lr} - ldr r3, [r0, #o_MusicPlayerInfo_func] + ldr r3, [r0, o_MusicPlayerInfo_func] cmp r3, 0 beq _081DD840 - ldr r0, [r0, #o_MusicPlayerInfo_intp] + ldr r0, [r0, o_MusicPlayerInfo_intp] bl call_r3 _081DD840: pop {r0} @@ -1149,7 +1149,7 @@ _081DD840: mov r7, r11 push {r4-r7} adds r7, r0, 0 - ldr r0, [r7, #o_MusicPlayerInfo_status] + ldr r0, [r7, o_MusicPlayerInfo_status] cmp r0, 0 bge _081DD858 b _081DDA6C @@ -1159,18 +1159,18 @@ _081DD858: mov r8, r0 adds r0, r7, 0 bl FadeOutBody - ldr r0, [r7, #o_MusicPlayerInfo_status] + ldr r0, [r7, o_MusicPlayerInfo_status] cmp r0, 0 bge _081DD86C b _081DDA6C _081DD86C: - ldrh r0, [r7, #o_MusicPlayerInfo_tempoC] - ldrh r1, [r7, #o_MusicPlayerInfo_tempoI] + ldrh r0, [r7, o_MusicPlayerInfo_tempoC] + ldrh r1, [r7, o_MusicPlayerInfo_tempoI] adds r0, r1 b _081DD9BC _081DD874: - ldrb r6, [r7, #o_MusicPlayerInfo_trackCount] - ldr r5, [r7, #o_MusicPlayerInfo_tracks] + ldrb r6, [r7, o_MusicPlayerInfo_trackCount] + ldr r5, [r7, o_MusicPlayerInfo_tracks] movs r3, 0x1 movs r4, 0 _081DD87C: @@ -1183,7 +1183,7 @@ _081DD886: mov r10, r3 orrs r4, r3 mov r11, r4 - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq _081DD8BA _081DD892: @@ -1209,7 +1209,7 @@ _081DD8B4: cmp r4, 0 bne _081DD892 _081DD8BA: - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0x40 tst r0, r3 beq _081DD938 @@ -1218,33 +1218,33 @@ _081DD8BA: movs r0, 0x80 strb r0, [r5] movs r0, 0x2 - strb r0, [r5, #o_MusicPlayerTrack_bendRange] + strb r0, [r5, o_MusicPlayerTrack_bendRange] movs r0, 0x40 - strb r0, [r5, #o_MusicPlayerTrack_volX] + strb r0, [r5, o_MusicPlayerTrack_volX] movs r0, 0x16 - strb r0, [r5, #o_MusicPlayerTrack_lfoSpeed] + strb r0, [r5, o_MusicPlayerTrack_lfoSpeed] movs r0, 0x1 adds r1, r5, 0x6 - strb r0, [r1, #o_MusicPlayerTrack_ToneData_type - 0x6] + strb r0, [r1, o_MusicPlayerTrack_ToneData_type - 0x6] b _081DD938 _081DD8E0: - ldr r2, [r5, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r5, o_MusicPlayerTrack_cmdPtr] ldrb r1, [r2] cmp r1, 0x80 bhs _081DD8EC - ldrb r1, [r5, #o_MusicPlayerTrack_runningStatus] + ldrb r1, [r5, o_MusicPlayerTrack_runningStatus] b _081DD8F6 _081DD8EC: adds r2, 0x1 - str r2, [r5, #o_MusicPlayerTrack_cmdPtr] + str r2, [r5, o_MusicPlayerTrack_cmdPtr] cmp r1, 0xBD bcc _081DD8F6 - strb r1, [r5, #o_MusicPlayerTrack_runningStatus] + strb r1, [r5, o_MusicPlayerTrack_runningStatus] _081DD8F6: cmp r1, 0xCF bcc _081DD90C mov r0, r8 - ldr r3, [r0, #o_SoundInfo_plynote] + ldr r3, [r0, o_SoundInfo_plynote] adds r0, r1, 0 subs r0, 0xCF adds r1, r7, 0 @@ -1256,15 +1256,15 @@ _081DD90C: bls _081DD92E adds r0, r1, 0 subs r0, 0xB1 - strb r0, [r7, #o_MusicPlayerInfo_cmd] + strb r0, [r7, o_MusicPlayerInfo_cmd] mov r3, r8 - ldr r3, [r3, #o_SoundInfo_MPlayJumpTable] + ldr r3, [r3, o_SoundInfo_MPlayJumpTable] lsls r0, 2 ldr r3, [r3, r0] adds r0, r7, 0 adds r1, r5, 0 bl call_r3 - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] cmp r0, 0 beq _081DD994 b _081DD938 @@ -1273,29 +1273,29 @@ _081DD92E: subs r1, 0x80 adds r1, r0 ldrb r0, [r1] - strb r0, [r5, #o_MusicPlayerTrack_wait] + strb r0, [r5, o_MusicPlayerTrack_wait] _081DD938: - ldrb r0, [r5, #o_MusicPlayerTrack_wait] + ldrb r0, [r5, o_MusicPlayerTrack_wait] cmp r0, 0 beq _081DD8E0 subs r0, 0x1 - strb r0, [r5, #o_MusicPlayerTrack_wait] - ldrb r1, [r5, #o_MusicPlayerTrack_lfoSpeed] + strb r0, [r5, o_MusicPlayerTrack_wait] + ldrb r1, [r5, o_MusicPlayerTrack_lfoSpeed] cmp r1, 0 beq _081DD994 - ldrb r0, [r5, #o_MusicPlayerTrack_mod] + ldrb r0, [r5, o_MusicPlayerTrack_mod] cmp r0, 0 beq _081DD994 - ldrb r0, [r5, #o_MusicPlayerTrack_lfoDelayC] + ldrb r0, [r5, o_MusicPlayerTrack_lfoDelayC] cmp r0, 0 beq _081DD95A subs r0, 0x1 - strb r0, [r5, #o_MusicPlayerTrack_lfoDelayC] + strb r0, [r5, o_MusicPlayerTrack_lfoDelayC] b _081DD994 _081DD95A: - ldrb r0, [r5, #o_MusicPlayerTrack_lfoSpeedC] + ldrb r0, [r5, o_MusicPlayerTrack_lfoSpeedC] adds r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_lfoSpeedC] + strb r0, [r5, o_MusicPlayerTrack_lfoSpeedC] adds r1, r0, 0 subs r0, 0x40 lsls r0, 24 @@ -1307,16 +1307,16 @@ _081DD96E: movs r0, 0x80 subs r2, r0, r1 _081DD972: - ldrb r0, [r5, #o_MusicPlayerTrack_mod] + ldrb r0, [r5, o_MusicPlayerTrack_mod] muls r0, r2 asrs r2, r0, 6 - ldrb r0, [r5, #o_MusicPlayerTrack_modM] + ldrb r0, [r5, o_MusicPlayerTrack_modM] eors r0, r2 lsls r0, 24 beq _081DD994 - strb r2, [r5, #o_MusicPlayerTrack_modM] + strb r2, [r5, o_MusicPlayerTrack_modM] ldrb r0, [r5] - ldrb r1, [r5, #o_MusicPlayerTrack_modT] + ldrb r1, [r5, o_MusicPlayerTrack_modT] cmp r1, 0 bne _081DD98E movs r1, 0xC @@ -1325,7 +1325,7 @@ _081DD98E: movs r1, 0x3 _081DD990: orrs r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_flags] + strb r0, [r5, o_MusicPlayerTrack_flags] _081DD994: mov r3, r10 mov r4, r11 @@ -1337,29 +1337,29 @@ _081DD998: lsls r3, 1 b _081DD87C _081DD9A4: - ldr r0, [r7, #o_MusicPlayerInfo_clock] + ldr r0, [r7, o_MusicPlayerInfo_clock] adds r0, 0x1 - str r0, [r7, #o_MusicPlayerInfo_clock] + str r0, [r7, o_MusicPlayerInfo_clock] cmp r4, 0 bne _081DD9B6 movs r0, 0x80 lsls r0, 24 - str r0, [r7, #o_MusicPlayerInfo_status] + str r0, [r7, o_MusicPlayerInfo_status] b _081DDA6C _081DD9B6: - str r4, [r7, #o_MusicPlayerInfo_status] - ldrh r0, [r7, #o_MusicPlayerInfo_tempoC] + str r4, [r7, o_MusicPlayerInfo_status] + ldrh r0, [r7, o_MusicPlayerInfo_tempoC] subs r0, 0x96 _081DD9BC: - strh r0, [r7, #o_MusicPlayerInfo_tempoC] + strh r0, [r7, o_MusicPlayerInfo_tempoC] cmp r0, 0x96 bcc _081DD9C4 b _081DD874 _081DD9C4: - ldrb r2, [r7, #o_MusicPlayerInfo_trackCount] - ldr r5, [r7, #o_MusicPlayerInfo_tracks] + ldrb r2, [r7, o_MusicPlayerInfo_trackCount] + ldr r5, [r7, o_MusicPlayerInfo_tracks] _081DD9C8: - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] movs r1, 0x80 tst r1, r0 beq _081DDA62 @@ -1370,11 +1370,11 @@ _081DD9C8: adds r0, r7, 0 adds r1, r5, 0 bl TrkVolPitSet - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq _081DDA58 _081DD9E6: - ldrb r1, [r4, #o_SoundChannel_status] + ldrb r1, [r4, o_SoundChannel_status] movs r0, 0xC7 tst r0, r1 bne _081DD9F6 @@ -1382,26 +1382,26 @@ _081DD9E6: bl ClearChain b _081DDA52 _081DD9F6: - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] movs r6, 0x7 ands r6, r0 - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0x3 tst r0, r3 beq _081DDA14 bl ChnVolSetAsm cmp r6, 0 beq _081DDA14 - ldrb r0, [r4, #o_CgbChannel_mo] + ldrb r0, [r4, o_CgbChannel_mo] movs r1, 0x1 orrs r0, r1 - strb r0, [r4, #o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_mo] _081DDA14: - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0xC tst r0, r3 beq _081DDA52 - ldrb r1, [r4, #o_SoundChannel_ky] + ldrb r1, [r4, o_SoundChannel_ky] movs r0, 0x8 ldrsb r0, [r5, r0] adds r2, r1, r0 @@ -1411,32 +1411,32 @@ _081DDA28: cmp r6, 0 beq _081DDA46 mov r0, r8 - ldr r3, [r0, #o_SoundInfo_MidiKeyToCgbFreq] + ldr r3, [r0, o_SoundInfo_MidiKeyToCgbFreq] adds r1, r2, 0 - ldrb r2, [r5, #o_MusicPlayerTrack_pitM] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] adds r0, r6, 0 bl call_r3 - str r0, [r4, #o_CgbChannel_fr] - ldrb r0, [r4, #o_CgbChannel_mo] + str r0, [r4, o_CgbChannel_fr] + ldrb r0, [r4, o_CgbChannel_mo] movs r1, 0x2 orrs r0, r1 - strb r0, [r4, #o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_mo] b _081DDA52 _081DDA46: adds r1, r2, 0 - ldrb r2, [r5, #o_MusicPlayerTrack_pitM] - ldr r0, [r4, #o_SoundChannel_wav] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] + ldr r0, [r4, o_SoundChannel_wav] bl MidiKeyToFreq - str r0, [r4, #o_SoundChannel_freq] + str r0, [r4, o_SoundChannel_freq] _081DDA52: - ldr r4, [r4, #o_SoundChannel_np] + ldr r4, [r4, o_SoundChannel_np] cmp r4, 0 bne _081DD9E6 _081DDA58: - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] movs r1, 0xF0 ands r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_flags] + strb r0, [r5, o_MusicPlayerTrack_flags] mov r2, r9 _081DDA62: subs r2, 0x1 @@ -1446,7 +1446,7 @@ _081DDA62: bgt _081DD9C8 _081DDA6C: ldr r0, lt2_ID_NUMBER - str r0, [r7, #o_MusicPlayerInfo_ident] + str r0, [r7, o_MusicPlayerInfo_ident] pop {r0-r7} mov r8, r0 mov r9, r1 @@ -1467,35 +1467,35 @@ lt2_ID_NUMBER: .word ID_NUMBER TrackStop: push {r4-r6,lr} adds r5, r1, 0 - ldrb r1, [r5, #o_MusicPlayerTrack_flags] + ldrb r1, [r5, o_MusicPlayerTrack_flags] movs r0, 0x80 tst r0, r1 beq TrackStop_Done - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq TrackStop_3 movs r6, 0 TrackStop_Loop: - ldrb r0, [r4, #o_SoundChannel_status] + ldrb r0, [r4, o_SoundChannel_status] cmp r0, 0 beq TrackStop_2 - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] movs r3, 0x7 ands r0, r3 beq TrackStop_1 ldr r3, =SOUND_INFO_PTR ldr r3, [r3] - ldr r3, [r3, #o_SoundInfo_CgbOscOff] + ldr r3, [r3, o_SoundInfo_CgbOscOff] bl call_r3 TrackStop_1: - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] TrackStop_2: - str r6, [r4, #o_SoundChannel_track] - ldr r4, [r4, #o_SoundChannel_np] + str r6, [r4, o_SoundChannel_track] + ldr r4, [r4, o_SoundChannel_np] cmp r4, 0 bne TrackStop_Loop TrackStop_3: - str r4, [r5, #o_MusicPlayerTrack_chan] + str r4, [r5, o_MusicPlayerTrack_chan] TrackStop_Done: pop {r4-r6} pop {r0} @@ -1550,41 +1550,41 @@ ply_note: ldr r1, =gClockTable adds r0, r1 ldrb r0, [r0] - strb r0, [r5, #o_MusicPlayerTrack_gateTime] - ldr r3, [r5, #o_MusicPlayerTrack_cmdPtr] + strb r0, [r5, o_MusicPlayerTrack_gateTime] + ldr r3, [r5, o_MusicPlayerTrack_cmdPtr] ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB46 - strb r0, [r5, #o_MusicPlayerTrack_key] + strb r0, [r5, o_MusicPlayerTrack_key] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB44 - strb r0, [r5, #o_MusicPlayerTrack_velocity] + strb r0, [r5, o_MusicPlayerTrack_velocity] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB44 - ldrb r1, [r5, #o_MusicPlayerTrack_gateTime] + ldrb r1, [r5, o_MusicPlayerTrack_gateTime] adds r1, r0 - strb r1, [r5, #o_MusicPlayerTrack_gateTime] + strb r1, [r5, o_MusicPlayerTrack_gateTime] adds r3, 0x1 _081DDB44: - str r3, [r5, #o_MusicPlayerTrack_cmdPtr] + str r3, [r5, o_MusicPlayerTrack_cmdPtr] _081DDB46: movs r0, 0 str r0, [sp, 0x14] adds r4, r5, 0 - adds r4, #o_MusicPlayerTrack_ToneData_type + adds r4, o_MusicPlayerTrack_ToneData_type ldrb r2, [r4] movs r0, TONEDATA_TYPE_RHY | TONEDATA_TYPE_SPL tst r0, r2 beq _081DDB98 - ldrb r3, [r5, #o_MusicPlayerTrack_key] + ldrb r3, [r5, o_MusicPlayerTrack_key] movs r0, TONEDATA_TYPE_SPL tst r0, r2 beq _081DDB66 - ldr r1, [r5, #o_MusicPlayerTrack_ToneData_keySplitTable] + ldr r1, [r5, o_MusicPlayerTrack_ToneData_keySplitTable] adds r1, r3 ldrb r0, [r1] b _081DDB68 @@ -1594,7 +1594,7 @@ _081DDB68: lsls r1, r0, 1 adds r1, r0 lsls r1, 2 - ldr r0, [r5, #o_MusicPlayerTrack_ToneData_wav] + ldr r0, [r5, o_MusicPlayerTrack_ToneData_wav] adds r1, r0 mov r9, r1 mov r6, r9 @@ -1787,7 +1787,7 @@ _081DDCBC: bl call_r3 b _081DDCDC _081DDCCE: - ldr r0, [r5, #o_MusicPlayerTrack_unk_3C] + ldr r0, [r5, o_MusicPlayerTrack_unk_3C] str r0, [r4, 0x18] ldrb r2, [r5, 0x9] adds r1, r3, 0 @@ -1816,37 +1816,37 @@ _081DDCEA: thumb_func_start ply_endtie ply_endtie: push {r4,r5} - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] cmp r3, 0x80 bhs _081DDD16 - strb r3, [r1, #o_MusicPlayerTrack_key] + strb r3, [r1, o_MusicPlayerTrack_key] adds r2, 0x1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] b _081DDD18 _081DDD16: - ldrb r3, [r1, #o_MusicPlayerTrack_key] + ldrb r3, [r1, o_MusicPlayerTrack_key] _081DDD18: - ldr r1, [r1, #o_MusicPlayerTrack_chan] + ldr r1, [r1, o_MusicPlayerTrack_chan] cmp r1, 0 beq _081DDD40 movs r4, 0x83 movs r5, 0x40 _081DDD22: - ldrb r2, [r1, #o_SoundChannel_status] + ldrb r2, [r1, o_SoundChannel_status] tst r2, r4 beq _081DDD3A tst r2, r5 bne _081DDD3A - ldrb r0, [r1, #o_SoundChannel_mk] + ldrb r0, [r1, o_SoundChannel_mk] cmp r0, r3 bne _081DDD3A movs r0, 0x40 orrs r2, r0 - strb r2, [r1, #o_SoundChannel_status] + strb r2, [r1, o_SoundChannel_status] b _081DDD40 _081DDD3A: - ldr r1, [r1, #o_SoundChannel_np] + ldr r1, [r1, o_SoundChannel_np] cmp r1, 0 bne _081DDD22 _081DDD40: @@ -1857,9 +1857,9 @@ _081DDD40: thumb_func_start clear_modM clear_modM: movs r2, 0 - strb r2, [r1, #o_MusicPlayerTrack_modM] - strb r2, [r1, #o_MusicPlayerTrack_lfoSpeedC] - ldrb r2, [r1, #o_MusicPlayerTrack_modT] + strb r2, [r1, o_MusicPlayerTrack_modM] + strb r2, [r1, o_MusicPlayerTrack_lfoSpeedC] + ldrb r2, [r1, o_MusicPlayerTrack_modT] cmp r2, 0 bne _081DDD54 movs r2, 0xC @@ -1867,17 +1867,17 @@ clear_modM: _081DDD54: movs r2, 0x3 _081DDD56: - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + ldrb r3, [r1, o_MusicPlayerTrack_flags] orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx lr thumb_func_end clear_modM thumb_func_start ld_r3_tp_adr_i ld_r3_tp_adr_i_unchecked: - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] adds r3, r2, 1 - str r3, [r1, #o_MusicPlayerTrack_cmdPtr] + str r3, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] bx lr thumb_func_end ld_r3_tp_adr_i @@ -1886,7 +1886,7 @@ ld_r3_tp_adr_i_unchecked: ply_lfos: mov r12, lr bl ld_r3_tp_adr_i_unchecked - strb r3, [r1, #o_MusicPlayerTrack_lfoSpeed] + strb r3, [r1, o_MusicPlayerTrack_lfoSpeed] cmp r3, 0 bne _081DDD7C bl clear_modM @@ -1898,7 +1898,7 @@ _081DDD7C: ply_mod: mov r12, lr bl ld_r3_tp_adr_i_unchecked - strb r3, [r1, #o_MusicPlayerTrack_mod] + strb r3, [r1, o_MusicPlayerTrack_mod] cmp r3, 0 bne _081DDD90 bl clear_modM diff --git a/src/m4a_tables.c b/src/m4a_tables.c index dfd285b1f..9a4ea32e6 100644 --- a/src/m4a_tables.c +++ b/src/m4a_tables.c @@ -83,7 +83,7 @@ const u8 gScaleTable[] = 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, }; -const u32 gFreqTable[12] = +const u32 gFreqTable[] = { 2147483648u, 2275179671u, @@ -99,7 +99,7 @@ const u32 gFreqTable[12] = 4053909305u, }; -const u16 gPcmSamplesPerVBlankTable[12] = +const u16 gPcmSamplesPerVBlankTable[] = { 96, 132, @@ -130,7 +130,7 @@ const u8 gCgbScaleTable[] = 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, }; -const s16 gCgbFreqTable[12] = +const s16 gCgbFreqTable[] = { -2004, -1891, diff --git a/src/mail.c b/src/mail.c index 04464f06b..ad784f61d 100644 --- a/src/mail.c +++ b/src/mail.c @@ -524,7 +524,7 @@ static void CB2_WaitForPaletteExitOnKeyPress(void) static void CB2_ExitOnKeyPress(void) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); sMailRead->callback2 = CB2_ExitMailReadFreeVars; diff --git a/src/main.c b/src/main.c index b3b76b1fb..454fefc5c 100644 --- a/src/main.c +++ b/src/main.c @@ -81,6 +81,8 @@ void InitIntrHandlers(void); static void WaitForVBlank(void); void EnableVCountIntrAtLine150(void); +#define B_START_SELECT (B_BUTTON | START_BUTTON | SELECT_BUTTON) + void AgbMain() { #if MODERN @@ -134,11 +136,9 @@ void AgbMain() { ReadKeys(); - if (!gSoftResetDisabled - && JOY_HELD_RAW(A_BUTTON) - && JOY_HELD_RAW(B_BUTTON) - && JOY_HELD_RAW(START_BUTTON) - && JOY_HELD_RAW(SELECT_BUTTON)) //The reset key combo A + B + START + SELECT + if (gSoftResetDisabled == FALSE + && (gMain.heldKeysRaw & A_BUTTON) + && (gMain.heldKeysRaw & B_START_SELECT) == B_START_SELECT) { rfu_REQ_stopMode(); rfu_waitREQComplete(); @@ -262,7 +262,9 @@ static void ReadKeys(void) if (keyInput != 0 && gMain.heldKeys == keyInput) { - if (--gMain.keyRepeatCounter == 0) + gMain.keyRepeatCounter--; + + if (gMain.keyRepeatCounter == 0) { gMain.newAndRepeatedKeys = keyInput; gMain.keyRepeatCounter = gKeyRepeatContinueDelay; @@ -280,10 +282,10 @@ static void ReadKeys(void) // Remap L to A if the L=A option is enabled. if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) { - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) gMain.newKeys |= A_BUTTON; - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) gMain.heldKeys |= A_BUTTON; } @@ -341,7 +343,7 @@ static void VBlankIntr(void) { if (gWirelessCommType != 0) RfuVSync(); - else if (!gLinkVSyncDisabled) + else if (gLinkVSyncDisabled == FALSE) LinkVSync(); gMain.vblankCounter1++; diff --git a/src/main_menu.c b/src/main_menu.c index 5b39b6d45..203461e6a 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -695,7 +695,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId) static void Task_WaitForSaveFileErrorWindow(u8 taskId) { RunTextPrinters(); - if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON))) + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) { ClearWindowTilemap(7); ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]); @@ -730,7 +730,7 @@ static void Task_MainMenuCheckBattery(u8 taskId) static void Task_WaitForBatteryDryErrorWindow(u8 taskId) { RunTextPrinters(); - if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON))) + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) { ClearWindowTilemap(7); ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]); @@ -886,14 +886,14 @@ static bool8 HandleMainMenuInput(u8 taskId) { s16* data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); IsWirelessAdapterConnected(); // why bother calling this here? debug? Task_HandleMainMenuAPressed will check too BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_HandleMainMenuAPressed; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITEALPHA); @@ -901,7 +901,7 @@ static bool8 HandleMainMenuInput(u8 taskId) SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(0, 160)); gTasks[taskId].func = Task_HandleMainMenuBPressed; } - else if ((JOY_NEW(DPAD_UP)) && tCurrItem > 0) + else if ((gMain.newKeys & DPAD_UP) && tCurrItem > 0) { if (tMenuType == HAS_MYSTERY_EVENTS && tIsScrolled == TRUE && tCurrItem == 1) { @@ -913,7 +913,7 @@ static bool8 HandleMainMenuInput(u8 taskId) sCurrItemAndOptionMenuCheck = tCurrItem; return TRUE; } - else if ((JOY_NEW(DPAD_DOWN)) && tCurrItem < tItemCount - 1) + else if ((gMain.newKeys & DPAD_DOWN) && tCurrItem < tItemCount - 1) { if (tMenuType == HAS_MYSTERY_EVENTS && tCurrItem == 3 && tIsScrolled == FALSE) { @@ -1150,7 +1150,7 @@ static void Task_DisplayMainMenuInvalidActionError(u8 taskId) gTasks[taskId].tCurrItem++; break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); @@ -1593,7 +1593,7 @@ static void Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint(u8 taskId) static void Task_NewGameBirchSpeech_WaitPressBeforeNameChoice(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_NewGameBirchSpeech_StartNamingScreen; diff --git a/src/match_call.c b/src/match_call.c index 944d85b8f..c9752495a 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -1252,7 +1252,7 @@ static bool32 sub_81962D8(u8 taskId) static bool32 sub_8196330(u8 taskId) { s16 *taskData = gTasks[taskId].data; - if (!ExecuteMatchCallTextPrinter(taskData[2]) && !IsSEPlaying() && JOY_NEW(A_BUTTON | B_BUTTON)) + if (!ExecuteMatchCallTextPrinter(taskData[2]) && !IsSEPlaying() && gMain.newKeys & (A_BUTTON | B_BUTTON)) { FillWindowPixelBuffer(taskData[2], PIXEL_FILL(8)); CopyWindowToVram(taskData[2], 2); @@ -1334,7 +1334,7 @@ static void InitMatchCallTextPrinter(int windowId, const u8 *str) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 10; printerTemplate.bgColor = 8; printerTemplate.shadowColor = 14; @@ -1345,7 +1345,7 @@ static void InitMatchCallTextPrinter(int windowId, const u8 *str) static bool32 ExecuteMatchCallTextPrinter(int windowId) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) gTextFlags.canABSpeedUpPrint = 1; else gTextFlags.canABSpeedUpPrint = 0; @@ -1773,7 +1773,7 @@ static int GetNumOwnedBadges(void) static bool32 sub_8196D74(int matchCallId) { int dayCount; - u32 otId; + int otId; u16 easyChatWord; int numRematchTrainersFought; int var0, var1, var2; diff --git a/src/menu.c b/src/menu.c index 9c5dec024..f3334919c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -180,7 +180,7 @@ u16 AddTextPrinterParameterized2(u8 windowId, u8 fontId, const u8 *str, u8 speed printer.currentY = 1; printer.letterSpacing = 0; printer.lineSpacing = 0; - printer.style = 0; + printer.unk = 0; printer.fgColor = fgColor; printer.bgColor = bgColor; printer.shadowColor = shadowColor; @@ -981,23 +981,23 @@ u8 Menu_GetCursorPos(void) s8 Menu_ProcessInput(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1011,23 +1011,23 @@ s8 Menu_ProcessInputNoWrap(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (oldPos != Menu_MoveCursorNoWrapAround(-1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (oldPos != Menu_MoveCursorNoWrapAround(1)) PlaySE(SE_SELECT); @@ -1039,23 +1039,23 @@ s8 Menu_ProcessInputNoWrap(void) s8 ProcessMenuInput_other(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1069,23 +1069,23 @@ s8 Menu_ProcessInputNoWrapAround_other(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { if (oldPos != Menu_MoveCursorNoWrapAround(-1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { if (oldPos != Menu_MoveCursorNoWrapAround(1)) PlaySE(SE_SELECT); @@ -1130,7 +1130,7 @@ void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 l printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = letterSpacing; printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); printer.x = left; @@ -1194,7 +1194,7 @@ void sub_8198AF8(const struct WindowTemplate *window, u8 fontId, u8 left, u8 top printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); @@ -1252,7 +1252,7 @@ void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); @@ -1407,34 +1407,34 @@ u8 ChangeGridMenuCursorPosition(s8 deltaX, s8 deltaY) s8 sub_8199284(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1448,34 +1448,34 @@ s8 Menu_ProcessInputGridLayout(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (oldPos != ChangeGridMenuCursorPosition(0, -1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (oldPos != ChangeGridMenuCursorPosition(0, 1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(-1, 0)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(1, 0)) PlaySE(SE_SELECT); @@ -1487,34 +1487,34 @@ s8 Menu_ProcessInputGridLayout(void) s8 sub_81993D8(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1529,34 +1529,34 @@ s8 sub_8199484(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { if (oldPos != ChangeGridMenuCursorPosition(0, -1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { if (oldPos != ChangeGridMenuCursorPosition(0, 1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(-1, 0)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(1, 0)) PlaySE(SE_SELECT); @@ -1616,7 +1616,7 @@ void sub_81995E4(u8 windowId, u8 itemCount, const struct MenuAction *strs, const printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; printer.x = 8; @@ -1650,7 +1650,7 @@ void CreateYesNoMenu(const struct WindowTemplate *window, u16 baseTileNum, u8 pa printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; @@ -1681,7 +1681,7 @@ void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct M printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; @@ -1949,7 +1949,7 @@ void AddTextPrinterParameterized3(u8 windowId, u8 fontId, u8 left, u8 top, const printer.currentY = printer.y; printer.letterSpacing = GetFontAttribute(fontId, 2); printer.lineSpacing = GetFontAttribute(fontId, 3); - printer.style = 0; + printer.unk = 0; printer.fgColor = color[1]; printer.bgColor = color[0]; printer.shadowColor = color[2]; @@ -1970,7 +1970,7 @@ void AddTextPrinterParameterized4(u8 windowId, u8 fontId, u8 left, u8 top, u8 le printer.currentY = printer.y; printer.letterSpacing = letterSpacing; printer.lineSpacing = lineSpacing; - printer.style = 0; + printer.unk = 0; printer.fgColor = color[1]; printer.bgColor = color[0]; printer.shadowColor = color[2]; @@ -1991,7 +1991,7 @@ void AddTextPrinterParameterized5(u8 windowId, u8 fontId, const u8 *str, u8 left printer.currentY = top; printer.letterSpacing = letterSpacing; printer.lineSpacing = lineSpacing; - printer.style = 0; + printer.unk = 0; printer.fgColor = GetFontAttribute(fontId, 5); printer.bgColor = GetFontAttribute(fontId, 6); diff --git a/src/menu_helpers.c b/src/menu_helpers.c index c80e52d27..69443d309 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -183,7 +183,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) { s16 valBefore = (*arg0); - if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { (*arg0)++; if ((*arg0) > arg1) @@ -199,7 +199,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { (*arg0)--; if ((*arg0) <= 0) @@ -215,7 +215,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT) { (*arg0) += 10; if ((*arg0) > arg1) @@ -231,7 +231,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT) { (*arg0) -= 10; if ((*arg0) <= 0) @@ -255,9 +255,9 @@ u8 GetLRKeysPressed(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) return MENU_L_PRESSED; - if (JOY_NEW(R_BUTTON)) + if (gMain.newKeys & R_BUTTON) return MENU_R_PRESSED; } @@ -268,9 +268,9 @@ u8 GetLRKeysPressedAndHeld(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_REPEAT(L_BUTTON)) + if (gMain.newAndRepeatedKeys & L_BUTTON) return MENU_L_PRESSED; - if (JOY_REPEAT(R_BUTTON)) + if (gMain.newAndRepeatedKeys & R_BUTTON) return MENU_R_PRESSED; } diff --git a/src/menu_specialized.c b/src/menu_specialized.c index 0745ac6d5..1d317a1aa 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -249,7 +249,7 @@ void sub_81D1D04(u8 a0) sUnknown_0203CF48[a0] = 0xFF; } -static u8 sub_81D1D34(u8 a0) // unused +static u8 sub_81D1D34(u8 a0) { return sUnknown_0203CF48[a0]; } @@ -893,73 +893,76 @@ static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) { return StringCopyPadded(dst, gText_EggNickname, 0, 12); } - GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, dst); - StringGetEnd10(dst); - species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES, NULL); - if (boxId == TOTAL_BOXES_COUNT) // Party mon. - { - level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); - gender = GetMonGender(&gPlayerParty[monId]); - } else { - // Needed to match, feel free to remove. - boxId++, boxId--; - monId++, monId--; - - boxMon = GetBoxedMonPtr(boxId, monId); - gender = GetBoxMonGender(boxMon); - level = GetLevelFromBoxMonExp(boxMon); - } + GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, dst); + StringGetEnd10(dst); + species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES, NULL); + if (boxId == TOTAL_BOXES_COUNT) // Party mon. + { + level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); + gender = GetMonGender(&gPlayerParty[monId]); + } + else + { + // Needed to match, feel free to remove. + boxId++;boxId--; + monId++;monId--; - if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) - gender = MON_GENDERLESS; + boxMon = GetBoxedMonPtr(boxId, monId); + gender = GetBoxMonGender(boxMon); + level = GetLevelFromBoxMonExp(boxMon); + } - for (str = dst; *str != EOS; str++) - ; + if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) + gender = MON_GENDERLESS; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SKIP; - *(str++) = 60; + for (str = dst; *str != EOS; str++) + ; - switch (gender) - { - default: - *(str++) = CHAR_SPACE; - break; - case MON_MALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_RED; *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_RED; - *(str++) = CHAR_MALE; - break; - case MON_FEMALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_GREEN; + *(str++) = EXT_CTRL_CODE_SKIP; + *(str++) = 60; + + switch (gender) + { + default: + *(str++) = CHAR_SPACE; + break; + case MON_MALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_RED; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_RED; + *(str++) = CHAR_MALE; + break; + case MON_FEMALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_GREEN; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_GREEN; + *(str++) = CHAR_FEMALE; + break; + } + *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_GREEN; - *(str++) = CHAR_FEMALE; - break; - } + *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + *(str++) = TEXT_COLOR_BLUE; + *(str++) = TEXT_COLOR_TRANSPARENT; + *(str++) = TEXT_COLOR_LIGHT_BLUE; + *(str++) = CHAR_SLASH; + *(str++) = CHAR_EXTRA_SYMBOL; + *(str++) = CHAR_LV_2; + str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); + *(str++) = CHAR_SPACE; + *str = EOS; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - *(str++) = TEXT_COLOR_BLUE; - *(str++) = TEXT_COLOR_TRANSPARENT; - *(str++) = TEXT_COLOR_LIGHT_BLUE; - *(str++) = CHAR_SLASH; - *(str++) = CHAR_EXTRA_SYMBOL; - *(str++) = CHAR_LV_2; - str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); - *(str++) = CHAR_SPACE; - *str = EOS; - - return str; + return str; + } } // Buffers the string in src to dest up to n chars. If src is less than n chars, fill with spaces diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 607083e26..ef7bf7228 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -168,7 +168,7 @@ const struct PulseBlendSettings gMirageTowerPulseBlendSettings = { .numColors = 15, .delay = 5, .numFadeCycles = -1, - .maxBlendCoeff = -5, + .maxBlendCoeff = 11, .fadeType = 1, .restorePaletteOnUnload = FALSE, .unk7_7 = 1, @@ -412,9 +412,10 @@ void DoMirageTowerCeilingCrumble(void) static void WaitCeilingCrumble(u8 taskId) { - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; + data[1]++; // Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed. - if (++data[1] == 1000 || data[0] == 17) + if (data[1] == 1000 || data[0] == 17) gTasks[taskId].func = FinishCeilingCrumbleTask; } @@ -690,7 +691,7 @@ static void DoFossilFallAndSink(u8 taskId) if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) return; DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); - FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC); + FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); FREE_AND_SET_NULL(sUnknown_0203CF0C); @@ -725,8 +726,8 @@ static void sub_81BF248(struct Sprite *sprite) static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) { + u8 r5, r4, r0, r2; u16 var, var2; - u8 r0, r5, r4, r2; u8 r2_1, r4_1; u8 b2, c2; @@ -738,25 +739,23 @@ static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) r4_1 = r4 & 7; r2_1 = r2 & 7; - - gUnknown_030012A8[2] = r4 & 7; //should be r4_1 but that doesn't match - gUnknown_030012A8[3] = r2 & 7; //should be r2_1 but that doesn't match - + gUnknown_030012A8[2] = r4 & 7; //should be using r4_1, but that doesn't match + gUnknown_030012A8[3] = r2 & 7; //" + r0 = r2 / 8; r5 = r4 / 8; - - gUnknown_030012A8[4] = r2 / 8; //should just be r0, but that doesn't match - gUnknown_030012A8[5] = r4 / 8; //should be just r5 but that doesn't match + + gUnknown_030012A8[4] = r2 / 8; //should be using r0, but that doesn't match + gUnknown_030012A8[5] = r4 / 8; //should be using r5, but that doesn't match var = (d / 8) * (r5 * 64) + (r0 * 64); - gUnknown_030012A8[6] = var; - + var2 = var + ((r4_1 * 8) + r2_1); var2 /= 2; - gUnknown_030012A8[7] = var + ((r4_1 * 8) + r2_1); // should be var2 with var2 being divided by 2 AFTER this assignment, but that doesn't match. - + gUnknown_030012A8[7] = var + ((r4_1 * 8) + r2_1); //should be using var2 with var2 being divided afterwards, but that doesn't match + b2 = ((b % 2) ^ 1); - c2 = (c << (b2 << 2)) | (15 << (((b2 ^ 1) << 2))); + c2 = (c << (b2 << 2)) | 15 << (((b2 ^ 1) << 2)); a[var2 + (e * 32)] &= c2; } diff --git a/src/mon_markings.c b/src/mon_markings.c index a819d4f9a..e1897af76 100644 --- a/src/mon_markings.c +++ b/src/mon_markings.c @@ -394,7 +394,7 @@ bool8 MonMarkingsMenuHandleInput(void) { u16 i; - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { s8 pos; PlaySE(SE_SELECT); @@ -404,7 +404,7 @@ bool8 MonMarkingsMenuHandleInput(void) return TRUE; } - if (JOY_NEW(DPAD_DOWN)) + if (gMain.newKeys & DPAD_DOWN) { s8 pos; PlaySE(SE_SELECT); @@ -414,7 +414,7 @@ bool8 MonMarkingsMenuHandleInput(void) return TRUE; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -433,7 +433,7 @@ bool8 MonMarkingsMenuHandleInput(void) return TRUE; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); return FALSE; diff --git a/src/move_relearner.c b/src/move_relearner.c index cd4da5835..3e7caf133 100644 --- a/src/move_relearner.c +++ b/src/move_relearner.c @@ -732,7 +732,7 @@ static void DoMoveRelearnerMain(void) } break; case MENU_STATE_WAIT_FOR_A_BUTTON: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sMoveRelearnerStruct->state = MENU_STATE_FADE_AND_RETURN; @@ -778,7 +778,7 @@ static void HandleInput(bool8 showContest) switch (itemId) { case LIST_NOTHING_CHOSEN: - if (!(JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) && !GetLRKeysPressed()) + if (!(gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) && !GetLRKeysPressed()) { break; } diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c index 00dcbf0e3..032cc3340 100644 --- a/src/mystery_event_menu.c +++ b/src/mystery_event_menu.c @@ -163,7 +163,7 @@ static void CB2_MysteryEventMenu(void) PrintMysteryMenuText(0, gText_PressAToLoadEvent, 1, 2, 1); gMain.state++; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -177,7 +177,7 @@ static void CB2_MysteryEventMenu(void) case 5: if (GetLinkPlayerCount_2() == 2) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); CheckShouldAdvanceLinkState(); @@ -187,7 +187,7 @@ static void CB2_MysteryEventMenu(void) CopyWindowToVram(1, 3); gMain.state++; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -227,7 +227,7 @@ static void CB2_MysteryEventMenu(void) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -274,7 +274,7 @@ static void CB2_MysteryEventMenu(void) } break; case 14: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gMain.state++; diff --git a/src/mystery_gift.c b/src/mystery_gift.c index a23f159b2..ca5ab1baf 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -561,7 +561,7 @@ bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str) goto inc; case 1: DrawDownArrow(1, 0xD0, 0x14, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]); - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { inc: (*textState)++; @@ -595,7 +595,7 @@ bool32 unref_HideDownArrowAndWaitButton(u8 * textState) { case 0: HideDownArrow(); - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { (*textState)++; } @@ -930,7 +930,7 @@ static bool32 mevent_save_game(u8 * state) (*state)++; break; case 3: - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { (*state)++; } @@ -1458,11 +1458,11 @@ void task00_mystery_gift(u8 taskId) case 20: if (data->IsCardOrNews == 0) { - if (({JOY_NEW(A_BUTTON);})) + if (({gMain.newKeys & A_BUTTON;})) { data->state = 21; } - if (({JOY_NEW(B_BUTTON);})) + if (({gMain.newKeys & B_BUTTON;})) { data->state = 27; } diff --git a/src/option_menu.c b/src/option_menu.c index b6440a89c..1cf0bad2e 100644 --- a/src/option_menu.c +++ b/src/option_menu.c @@ -271,16 +271,16 @@ static void Task_OptionMenuFadeIn(u8 taskId) static void Task_OptionMenuProcessInput(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].data[TD_MENUSELECTION] == MENUITEM_CANCEL) gTasks[taskId].func = Task_OptionMenuSave; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { gTasks[taskId].func = Task_OptionMenuSave; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gTasks[taskId].data[TD_MENUSELECTION] > 0) gTasks[taskId].data[TD_MENUSELECTION]--; @@ -288,7 +288,7 @@ static void Task_OptionMenuProcessInput(u8 taskId) gTasks[taskId].data[TD_MENUSELECTION] = MENUITEM_CANCEL; HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (gTasks[taskId].data[TD_MENUSELECTION] < MENUITEM_CANCEL) gTasks[taskId].data[TD_MENUSELECTION]++; @@ -405,7 +405,7 @@ static void DrawOptionMenuChoice(const u8 *text, u8 x, u8 y, u8 style) static u8 TextSpeed_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection <= 1) selection++; @@ -414,7 +414,7 @@ static u8 TextSpeed_ProcessInput(u8 selection) sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; @@ -451,7 +451,7 @@ static void TextSpeed_DrawChoices(u8 selection) static u8 BattleScene_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; sArrowPressed = TRUE; @@ -474,7 +474,7 @@ static void BattleScene_DrawChoices(u8 selection) static u8 BattleStyle_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; sArrowPressed = TRUE; @@ -497,7 +497,7 @@ static void BattleStyle_DrawChoices(u8 selection) static u8 Sound_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; SetPokemonCryStereo(selection); @@ -521,7 +521,7 @@ static void Sound_DrawChoices(u8 selection) static u8 FrameType_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection < WINDOW_FRAMES_COUNT - 1) selection++; @@ -532,7 +532,7 @@ static u8 FrameType_ProcessInput(u8 selection) LoadPalette(GetWindowFrameTilesPal(selection)->pal, 0x70, 0x20); sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; @@ -579,7 +579,7 @@ static void FrameType_DrawChoices(u8 selection) static u8 ButtonMode_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection <= 1) selection++; @@ -588,7 +588,7 @@ static u8 ButtonMode_ProcessInput(u8 selection) sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; diff --git a/src/overworld.c b/src/overworld.c index 223e6e152..3c6dcf8f5 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2453,19 +2453,20 @@ static void UpdateHeldKeyCode(u16 key) static u16 KeyInterCB_ReadButtons(u32 key) { - if (JOY_HELD(DPAD_UP)) + if (gMain.heldKeys & DPAD_UP) return LINK_KEY_CODE_DPAD_UP; - if (JOY_HELD(DPAD_DOWN)) + else if (gMain.heldKeys & DPAD_DOWN) return LINK_KEY_CODE_DPAD_DOWN; - if (JOY_HELD(DPAD_LEFT)) + else if (gMain.heldKeys & DPAD_LEFT) return LINK_KEY_CODE_DPAD_LEFT; - if (JOY_HELD(DPAD_RIGHT)) + else if (gMain.heldKeys & DPAD_RIGHT) return LINK_KEY_CODE_DPAD_RIGHT; - if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) return LINK_KEY_CODE_START_BUTTON; - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) return LINK_KEY_CODE_A_BUTTON; - return LINK_KEY_CODE_EMPTY; + else + return LINK_KEY_CODE_EMPTY; } static u16 GetDirectionForDpadKey(u16 a1) @@ -2572,7 +2573,7 @@ static u16 sub_8087170(u32 keyOrPlayerId) { if (sPlayerTradingStates[keyOrPlayerId] == PLAYER_TRADING_STATE_UNK_2) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { SetKeyInterceptCallback(KeyInterCB_DoNothingAndKeepAlive); return LINK_KEY_CODE_UNK_7; @@ -3187,7 +3188,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(objEvent->previousElevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation); - if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) + if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte)); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte)); diff --git a/src/party_menu.c b/src/party_menu.c index 1d4952375..6e22fa542 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1410,7 +1410,7 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) break; } - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) return 8; if (movementDir) @@ -1420,10 +1420,10 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) } // Pressed Cancel - if ((JOY_NEW(A_BUTTON)) && *slotPtr == PARTY_SIZE + 1) + if ((gMain.newKeys & A_BUTTON) && *slotPtr == PARTY_SIZE + 1) return 2; - return JOY_NEW(A_BUTTON | B_BUTTON); + return gMain.newKeys & (A_BUTTON | B_BUTTON); } static void UpdateCurrentPartySelection(s8 *slotPtr, s8 movementDir) @@ -1861,7 +1861,7 @@ u8 GetMonAilment(struct Pokemon *mon) static void SetPartyMonsAllowedInMinigame(void) { - s16 *ptr; + u16 *ptr; if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { @@ -3764,7 +3764,7 @@ static u16 GetFieldMoveMonSpecies(void) static void Task_CancelAfterAorBPress(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) CursorCb_Cancel1(taskId); } @@ -4721,7 +4721,7 @@ static void Task_DoLearnedMoveFanfareAfterText(u8 taskId) static void Task_LearnNextMoveOrClosePartyMenu(u8 taskId) { - if (IsFanfareTaskInactive() && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (IsFanfareTaskInactive() && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { if (gPartyMenu.learnMoveState == 1) Task_TryLearningNextMove(taskId); @@ -4930,7 +4930,7 @@ static void UpdateMonDisplayInfoAfterRareCandy(u8 slot, struct Pokemon *mon) static void Task_DisplayLevelUpStatsPg1(u8 taskId) { - if (WaitFanfare(FALSE) && IsPartyMenuTextPrinterActive() != TRUE && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (WaitFanfare(FALSE) && IsPartyMenuTextPrinterActive() != TRUE && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { PlaySE(SE_SELECT); DisplayLevelUpStatsPg1(taskId); @@ -4940,7 +4940,7 @@ static void Task_DisplayLevelUpStatsPg1(u8 taskId) static void Task_DisplayLevelUpStatsPg2(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); DisplayLevelUpStatsPg2(taskId); @@ -4950,9 +4950,9 @@ static void Task_DisplayLevelUpStatsPg2(u8 taskId) static void DisplayLevelUpStatsPg1(u8 taskId) { - u16 *arrayPtr = (u16*)sPartyMenuInternal->data; + s16 *arrayPtr = sPartyMenuInternal->data; - arrayPtr[12] = (u16)CreateLevelUpStatsWindow(); + arrayPtr[12] = CreateLevelUpStatsWindow(); DrawLevelUpWindowPg1(arrayPtr[12], arrayPtr, &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); ScheduleBgCopyTilemapToVram(2); @@ -4960,7 +4960,7 @@ static void DisplayLevelUpStatsPg1(u8 taskId) static void DisplayLevelUpStatsPg2(u8 taskId) { - u16 *arrayPtr = (u16 *)sPartyMenuInternal->data; + s16 *arrayPtr = sPartyMenuInternal->data; DrawLevelUpWindowPg2(arrayPtr[12], &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); @@ -4971,7 +4971,7 @@ static void Task_TryLearnNewMoves(u8 taskId) { u16 learnMove; - if (WaitFanfare(0) && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (WaitFanfare(0) && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { RemoveLevelUpStatsWindow(); learnMove = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], TRUE); @@ -5608,7 +5608,7 @@ static void Task_ValidateChosenHalfParty(u8 taskId) static void Task_ContinueChoosingHalfParty(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); DisplayPartyMenuStdMessage(PARTY_MSG_CHOOSE_MON); diff --git a/src/player_pc.c b/src/player_pc.c index 238424ee3..fc0bd9f4c 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -327,7 +327,7 @@ void PlayerPC(void) static void InitPlayerPCMenu(u8 taskId) { - s16 *data; + u16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -346,7 +346,7 @@ static void InitPlayerPCMenu(u8 taskId) static void PlayerPCProcessMenuInput(u8 taskId) { - s16 *data; + u16 *data; s8 inputOptionId; data = gTasks[taskId].data; @@ -435,7 +435,7 @@ static void PlayerPC_TurnOff(u8 taskId) static void InitItemStorageMenu(u8 taskId, u8 var) { - s16 *data; + u16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -548,7 +548,7 @@ static void ItemStorage_Toss(u8 taskId) static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) { - s16 *data = gTasks[taskId].data; + u16 *data = gTasks[taskId].data; data[3] = toss; sub_816B4DC(taskId); @@ -581,9 +581,9 @@ static void ItemStorage_SetItemAndMailCount(u8 taskId) static void sub_816B4DC(u8 taskId) { - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent((u8)data[4], FALSE); + ClearStdWindowAndFrameToTransparent(data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); ScheduleBgCopyTilemapToVram(0); @@ -1134,7 +1134,7 @@ static void ItemStorage_ProcessInput(u8 taskId) s32 id; data = gTasks[taskId].data; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); if ((playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos) != (playerPCItemPageInfo.count - 1)) @@ -1212,7 +1212,7 @@ static void sub_816C4FC(u8 taskId) s32 id; data = gTasks[taskId].data; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); ItemStorage_DoItemSwap(taskId, FALSE); @@ -1227,7 +1227,7 @@ static void sub_816C4FC(u8 taskId) case LIST_NOTHING_CHOSEN: break; case LIST_CANCEL: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { ItemStorage_DoItemSwap(taskId, FALSE); } @@ -1332,7 +1332,7 @@ static void ItemStorage_HandleQuantityRolling(u8 taskId) sub_816C6BC(sub_816BC7C(4), data[2], STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sub_816BCC4(4); @@ -1341,7 +1341,7 @@ static void ItemStorage_HandleQuantityRolling(u8 taskId) else ItemStorage_DoItemToss(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_816BCC4(4); @@ -1380,7 +1380,7 @@ static void ItemStorage_DoItemToss(u8 taskId) data = gTasks[taskId].data; b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId) == 0) + if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) { CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); @@ -1412,7 +1412,7 @@ static void ItemStorage_HandleRemoveItem(u8 taskId) s16 *data; data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { RemovePCItem((playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove), data[2]); DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); @@ -1429,7 +1429,7 @@ static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId) s16 *data; data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(gSaveBlock1Ptr->pcItems[(playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos)].itemId)); ItemStorage_StartScrollIndicatorAndProcessInput(taskId); diff --git a/src/pokeblock.c b/src/pokeblock.c index b44112b88..11fe83240 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -430,7 +430,7 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate = // code void OpenPokeblockCase(u8 caseId, void (*callback)(void)) { - sPokeblockMenu = Alloc(sizeof(struct PokeblockMenuStruct)); + sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu)); sPokeblockMenu->caseId = caseId; sPokeblockMenu->callbackOnUse = NULL; sPokeblockMenu->unkTaskId = 0xFF; @@ -984,7 +984,7 @@ static void Task_HandlePokeblockMenuInput(u8 taskId) if (!gPaletteFade.active && MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1) @@ -1035,7 +1035,7 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) if (MenuHelpers_CallLinkSomething() == TRUE) return; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); @@ -1069,7 +1069,7 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) break; case LIST_CANCEL: // same id as STOW CASE field PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) HandlePokeblocksSwap(taskId, FALSE); else HandlePokeblocksSwap(taskId, TRUE); @@ -1193,7 +1193,7 @@ static void TossPokeblockChoice_Yes(u8 taskId) static void HandleErasePokeblock(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { s16 *data; u16 *lastPage, *lastPos; diff --git a/src/pokedex.c b/src/pokedex.c index 803b6019c..c5d7d2730 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -171,16 +171,16 @@ struct PokedexView u16 ownCount; u16 monSpriteIds[MAX_MONS_ON_SCREEN]; u16 selectedMonSpriteId; - s16 pokeBallRotationStep; - s16 pokeBallRotationBackup; + u16 pokeBallRotationStep; + u16 pokeBallRotationBackup; u8 pokeBallRotation; u8 initialVOffset; u8 scrollTimer; u8 scrollDirection; s16 listVOffset; s16 listMovingVOffset; - s16 scrollMonIncrement; - s16 maxScrollTimer; + u16 scrollMonIncrement; + u16 maxScrollTimer; u16 scrollSpeed; u16 unkArr1[4]; // Cleared, never read u8 filler[8]; @@ -1672,7 +1672,7 @@ static void Task_HandlePokedexInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { UpdateSelectedMonSpriteId(); BeginNormalPaletteFade(~(1 << (gSprites[sPokedexView->selectedMonSpriteId].oam.paletteNum + 16)), 0, 0, 0x10, RGB_BLACK); @@ -1681,7 +1681,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1689,7 +1689,7 @@ static void Task_HandlePokedexInput(u8 taskId) gTasks[taskId].func = Task_HandlePokedexStartMenuInput; PlaySE(SE_SELECT); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); @@ -1703,7 +1703,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ClosePokedex; @@ -1736,7 +1736,7 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->menuCursorPos) { @@ -1767,18 +1767,18 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandlePokedexInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos != 0) + else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos != 0) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 3) + else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 3) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -1872,7 +1872,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { u32 a; @@ -1884,7 +1884,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1892,7 +1892,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) gTasks[taskId].func = Task_HandleSearchResultsStartMenuInput; PlaySE(SE_SELECT); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].tTaskId = LoadSearchMenu(); @@ -1901,7 +1901,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ReturnToPokedexFromSearchResults; @@ -1933,7 +1933,7 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->menuCursorPos) { @@ -1969,18 +1969,18 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandleSearchResultsInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos) + else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 4) + else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 4) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -2059,10 +2059,10 @@ static bool8 LoadPokedexListPage(u8 page) SetGpuReg(REG_OFFSET_BG2VOFS, sPokedexView->initialVOffset); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sPokedex_BgTemplate, ARRAY_COUNT(sPokedex_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(1, gPokedexList_Tilemap, 0, 0); CopyToBgTilemapBuffer(3, gPokedexListUnderlay_Tilemap, 0, 0); @@ -2589,7 +2589,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) u16 startingPos; u8 scrollDir = 0; - if ((JOY_HELD(DPAD_UP)) && (selectedMon > 0)) + if ((gMain.heldKeys & DPAD_UP) && (selectedMon > 0)) { scrollDir = 1; selectedMon = GetNextPosition(1, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2597,7 +2597,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(1, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if (JOY_HELD(DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((gMain.heldKeys & DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) { scrollDir = 2; selectedMon = GetNextPosition(0, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2605,7 +2605,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(2, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if (JOY_NEW(DPAD_LEFT) && (selectedMon > 0)) + else if ((gMain.newKeys & DPAD_LEFT) && (selectedMon > 0)) { startingPos = selectedMon; @@ -2616,7 +2616,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonSpritesAtPos(selectedMon, 0xE); PlaySE(SE_DEX_PAGE); } - else if ((JOY_NEW(DPAD_RIGHT)) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((gMain.newKeys & DPAD_RIGHT) && (selectedMon < sPokedexView->pokemonListCount - 1)) { startingPos = selectedMon; for (i = 0; i < 7; i++) @@ -2665,7 +2665,7 @@ static bool8 TryDoInfoScreenScroll(void) u16 nextPokemon; u16 selectedPokemon = sPokedexView->selectedPokemon; - if ((JOY_NEW(DPAD_UP)) && selectedPokemon) + if ((gMain.newKeys & DPAD_UP) && selectedPokemon) { nextPokemon = selectedPokemon; while (nextPokemon != 0) @@ -2688,7 +2688,7 @@ static bool8 TryDoInfoScreenScroll(void) return TRUE; } } - else if ((JOY_NEW(DPAD_DOWN)) && selectedPokemon < sPokedexView->pokemonListCount - 1) + else if ((gMain.newKeys & DPAD_DOWN) && selectedPokemon < sPokedexView->pokemonListCount - 1) { nextPokemon = selectedPokemon; while (nextPokemon < sPokedexView->pokemonListCount - 1) @@ -3185,10 +3185,10 @@ static u8 LoadInfoScreen(struct PokedexListItem* item, u8 monSpriteId) gTasks[taskId].data[5] = 255; ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sInfoScreen_BgTemplate, ARRAY_COUNT(sInfoScreen_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); InitWindows(sInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); @@ -3355,14 +3355,14 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_SCROLL); return; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_ExitInfoScreen; PlaySE(SE_PC_OFF); return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->selectedScreen) { @@ -3399,8 +3399,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT) - || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen > 0) { sPokedexView->selectedScreen--; @@ -3408,8 +3408,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if ((JOY_NEW(DPAD_RIGHT) - || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((gMain.newKeys & DPAD_RIGHT) + || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen < CANCEL_SCREEN) { sPokedexView->selectedScreen++; @@ -3629,7 +3629,7 @@ static void Task_HandleCryScreenInput(u8 taskId) else LoadPlayArrowPalette(FALSE); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { LoadPlayArrowPalette(TRUE); CryScreenPlayButton(NationalPokedexNumToSpecies(sPokedexListItem->dexNum)); @@ -3637,7 +3637,7 @@ static void Task_HandleCryScreenInput(u8 taskId) } else if (!gPaletteFade.active) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3646,8 +3646,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_PC_OFF); return; } - if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3656,8 +3656,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if (JOY_NEW(DPAD_RIGHT) - || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((gMain.newKeys & DPAD_RIGHT) + || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { if (!sPokedexListItem->owned) { @@ -3809,15 +3809,15 @@ static void Task_LoadSizeScreen(u8 taskId) static void Task_HandleSizeScreenInput(u8 taskId) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 1; gTasks[taskId].func = Task_SwitchScreensFromSizeScreen; PlaySE(SE_PC_OFF); } - else if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if ((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 2; @@ -3950,8 +3950,8 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) ResetOtherVideoRegisters(DISPCNT_BG0_ON); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sNewEntryInfoScreen_BgTemplate, ARRAY_COUNT(sNewEntryInfoScreen_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); InitWindows(sNewEntryInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); gTasks[taskId].tState = 1; @@ -4009,7 +4009,7 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) static void Task_HandleCaughtMonPageInput(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0x0000FFFF, 0, 0, 16, RGB_BLACK); gSprites[gTasks[taskId].tMonSpriteId].callback = SpriteCB_SlideCaughtMonToCenter; @@ -4167,13 +4167,12 @@ static void PrintMonHeight(u16 height, u8 left, u8 top) static void PrintMonWeight(u16 weight, u8 left, u8 top) { u8 buffer[16]; - u8 i; bool8 output; + u8 i; u32 lbs = (weight * 100000) / 4536; if (lbs % 10u >= 5) lbs += 10; - i = 0; output = FALSE; @@ -4228,19 +4227,13 @@ const u8 *GetPokedexCategoryName(u16 dexNum) // unused return gPokedexEntries[dexNum].categoryName; } -enum -{ - HEIGHT, - WEIGHT, -}; - u16 GetPokedexHeightWeight(u16 dexNum, u8 data) { switch (data) { - case HEIGHT: + case 0: // height return gPokedexEntries[dexNum].height; - case WEIGHT: + case 1: // weight return gPokedexEntries[dexNum].weight; default: return 1; @@ -4818,10 +4811,10 @@ static void Task_LoadSearchMenu(u8 taskId) ResetOtherVideoRegisters(0); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sSearchMenu_BgTemplate, ARRAY_COUNT(sSearchMenu_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); InitWindows(sSearchMenu_WindowTemplate); DeactivateAllTextPrinters(); PutWindowTilemap(0); @@ -4905,13 +4898,13 @@ static void Task_SwitchToSearchMenuTopBar(u8 taskId) static void Task_HandleSearchTopBarInput(u8 taskId) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); gTasks[taskId].func = Task_ExitSearch; return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (gTasks[taskId].tTopBarItem) { @@ -4932,7 +4925,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT)) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) + if ((gMain.newKeys & DPAD_LEFT) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem--; @@ -4940,7 +4933,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_RIGHT)) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) + if ((gMain.newKeys & DPAD_RIGHT) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem++; @@ -4979,14 +4972,14 @@ static void Task_HandleSearchMenuInput(u8 taskId) movementMap = sSearchMovementMap_SearchNatDex; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_BALL); SetDefaultSearchModeAndOrder(taskId); gTasks[taskId].func = Task_SwitchToSearchMenuTopBar; return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].tMenuItem == SEARCH_OK) { @@ -5021,7 +5014,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) return; } - if ((JOY_NEW(DPAD_LEFT)) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) + if ((gMain.newKeys & DPAD_LEFT) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][0]; @@ -5029,7 +5022,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if (JOY_NEW(DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) + if ((gMain.newKeys & DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][1]; @@ -5037,7 +5030,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_UP)) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) + if ((gMain.newKeys & DPAD_UP) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][2]; @@ -5045,7 +5038,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_DOWN)) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) + if ((gMain.newKeys & DPAD_DOWN) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][3]; @@ -5089,7 +5082,7 @@ static void Task_WaitAndCompleteSearch(u8 taskId) static void Task_SearchCompleteWaitForInput(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sPokedexView->pokemonListCount != 0) { @@ -5115,9 +5108,9 @@ static void Task_SelectSearchMenuItem(u8 taskId) u16 *scrollOffset; DrawOrEraseSearchParameterBox(FALSE); - menuItem = (u16)gTasks[taskId].tMenuItem; - cursorPos = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; - scrollOffset = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; + menuItem = gTasks[taskId].tMenuItem; + cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; + scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; gTasks[taskId].tCursorPos = *cursorPos; gTasks[taskId].tScrollOffset = *scrollOffset; PrintSearchParameterText(taskId); @@ -5142,7 +5135,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; maxOption = sSearchOptions[menuItem].numOptions - 1; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_PIN); ClearSearchParameterBoxText(); @@ -5152,7 +5145,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) CopyBgTilemapBufferToVram(3); return; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_BALL); ClearSearchParameterBoxText(); @@ -5165,7 +5158,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) return; } moved = FALSE; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (*cursorPos != 0) { @@ -5191,7 +5184,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) } return; } - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (*cursorPos < MAX_SEARCH_PARAM_CURSOR_POS && *cursorPos < maxOption) { @@ -5236,8 +5229,9 @@ static void Task_ExitSearchWaitForFade(u8 taskId) void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) { - u16 i, temp; //This would have been better as a pointer but here we are - u32 ptr = (u32)GetBgTilemapBuffer(3); //This should be a pointer, but this only matches as a u32. + u16 i; + u16 temp; //should be a pointer, but does not match as one + u32 ptr = (u32)GetBgTilemapBuffer(3); //same as above for (i = 0; i < width; i++) { @@ -5245,7 +5239,7 @@ void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) temp &= 0x0fff; temp |= (flags << 12); *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2) = temp; - + temp = *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2); temp &= 0x0fff; temp |= (flags << 12); @@ -5451,8 +5445,8 @@ static void PrintSearchParameterText(u8 taskId) const struct SearchOptionText *texts = sSearchOptions[gTasks[taskId].tMenuItem].texts; const u16 *cursorPos = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataCursorPos]; const u16 *scrollOffset = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataScrollOffset]; - - u16 i, j; + u16 i; + u16 j; ClearSearchParameterBoxText(); @@ -5541,7 +5535,8 @@ static bool8 SearchParamCantScrollUp(u8 taskId) if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset != 0) return FALSE; - return TRUE; + else + return TRUE; } static bool8 SearchParamCantScrollDown(u8 taskId) @@ -5552,7 +5547,8 @@ static bool8 SearchParamCantScrollDown(u8 taskId) if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset < lastOption - MAX_SEARCH_PARAM_CURSOR_POS) return FALSE; - return TRUE; + else + return TRUE; } #define sTaskId data[0] diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index 7a3b38dc2..cfd5e67e4 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -723,12 +723,12 @@ static void Task_HandlePokedexAreaScreenInput(u8 taskId) return; break; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gTasks[taskId].data[1] = 1; PlaySE(SE_PC_OFF); } - else if (JOY_NEW(DPAD_RIGHT) || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if (gMain.newKeys & DPAD_RIGHT || (gMain.newKeys & R_BUTTON && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { gTasks[taskId].data[1] = 2; PlaySE(SE_DEX_PAGE); diff --git a/src/pokemon.c b/src/pokemon.c index 8767207d7..3621284d6 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -69,7 +69,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0; EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0}; EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0}; -EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL, NULL}; +EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL}; // const rom data #include "data/battle_moves.h" @@ -5750,7 +5750,7 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId) u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) { u16 retVal; - // Dont modify HP, Accuracy, or Evasion by nature + // Don't modify HP, Accuracy, or Evasion by nature if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS) { return n; @@ -6811,8 +6811,6 @@ static bool8 ShouldSkipFriendshipChange(void) return FALSE; } -#define MAGIC_NUMBER 0xA3 - static void sub_806F160(struct Unknown_806F160_Struct* structPtr) { u16 i, j; @@ -6861,7 +6859,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) structPtr->field_0_0 = 7; structPtr->field_0_1 = 7; structPtr->field_1 = 4; - structPtr->size = 1; + structPtr->field_3_0 = 1; structPtr->field_3_1 = 2; break; case 0: @@ -6869,12 +6867,12 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) structPtr->field_0_0 = 4; structPtr->field_0_1 = 4; structPtr->field_1 = 4; - structPtr->size = 1; + structPtr->field_3_0 = 1; structPtr->field_3_1 = 0; break; } - structPtr->bytes = AllocZeroed(structPtr->size * 0x800 * 4 * structPtr->field_0_0); + structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0); structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32); if (structPtr->bytes == NULL || structPtr->byteArrays == NULL) { @@ -6883,7 +6881,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) else { for (i = 0; i < structPtr->field_0_0; i++) - structPtr->byteArrays[i] = structPtr->bytes + (structPtr->size * (i << 0xD)); + structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD)); } structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0); @@ -6902,8 +6900,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) case 2: sub_806F1FC(structPtr); break; - case 1: case 0: + case 1: default: sub_806F160(structPtr); break; @@ -6932,7 +6930,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) } else { - structPtr->magic = MAGIC_NUMBER; + structPtr->magic = 0xA3; gUnknown_020249B4[id] = structPtr; } @@ -6943,12 +6941,12 @@ void sub_806F47C(u8 id) { struct Unknown_806F160_Struct *structPtr; - id &= 1; + id %= 2; structPtr = gUnknown_020249B4[id]; if (structPtr == NULL) return; - if (structPtr->magic != MAGIC_NUMBER) + if (structPtr->magic != 0xA3) { memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct)); } @@ -6972,13 +6970,15 @@ void sub_806F47C(u8 id) u8 *sub_806F4F8(u8 id, u8 arg1) { struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2]; - if (structPtr->magic != MAGIC_NUMBER) + if (structPtr->magic != 0xA3) { return NULL; } - - if (arg1 >= structPtr->field_0_0) - arg1 = 0; + else + { + if (arg1 >= structPtr->field_0_0) + arg1 = 0; - return structPtr->byteArrays[arg1]; + return structPtr->byteArrays[arg1]; + } } diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c index f69bccb99..bfcf77b5c 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -2883,10 +2883,9 @@ static void sub_8181C2C(struct Sprite *sprite) } else { + s32 var = sUnknown_03001240[sprite->data[0]].field_8; - const s16 var = sUnknown_03001240[sprite->data[0]].field_8; - - sprite->pos2.x = var * ((counter % 128) * 8) / 128 + 8 * -var; //Should be - 8 * var instead of + 8 * -var, but that doesn't match + sprite->pos2.x = var * ((counter % 128) * 8) / 128 + 8 * -var; sprite->pos2.y = -(Sin(counter % 128, 8)); } diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index b6c557cab..d54275940 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -405,7 +405,7 @@ void StartPokemonJump(u16 partyIndex, MainCallback callback) if (gReceivedRemoteLinkPlayers) { - gUnknown_02022CFC = Alloc(sizeof(struct PokemonJump1)); + gUnknown_02022CFC = Alloc(sizeof(*gUnknown_02022CFC)); if (gUnknown_02022CFC) { ResetTasks(); @@ -1244,7 +1244,7 @@ static bool32 sub_802B8CC(void) break; // fall through case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_802C164(); sub_802AE14(3); @@ -1335,7 +1335,7 @@ static bool32 sub_802BA58(void) case 2: case 5: gUnknown_02022CFC->unk3C++; - if (JOY_NEW(A_BUTTON | B_BUTTON) || gUnknown_02022CFC->unk3C > 180) + if (gMain.newKeys & (A_BUTTON | B_BUTTON) || gUnknown_02022CFC->unk3C > 180) { sub_802DA14(); gUnknown_02022CFC->unkA++; @@ -3921,7 +3921,7 @@ static void Task_ShowPokemonJumpRecords(u8 taskId) data[0]++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { rbox_fill_rectangle(data[1]); CopyWindowToVram(data[1], 1); diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 4db9fbf92..11c56706a 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1755,10 +1755,10 @@ static void Task_PokemonStorageSystemPC(u8 taskId) { case MENU_NOTHING_CHOSEN: task->data[3] = task->data[1]; - if (JOY_NEW(DPAD_UP) && --task->data[3] < 0) + if (gMain.newKeys & DPAD_UP && --task->data[3] < 0) task->data[3] = 4; - if (JOY_NEW(DPAD_DOWN) && ++task->data[3] > 4) + if (gMain.newKeys & DPAD_DOWN && ++task->data[3] > 4) task->data[3] = 0; if (task->data[1] != task->data[3]) { @@ -1797,13 +1797,13 @@ static void Task_PokemonStorageSystemPC(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (--task->data[1] < 0) task->data[1] = 4; @@ -1813,7 +1813,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (++task->data[1] > 3) task->data[1] = 0; @@ -1975,22 +1975,22 @@ static void sub_80C78E4(void) static u8 HandleBoxChooseSelectionInput(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); return 201; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return gUnknown_02039D04->curBox; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { PlaySE(SE_SELECT); sub_80C7BB4(); } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { PlaySE(SE_SELECT); sub_80C7B80(); @@ -2156,7 +2156,7 @@ static void Cb2_EnterPSS(u8 boxOption) { ResetTasks(); sCurrentBoxOption = boxOption; - sPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); + sPSSData = Alloc(sizeof(*sPSSData)); if (sPSSData == NULL) { SetMainCallback2(Cb2_ExitPSS); @@ -2176,7 +2176,7 @@ static void Cb2_EnterPSS(u8 boxOption) static void Cb2_ReturnToPSS(void) { ResetTasks(); - sPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); + sPSSData = Alloc(sizeof(*sPSSData)); if (sPSSData == NULL) { SetMainCallback2(Cb2_ExitPSS); @@ -2392,7 +2392,7 @@ static void Cb_ReshowPSS(u8 taskId) } break; case 2: - if (!IsDma3ManagerBusyWithBgCopy() && JOY_NEW(A_BUTTON | B_BUTTON)) + if (!IsDma3ManagerBusyWithBgCopy() && gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearBottomWindow(); sPSSData->state++; @@ -2614,7 +2614,7 @@ static void Cb_MainPSS(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state = 0; @@ -2631,7 +2631,7 @@ static void Cb_MainPSS(u8 taskId) sPSSData->state = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -2857,7 +2857,7 @@ static void Cb_OnSelectedMon(u8 taskId) sPSSData->state = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -2942,7 +2942,7 @@ static void Cb_WithdrawMon(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3033,7 +3033,7 @@ static void Cb_DepositMenu(u8 taskId) } break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); sPSSData->state = 1; @@ -3094,14 +3094,14 @@ static void Cb_ReleaseMon(u8 taskId) sPSSData->state++; break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_BYE_BYE); sPSSData->state++; } break; case 5: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); if (sInPartyMenu) @@ -3133,14 +3133,14 @@ static void Cb_ReleaseMon(u8 taskId) sPSSData->state++; break; case 9: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_SURPRISE); sPSSData->state++; } break; case 10: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sub_80CC064(); @@ -3156,14 +3156,14 @@ static void Cb_ReleaseMon(u8 taskId) } break; case 12: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_WORRIED); sPSSData->state++; } break; case 13: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3256,7 +3256,7 @@ static void Cb_GiveMovingItemToMon(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3295,7 +3295,7 @@ static void Cb_ItemToBag(u8 taskId) } break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sub_80CE00C(); @@ -3308,7 +3308,7 @@ static void Cb_ItemToBag(u8 taskId) SetPSSCallback(Cb_MainPSS); break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3348,7 +3348,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3387,7 +3387,7 @@ static void Cb_ShowItemInfo(u8 taskId) sPSSData->state++; break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PlaySE(SE_WIN_OPEN); sPSSData->state++; @@ -3437,7 +3437,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) } break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state = 5; @@ -3493,7 +3493,7 @@ static void Cb_PrintCantStoreMail(u8 taskId) sPSSData->state++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3758,7 +3758,7 @@ static void Cb_OnCloseBoxPressed(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3819,7 +3819,7 @@ static void Cb_OnBPressed(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -5461,7 +5461,7 @@ static void sub_80CCA3C(const void *tilemap, s8 direction, u8 arg2) if (direction == 0) return; - if (direction > 0) + else if (direction > 0) x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference else x -= 4; @@ -6939,7 +6939,7 @@ static u8 InBoxInput_Normal(void) sPSSData->field_CD3 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = TRUE; if (sBoxCursorPosition >= IN_BOX_ROWS) @@ -6953,7 +6953,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { retVal = TRUE; cursorPosition += IN_BOX_ROWS; @@ -6967,7 +6967,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { retVal = TRUE; if (sBoxCursorPosition % IN_BOX_ROWS != 0) @@ -6981,7 +6981,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { retVal = TRUE; if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) @@ -6995,7 +6995,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { retVal = TRUE; cursorArea = CURSOR_AREA_BOX; @@ -7003,7 +7003,7 @@ static u8 InBoxInput_Normal(void) break; } - if ((JOY_NEW(A_BUTTON)) && sub_80CFA5C()) + if ((gMain.newKeys & A_BUTTON) && sub_80CFA5C()) { if (!sCanOnlyMove) return 8; @@ -7037,18 +7037,18 @@ static u8 InBoxInput_Normal(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7066,9 +7066,9 @@ static u8 InBoxInput_Normal(void) static u8 InBoxInput_GrabbingMultiple(void) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sBoxCursorPosition / IN_BOX_ROWS != 0) { @@ -7080,7 +7080,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT) { @@ -7092,7 +7092,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sBoxCursorPosition % IN_BOX_ROWS != 0) { @@ -7104,7 +7104,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) { @@ -7141,7 +7141,7 @@ static u8 InBoxInput_GrabbingMultiple(void) static u8 InBoxInput_MovingMultiple(void) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sub_80D0580(0)) { @@ -7153,7 +7153,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sub_80D0580(1)) { @@ -7165,7 +7165,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sub_80D0580(2)) { @@ -7177,7 +7177,7 @@ static u8 InBoxInput_MovingMultiple(void) return 10; } } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sub_80D0580(3)) { @@ -7189,7 +7189,7 @@ static u8 InBoxInput_MovingMultiple(void) return 9; } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sub_80D0BC0()) { @@ -7202,7 +7202,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return 24; } @@ -7210,9 +7210,9 @@ static u8 InBoxInput_MovingMultiple(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } @@ -7237,7 +7237,7 @@ static u8 HandleInput_InParty(void) gotoBox = FALSE; retVal = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (--cursorPosition < 0) cursorPosition = PARTY_SIZE; @@ -7245,7 +7245,7 @@ static u8 HandleInput_InParty(void) retVal = 1; break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (++cursorPosition > PARTY_SIZE) cursorPosition = 0; @@ -7253,14 +7253,14 @@ static u8 HandleInput_InParty(void) retVal = 1; break; } - else if (JOY_REPEAT(DPAD_LEFT) && sBoxCursorPosition != 0) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT && sBoxCursorPosition != 0) { retVal = 1; sPSSData->field_CD6 = sBoxCursorPosition; cursorPosition = 0; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sBoxCursorPosition == 0) { @@ -7276,7 +7276,7 @@ static u8 HandleInput_InParty(void) break; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sBoxCursorPosition == PARTY_SIZE) { @@ -7312,7 +7312,7 @@ static u8 HandleInput_InParty(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (sPSSData->boxOption == BOX_OPTION_DEPOSIT) return 19; @@ -7326,7 +7326,7 @@ static u8 HandleInput_InParty(void) cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7355,7 +7355,7 @@ static u8 HandleInput_OnBox(void) sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; cursorArea = CURSOR_AREA_BUTTONS; @@ -7363,7 +7363,7 @@ static u8 HandleInput_OnBox(void) sPSSData->field_CD7 = 1; break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { retVal = 1; cursorArea = CURSOR_AREA_IN_BOX; @@ -7371,30 +7371,30 @@ static u8 HandleInput_OnBox(void) break; } - if (JOY_HELD(DPAD_LEFT)) + if (gMain.heldKeys & DPAD_LEFT) return 10; - if (JOY_HELD(DPAD_RIGHT)) + if (gMain.heldKeys & DPAD_RIGHT) return 9; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_80CD1A8(FALSE); AddBoxMenu(); return 7; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7428,7 +7428,7 @@ static u8 HandleInput_OnButtons(void) sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; cursorArea = CURSOR_AREA_IN_BOX; @@ -7440,8 +7440,7 @@ static u8 HandleInput_OnButtons(void) sPSSData->field_CD7 = 1; break; } - - if (JOY_REPEAT(DPAD_DOWN | START_BUTTON)) + else if (gMain.newAndRepeatedKeys & (DPAD_DOWN | START_BUTTON)) { retVal = 1; cursorArea = CURSOR_AREA_BOX; @@ -7450,14 +7449,14 @@ static u8 HandleInput_OnButtons(void) break; } - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) { retVal = 1; if (--cursorPosition < 0) cursorPosition = 1; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { retVal = 1; if (++cursorPosition > 1) @@ -7465,12 +7464,12 @@ static u8 HandleInput_OnButtons(void) break; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return (cursorPosition == 0) ? 5 : 4; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7919,23 +7918,23 @@ static s16 sub_80D00AC(void) do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { textId = Menu_GetCursorPos(); break; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); textId = -1; } - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 012e133e6..8ea25295c 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1496,23 +1496,23 @@ static void Task_HandleInput(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { ChangeSummaryPokemon(taskId, -1); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { ChangeSummaryPokemon(taskId, 1); } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if ((gMain.newKeys & DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) { ChangePage(taskId, -1); } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if ((gMain.newKeys & DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) { ChangePage(taskId, 1); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_SKILLS) { @@ -1529,7 +1529,7 @@ static void Task_HandleInput(u8 taskId) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StopPokemonAnimations(); PlaySE(SE_SELECT); @@ -1877,17 +1877,17 @@ static void Task_HandleInput_MoveSelect(u8 taskId) if (MenuHelpers_CallLinkSomething() != 1) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 4; ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->lockMovesFlag == TRUE || (sMonSummaryScreen->newMove == MOVE_NONE && sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES)) @@ -1905,7 +1905,7 @@ static void Task_HandleInput_MoveSelect(u8 taskId) PlaySE(SE_FAILURE); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseMoveSelectMode(taskId); @@ -2017,24 +2017,24 @@ static void Task_HandleInput_MovePositionSwitch(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 3; ChangeSelectedMove(&data[0], -1, &sMonSummaryScreen->secondMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 3; ChangeSelectedMove(&data[0], 1, &sMonSummaryScreen->secondMoveIndex); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->firstMoveIndex == sMonSummaryScreen->secondMoveIndex) ExitMovePositionSwitchMode(taskId, FALSE); else ExitMovePositionSwitchMode(taskId, TRUE); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { ExitMovePositionSwitchMode(taskId, FALSE); } @@ -2160,25 +2160,25 @@ static void Task_HandleReplaceMoveInput(u8 taskId) { if (gPaletteFade.active != TRUE) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 4; ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { ChangePage(taskId, -1); } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { ChangePage(taskId, 1); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (CanReplaceMove() == TRUE) { @@ -2194,7 +2194,7 @@ static void Task_HandleReplaceMoveInput(u8 taskId) ShowCantForgetHMsWindow(taskId); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StopPokemonAnimations(); PlaySE(SE_SELECT); @@ -2234,7 +2234,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) u16 move; if (FuncIsActiveTask(Task_ShowPowerAccWindow) != 1) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[1] = 1; data[0] = 4; @@ -2242,7 +2242,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) data[1] = 0; gTasks[taskId].func = Task_HandleReplaceMoveInput; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[1] = 1; data[0] = 4; @@ -2250,7 +2250,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) data[1] = 0; gTasks[taskId].func = Task_HandleReplaceMoveInput; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES) { @@ -2264,7 +2264,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) HandleAppealJamTilemap(9, -2, move); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) { @@ -2278,7 +2278,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) HandleAppealJamTilemap(9, -2, move); } } - else if (JOY_NEW(A_BUTTON | B_BUTTON)) + else if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) diff --git a/src/pokenav.c b/src/pokenav.c index 9f9cf7dee..eac0c85b4 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -315,7 +315,7 @@ static void Task_RunLoopedTask_LinkMode(u8 taskId) void CB2_InitPokeNav(void) { - gPokenavResources = Alloc(sizeof(struct PokenavResources)); + gPokenavResources = Alloc(sizeof(*gPokenavResources)); if (gPokenavResources == NULL) { SetMainCallback2(CB2_ReturnToFieldWithOpenMenu); @@ -343,7 +343,7 @@ static void CB2_InitPokenavForTutorial(void) if (gPaletteFade.active) return; - gPokenavResources = Alloc(sizeof(struct PokenavResources)); + gPokenavResources = Alloc(sizeof(*gPokenavResources)); if (gPokenavResources == NULL) { SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); diff --git a/src/pokenav_conditions_1.c b/src/pokenav_conditions_1.c index c27cd410c..77d982d85 100644 --- a/src/pokenav_conditions_1.c +++ b/src/pokenav_conditions_1.c @@ -88,13 +88,13 @@ u32 HandlePartyConditionInput(struct PokenavSub11 *structPtr) if (ret == PARTY_CONDITION_FUNC_NONE) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); structPtr->callback = GetConditionReturnCallback; ret = PARTY_CONDITION_FUNC_RETURN; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (structPtr->searchMode == 0) { @@ -165,7 +165,7 @@ u8 ConditionGraphHandleDpadInput(struct PokenavSub11 *structPtr) struct PokenavSub18 *monListPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_MON_LIST); u8 ret = 0; - if (JOY_HELD(DPAD_UP)) + if (gMain.heldKeys & DPAD_UP) { if (structPtr->searchMode == 0 || monListPtr->currIndex != 0) { @@ -173,7 +173,7 @@ u8 ConditionGraphHandleDpadInput(struct PokenavSub11 *structPtr) ret = SwitchConditionSummaryIndex(1); } } - else if (JOY_HELD(DPAD_DOWN)) + else if (gMain.heldKeys & DPAD_DOWN) { if (structPtr->searchMode == 0 || monListPtr->currIndex < monListPtr->listCount - 1) { diff --git a/src/pokenav_conditions_3.c b/src/pokenav_conditions_3.c index 196484df7..f698cbfa6 100644 --- a/src/pokenav_conditions_3.c +++ b/src/pokenav_conditions_3.c @@ -182,28 +182,29 @@ static bool32 HandleConditionSearchInput_WaitSetup(struct PokenavSub7 *structPtr static u32 HandleConditionSearchInput(struct PokenavSub7 *structPtr) { - if (JOY_REPEAT(DPAD_UP)) - return CONDITION_SEARCH_FUNC_MOVE_UP; - if (JOY_REPEAT(DPAD_DOWN)) - return CONDITION_SEARCH_FUNC_MOVE_DOWN; - if (JOY_NEW(DPAD_LEFT)) - return CONDITION_SEARCH_FUNC_PAGE_UP; - if (JOY_NEW(DPAD_RIGHT)) - return CONDITION_SEARCH_FUNC_PAGE_DOWN; - if (JOY_NEW(B_BUTTON)) + if (gMain.newAndRepeatedKeys & DPAD_UP) + return 1; + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) + return 2; + else if (gMain.newKeys & DPAD_LEFT) + return 3; + else if (gMain.newKeys & DPAD_RIGHT) + return 4; + else if (gMain.newKeys & B_BUTTON) { structPtr->isPartyCondition = 0; structPtr->callback = ReturnToConditionSearchList; return CONDITION_SEARCH_FUNC_EXIT; } - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { structPtr->monList->currIndex = GetSelectedPokenavListIndex(); structPtr->isPartyCondition = 1; structPtr->callback = OpenConditionGraphFromSearchList; return CONDITION_SEARCH_FUNC_SELECT_MON; } - return CONDITION_SEARCH_FUNC_NONE; + else + return 0; } static u32 ReturnToConditionSearchList(struct PokenavSub7 *structPtr) diff --git a/src/pokenav_main_menu.c b/src/pokenav_main_menu.c index 806300539..2c35e4b78 100644 --- a/src/pokenav_main_menu.c +++ b/src/pokenav_main_menu.c @@ -436,10 +436,9 @@ static u32 LoopedTask_SlideMenuHeaderDown(s32 a0) if (ChangeBgY(0, 384, 2) <= 0) { ChangeBgY(0, 0, 0); - return LT_FINISH; + return 4; } - - return LT_PAUSE; + return 2; } void CopyPaletteIntoBufferUnfaded(const u16 *palette, u32 bufferOffset, u32 size) @@ -459,9 +458,11 @@ void Pokenav_AllocAndLoadPalettes(const struct SpritePalette *palettes) { break; } - - index = (index * 16) + 0x100; - CopyPaletteIntoBufferUnfaded(current->data, index, 0x20); + else + { + index = (index * 16) + 0x100; + CopyPaletteIntoBufferUnfaded(current->data, index, 0x20); + } } } @@ -681,7 +682,7 @@ static void LoadLeftHeaderGfxForMenu(u32 menuGfxId) size = GetDecompressedDataSize(sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].data); LoadPalette(&gPokenavLeftHeader_Pal[tag * 16], (IndexOfSpritePaletteTag(1) * 16) + 0x100, 0x20); LZ77UnCompWram(sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].data, gDecompressionBuffer); - RequestDma3Copy(gDecompressionBuffer, (void *)OBJ_VRAM0 + (GetSpriteTileStartByTag(2) * 32), size, 1); + RequestDma3Copy(gDecompressionBuffer, (void *)VRAM + 0x10000 + (GetSpriteTileStartByTag(2) * 32), size, 1); structPtr->leftHeaderSprites[1]->oam.tileNum = GetSpriteTileStartByTag(2) + sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].size; if (menuGfxId == POKENAV_GFX_MAP_MENU_ZOOMED_OUT || menuGfxId == POKENAV_GFX_MAP_MENU_ZOOMED_IN) diff --git a/src/pokenav_match_call_1.c b/src/pokenav_match_call_1.c index fb44aaa87..f9ca66f37 100755 --- a/src/pokenav_match_call_1.c +++ b/src/pokenav_match_call_1.c @@ -79,16 +79,16 @@ static u32 CB2_HandleMatchCallInput(struct Pokenav3Struct *state) { int selection; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return POKENAV_MC_FUNC_UP; - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return POKENAV_MC_FUNC_DOWN; - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return POKENAV_MC_FUNC_PG_UP; - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return POKENAV_MC_FUNC_PG_DOWN; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { state->callback = CB2_HandleMatchCallOptionsInput; state->optionCursorPos = 0; @@ -108,7 +108,7 @@ static u32 CB2_HandleMatchCallInput(struct Pokenav3Struct *state) return POKENAV_MC_FUNC_SELECT; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (GetPokenavMode() != POKENAV_MODE_FORCE_CALL_READY) { @@ -132,19 +132,19 @@ static u32 GetExitMatchCallMenuId(struct Pokenav3Struct *state) static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) { - if ((JOY_NEW(DPAD_UP)) && state->optionCursorPos) + if ((gMain.newKeys & DPAD_UP) && state->optionCursorPos) { state->optionCursorPos--; return POKENAV_MC_FUNC_MOVE_OPTIONS_CURSOR; } - if ((JOY_NEW(DPAD_DOWN)) && state->optionCursorPos < state->maxOptionId) + if ((gMain.newKeys & DPAD_DOWN) && state->optionCursorPos < state->maxOptionId) { state->optionCursorPos++; return POKENAV_MC_FUNC_MOVE_OPTIONS_CURSOR; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (state->matchCallOptions[state->optionCursorPos]) { @@ -166,7 +166,7 @@ static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_CANCEL; @@ -177,12 +177,12 @@ static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) static u32 CB2_HandleCheckPageInput(struct Pokenav3Struct *state) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return POKENAV_MC_FUNC_CHECK_PAGE_UP; - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return POKENAV_MC_FUNC_CHECK_PAGE_DOWN; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_EXIT_CHECK_PAGE; @@ -193,7 +193,7 @@ static u32 CB2_HandleCheckPageInput(struct Pokenav3Struct *state) static u32 CB2_HandleCallInput(struct Pokenav3Struct *state) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_10; diff --git a/src/pokenav_match_call_2.c b/src/pokenav_match_call_2.c index adcd889d3..381fa24d8 100755 --- a/src/pokenav_match_call_2.c +++ b/src/pokenav_match_call_2.c @@ -1125,7 +1125,7 @@ static void PrintMatchCallMessage(struct Pokenav4Struct *state) static bool32 WaitForMatchCallMessageText(struct Pokenav4Struct *state) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) gTextFlags.canABSpeedUpPrint = 1; else gTextFlags.canABSpeedUpPrint = 0; diff --git a/src/pokenav_menu_handler_1.c b/src/pokenav_menu_handler_1.c index c8820ac38..b3aaff50b 100644 --- a/src/pokenav_menu_handler_1.c +++ b/src/pokenav_menu_handler_1.c @@ -216,7 +216,7 @@ static u32 HandleMainMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sMenuItems[state->menuType][state->cursorPos]) { @@ -250,9 +250,9 @@ static u32 HandleMainMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_EXIT; } } - - if (JOY_NEW(B_BUTTON)) - return POKENAV_MENU_FUNC_EXIT; + + if (gMain.newKeys & B_BUTTON) + return -1; return POKENAV_MENU_FUNC_NONE; } @@ -262,8 +262,8 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) { if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - - if (JOY_NEW(A_BUTTON)) + + if (gMain.newKeys & A_BUTTON) { if (sMenuItems[state->menuType][state->cursorPos] == POKENAV_MENUITEM_MATCH_CALL) { @@ -278,7 +278,7 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_FAILURE); return POKENAV_MENU_FUNC_NONE; @@ -293,7 +293,7 @@ static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u32 menuItem = sMenuItems[state->menuType][state->cursorPos]; if (menuItem != POKENAV_MENUITEM_MATCH_CALL && menuItem != POKENAV_MENUITEM_SWITCH_OFF) @@ -312,7 +312,7 @@ static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state) return -1; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return -1; } @@ -329,7 +329,7 @@ static u32 HandleCantOpenRibbonsInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_MOVE_CURSOR; } - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { state->callback = GetMainMenuInputHandler(); return POKENAV_MENU_FUNC_RESHOW_DESCRIPTION; @@ -343,7 +343,7 @@ static u32 HandleConditionMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sMenuItems[state->menuType][state->cursorPos]) { @@ -363,7 +363,7 @@ static u32 HandleConditionMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_RETURN_TO_MAIN; } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (state->cursorPos != sLastCursorPositions[state->menuType]) { @@ -387,7 +387,7 @@ static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 menuItem = sMenuItems[state->menuType][state->cursorPos]; if (menuItem != POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL) @@ -404,7 +404,7 @@ static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_RETURN_TO_CONDITION; } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (state->cursorPos != sLastCursorPositions[state->menuType]) { @@ -463,7 +463,7 @@ static void ReturnToConditionMenu(struct Pokenav1Struct *state) static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (--state->cursorPos < 0) state->cursorPos = sLastCursorPositions[state->menuType]; @@ -471,7 +471,7 @@ static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state) state->currMenuItem = sMenuItems[state->menuType][state->cursorPos]; return TRUE; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { state->cursorPos++; if (state->cursorPos > sLastCursorPositions[state->menuType]) diff --git a/src/pokenav_region_map.c b/src/pokenav_region_map.c index 2dd2e4408..2b846991e 100755 --- a/src/pokenav_region_map.c +++ b/src/pokenav_region_map.c @@ -219,7 +219,7 @@ static u32 HandleRegionMapInput(struct Pokenav5Struct *state) static u32 HandleRegionMapInputZoomDisabled(struct Pokenav5Struct *state) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = GetExitRegionMapMenuId; return POKENAV_MAP_FUNC_EXIT; diff --git a/src/pokenav_ribbons_1.c b/src/pokenav_ribbons_1.c index 9c171dd45..6c20a0dc3 100644 --- a/src/pokenav_ribbons_1.c +++ b/src/pokenav_ribbons_1.c @@ -174,21 +174,21 @@ static u32 HandleRibbonsMonListInput_WaitListInit(struct PokenavSub9 *structPtr) static u32 HandleRibbonsMonListInput(struct PokenavSub9 *structPtr) { - if (JOY_REPEAT(DPAD_UP)) - return RIBBONS_MON_LIST_FUNC_MOVE_UP; - if (JOY_REPEAT(DPAD_DOWN)) - return RIBBONS_MON_LIST_FUNC_MOVE_DOWN; - if (JOY_NEW(DPAD_LEFT)) - return RIBBONS_MON_LIST_FUNC_PAGE_UP; - if (JOY_NEW(DPAD_RIGHT)) - return RIBBONS_MON_LIST_FUNC_PAGE_DOWN; - if (JOY_NEW(B_BUTTON)) + if (gMain.newAndRepeatedKeys & DPAD_UP) + return 1; + if (gMain.newAndRepeatedKeys & DPAD_DOWN) + return 2; + if (gMain.newKeys & DPAD_LEFT) + return 3; + if (gMain.newKeys & DPAD_RIGHT) + return 4; + if (gMain.newKeys & B_BUTTON) { structPtr->saveMonList = 0; structPtr->callback = RibbonsMonMenu_ReturnToMainMenu; return RIBBONS_MON_LIST_FUNC_EXIT; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { structPtr->monList->currIndex = GetSelectedPokenavListIndex(); structPtr->saveMonList = 1; diff --git a/src/pokenav_ribbons_2.c b/src/pokenav_ribbons_2.c index 203aa19e5..7764a965d 100644 --- a/src/pokenav_ribbons_2.c +++ b/src/pokenav_ribbons_2.c @@ -198,26 +198,26 @@ void FreeRibbonsSummaryScreen1(void) u32 RibbonsSummaryHandleInput(struct PokenavSub13 *structPtr) { - if (JOY_REPEAT(DPAD_UP) && structPtr->monList->currIndex != 0) + if (gMain.newAndRepeatedKeys & DPAD_UP && structPtr->monList->currIndex != 0) { structPtr->monList->currIndex--; structPtr->field_C = 0; sub_81D0814(structPtr); return RIBBONS_SUMMARY_FUNC_MOVED_CURSOR; } - if (JOY_REPEAT(DPAD_DOWN) && structPtr->monList->currIndex < structPtr->monList->listCount - 1) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN && structPtr->monList->currIndex < structPtr->monList->listCount - 1) { structPtr->monList->currIndex++; structPtr->field_C = 0; sub_81D0814(structPtr); return RIBBONS_SUMMARY_FUNC_MOVED_CURSOR; } - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { structPtr->callback = HandleExpandedRibbonInput; return RIBBONS_SUMMARY_FUNC_SELECT_RIBBON; } - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { structPtr->callback = ReturnToRibbonsListFromSummary; return RIBBONS_SUMMARY_FUNC_EXIT; @@ -227,15 +227,15 @@ u32 RibbonsSummaryHandleInput(struct PokenavSub13 *structPtr) u32 HandleExpandedRibbonInput(struct PokenavSub13 *structPtr) { - if (JOY_REPEAT(DPAD_UP) && sub_81D05DC(structPtr)) - return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_DOWN) && sub_81D061C(structPtr)) - return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_LEFT) && sub_81D0664(structPtr)) - return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_REPEAT(DPAD_RIGHT) && sub_81D0688(structPtr)) - return RIBBONS_SUMMARY_FUNC_EXPANDED_CURSOR_MOVE; - if (JOY_NEW(B_BUTTON)) + if (gMain.newAndRepeatedKeys & DPAD_UP && sub_81D05DC(structPtr)) + return 3; + else if (gMain.newAndRepeatedKeys & DPAD_DOWN && sub_81D061C(structPtr)) + return 3; + else if (gMain.newAndRepeatedKeys & DPAD_LEFT && sub_81D0664(structPtr)) + return 3; + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT && sub_81D0688(structPtr)) + return 3; + else if (gMain.newKeys & B_BUTTON) { structPtr->callback = RibbonsSummaryHandleInput; return RIBBONS_SUMMARY_FUNC_EXPANDED_CANCEL; diff --git a/src/record_mixing.c b/src/record_mixing.c index 344c535a4..898459c0a 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -712,18 +712,17 @@ static u8 sub_80E7A9C(struct DayCareMail *rmMail) return rmMail->message.itemId; } -static void ExchangeMail(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) +static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) { struct DayCareMail buffer; struct RecordMixingDayCareMail *mail1; struct RecordMixingDayCareMail *mail2; mail1 = (void *)src + recordSize * idxs[which0][0]; - buffer = mail1->mail[idxs[which0][1]]; - + memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DayCareMail)); mail2 = (void *)src + recordSize * idxs[which1][0]; - mail1->mail[idxs[which0][1]] = mail2->mail[idxs[which1][1]]; - mail2->mail[idxs[which1][1]] = buffer; + memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DayCareMail)); + memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DayCareMail)); } static void sub_80E7B2C(const u8 *src) @@ -865,22 +864,22 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r } else if (sp1c[i][0] == TRUE && sp1c[i][1] == TRUE) { - u8 mail1, mail2; + u32 var1, var2; sp24[j][0] = i; - mail1 = sub_80E7A9C(&_src->mail[0]); - mail2 = sub_80E7A9C(&_src->mail[1]); - if (!(mail1 || mail2) || (mail1 && mail2)) //Logical (not bitwise) XOR. Should be ((mail1 || mail2) && !(mail1 && mail2)), but that doesn't match. + var1 = sub_80E7A9C(&_src->mail[0]); + var2 = sub_80E7A9C(&_src->mail[1]); + if (!(var1 || var2) || (var1 && var2)) { sp24[j][1] = Random2() % 2; } - else if (mail1 && !mail2) + else if (var1 && !var2) { sp24[j][1] = 0; } - else if (!mail1 && mail2) + else if (!var1 && var2) { - sp24[j][1] = 1; + sp24[j][1] = 1; } j++; } @@ -896,27 +895,27 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r switch (sp34) { case 2: - ExchangeMail(src, recordSize, sp24, 0, 1); + sub_80E7AA4(src, recordSize, sp24, 0, 1); break; case 3: which0 = gUnknown_0858CFB8[tableId][0]; which1 = gUnknown_0858CFB8[tableId][1]; - ExchangeMail(src, recordSize, sp24, which0, which1); + sub_80E7AA4(src, recordSize, sp24, which0, which1); break; case 4: ptr = sp24; which0 = gUnknown_0858CFBE[tableId][0]; which1 = gUnknown_0858CFBE[tableId][1]; - ExchangeMail(src, recordSize, ptr, which0, which1); + sub_80E7AA4(src, recordSize, ptr, which0, which1); which0 = gUnknown_0858CFBE[tableId][2]; which1 = gUnknown_0858CFBE[tableId][3]; - ExchangeMail(src, recordSize, ptr, which0, which1); + sub_80E7AA4(src, recordSize, ptr, which0, which1); break; } _src = (void *)src + which * recordSize; - gSaveBlock1Ptr->daycare.mons[0].mail = _src->mail[0]; - gSaveBlock1Ptr->daycare.mons[1].mail = _src->mail[1]; + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DayCareMail)); SeedRng(oldSeed); } diff --git a/src/region_map.c b/src/region_map.c index 49b21be07..3438ea3ed 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -651,31 +651,31 @@ static u8 ProcessRegionMapInput_Full(void) input = MAP_INPUT_NONE; gRegionMap->cursorDeltaX = 0; gRegionMap->cursorDeltaY = 0; - if (JOY_HELD(DPAD_UP) && gRegionMap->cursorPosY > MAPCURSOR_Y_MIN) + if (gMain.heldKeys & DPAD_UP && gRegionMap->cursorPosY > MAPCURSOR_Y_MIN) { gRegionMap->cursorDeltaY = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_DOWN) && gRegionMap->cursorPosY < MAPCURSOR_Y_MAX) + if (gMain.heldKeys & DPAD_DOWN && gRegionMap->cursorPosY < MAPCURSOR_Y_MAX) { gRegionMap->cursorDeltaY = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_LEFT) && gRegionMap->cursorPosX > MAPCURSOR_X_MIN) + if (gMain.heldKeys & DPAD_LEFT && gRegionMap->cursorPosX > MAPCURSOR_X_MIN) { gRegionMap->cursorDeltaX = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_RIGHT) && gRegionMap->cursorPosX < MAPCURSOR_X_MAX) + if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->cursorPosX < MAPCURSOR_X_MAX) { gRegionMap->cursorDeltaX = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { input = MAP_INPUT_A_BUTTON; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { input = MAP_INPUT_B_BUTTON; } @@ -730,31 +730,31 @@ static u8 ProcessRegionMapInput_Zoomed(void) input = MAP_INPUT_NONE; gRegionMap->zoomedCursorDeltaX = 0; gRegionMap->zoomedCursorDeltaY = 0; - if (JOY_HELD(DPAD_UP) && gRegionMap->scrollY > -0x34) + if (gMain.heldKeys & DPAD_UP && gRegionMap->scrollY > -0x34) { gRegionMap->zoomedCursorDeltaY = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_DOWN) && gRegionMap->scrollY < 0x3c) + if (gMain.heldKeys & DPAD_DOWN && gRegionMap->scrollY < 0x3c) { gRegionMap->zoomedCursorDeltaY = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_LEFT) && gRegionMap->scrollX > -0x2c) + if (gMain.heldKeys & DPAD_LEFT && gRegionMap->scrollX > -0x2c) { gRegionMap->zoomedCursorDeltaX = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_RIGHT) && gRegionMap->scrollX < 0xac) + if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->scrollX < 0xac) { gRegionMap->zoomedCursorDeltaX = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { input = MAP_INPUT_A_BUTTON; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { input = MAP_INPUT_B_BUTTON; } diff --git a/src/reset_rtc_screen.c b/src/reset_rtc_screen.c index d0e815816..204eb6733 100644 --- a/src/reset_rtc_screen.c +++ b/src/reset_rtc_screen.c @@ -380,7 +380,7 @@ static void Task_ResetRtc_1(u8 taskId) u8 selection = data[2]; const struct ResetRtcStruct *selectionInfo = &sUnknown_08510428[selection - 1]; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gTasks[taskId].func = Task_ResetRtc_2; data[1] = 0; @@ -389,7 +389,7 @@ static void Task_ResetRtc_1(u8 taskId) return; } - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selectionInfo->right) { @@ -399,7 +399,7 @@ static void Task_ResetRtc_1(u8 taskId) } } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selectionInfo->left) { @@ -411,7 +411,7 @@ static void Task_ResetRtc_1(u8 taskId) if (selection == 5) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gLocalTime.days = data[3]; gLocalTime.hours = data[4]; @@ -423,7 +423,7 @@ static void Task_ResetRtc_1(u8 taskId) data[2] = 6; } } - else if (MoveTimeUpDown(&data[selectionInfo->dataIndex], selectionInfo->minVal, selectionInfo->maxVal, JOY_REPEAT(DPAD_UP | DPAD_DOWN))) + else if (MoveTimeUpDown(&data[selectionInfo->dataIndex], selectionInfo->minVal, selectionInfo->maxVal, gMain.newAndRepeatedKeys & (DPAD_UP | DPAD_DOWN))) { PlaySE(SE_SELECT); PrintTime(data[8], 0, 1, data[3], data[4], data[5], data[6]); @@ -532,12 +532,12 @@ static void Task_ShowResetRtcPrompt(u8 taskId) ScheduleBgCopyTilemapToVram(0); data[0]++; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { DestroyTask(taskId); DoSoftReset(); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); DestroyTask(taskId); @@ -620,7 +620,7 @@ static void Task_ResetRtcScreen(u8 taskId) } data[0] = 5; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 1, 0, 0x10, RGB_WHITEALPHA); data[0] = 6; diff --git a/src/save.c b/src/save.c index 0a2a4e799..680f33de0 100644 --- a/src/save.c +++ b/src/save.c @@ -13,7 +13,7 @@ #include "link.h" #include "constants/game_stat.h" -static u16 CalculateChecksum(const void *data, u16 size); +static u16 CalculateChecksum(void *data, u16 size); static bool8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); static u8 GetSaveValidStatus(const struct SaveSectionLocation *location); static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); @@ -621,7 +621,7 @@ static bool8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) return TRUE; } -static u16 CalculateChecksum(const void *data, u16 size) +static u16 CalculateChecksum(void *data, u16 size) { u16 i; u32 checksum = 0; @@ -648,7 +648,7 @@ static void UpdateSaveAddresses(void) gRamSaveSectionLocations[i].size = sSaveSectionOffsets[i].size; } - for (; i <= SECTOR_ID_PKMN_STORAGE_END; i++) //i = SECTOR_ID_PKMN_STORAGE_START; in the initialization clause does not match + for (; i <= SECTOR_ID_PKMN_STORAGE_END; i++) //setting i to SECTOR_ID_PKMN_STORAGE_START does not match { gRamSaveSectionLocations[i].data = (void*)(gPokemonStoragePtr) + sSaveSectionOffsets[i].toAdd; gRamSaveSectionLocations[i].size = sSaveSectionOffsets[i].size; diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 9bf0e7ed4..a2a2acc8d 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -306,7 +306,7 @@ static void CB2_GameplayCannotBeContinued(void) { gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); @@ -319,7 +319,7 @@ static void CB2_FadeAndReturnToTitleScreen(void) { gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); SetVBlankCallback(VBlankCB); @@ -349,7 +349,7 @@ static void VBlankCB_UpdateClockGraphics(void) gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; - gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { diff --git a/src/scrcmd.c b/src/scrcmd.c index 578e357fa..b71fa40ad 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -788,8 +788,8 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) { u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - s16 x; - s16 y; + u16 x; + u16 y; PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) @@ -1325,9 +1325,9 @@ bool8 ScrCmd_closemessage(struct ScriptContext *ctx) static bool8 WaitForAorBPress(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return TRUE; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return TRUE; return FALSE; } diff --git a/src/script.c b/src/script.c index 889c25765..9ba1a7429 100644 --- a/src/script.c +++ b/src/script.c @@ -26,9 +26,9 @@ void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTable s32 i; ctx->mode = 0; - ctx->scriptPtr = NULL; + ctx->scriptPtr = 0; ctx->stackDepth = 0; - ctx->nativePtr = NULL; + ctx->nativePtr = 0; ctx->cmdTable = cmdTable; ctx->cmdTableEnd = cmdTableEnd; @@ -55,7 +55,7 @@ void SetupNativeScript(struct ScriptContext *ctx, bool8 (*ptr)(void)) void StopScript(struct ScriptContext *ctx) { ctx->mode = 0; - ctx->scriptPtr = NULL; + ctx->scriptPtr = 0; } bool8 RunScriptCommand(struct ScriptContext *ctx) diff --git a/src/script_menu.c b/src/script_menu.c index 425cdc251..2b135e301 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -170,7 +170,7 @@ static void Task_HandleMultichoiceInput(u8 taskId) else selection = Menu_ProcessInput(); - if (JOY_NEW(DPAD_UP | DPAD_DOWN)) + if (gMain.newKeys & (DPAD_UP | DPAD_DOWN)) { DrawLinkServicesMultichoiceMenu(tMultichoiceId); } diff --git a/src/secret_base.c b/src/secret_base.c index 0ee5cc740..8e0929593 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -963,7 +963,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], (u16 *)&data[2], (u16 *)&data[1]); + ListMenuGetScrollAndRow(data[5], &data[2], &data[1]); switch (input) { case LIST_NOTHING_CHOSEN: @@ -1044,10 +1044,10 @@ void DeleteRegistry_Yes_Callback(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + DestroyListMenuTask(data[5], &data[2], &data[1]); gSaveBlock1Ptr->secretBases[data[4]].registryStatus = 0; BuildRegistryMenuItems(taskId); - sub_812225C((u16 *)&data[2], (u16 *)&data[1], (u16)data[3], (u16)data[0]); + sub_812225C(&data[2], &data[1], data[3], data[0]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } @@ -1061,7 +1061,7 @@ static void DeleteRegistry_No(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + DestroyListMenuTask(data[5], &data[2], &data[1]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } diff --git a/src/shop.c b/src/shop.c index 44ab0885c..66f775fb0 100755 --- a/src/shop.c +++ b/src/shop.c @@ -1017,7 +1017,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(4, 0); @@ -1030,7 +1030,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) ConvertIntToDecimalStringN(gStringVar3, gShopDataPtr->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); BuyMenuDisplayMessage(taskId, gText_Var1AndYouWantedVar2, BuyMenuConfirmPurchase); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(4, 0); @@ -1106,7 +1106,7 @@ static void Task_ReturnToItemListAfterItemPurchase(u8 taskId) { s16 *data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); if (tItemId == ITEM_POKE_BALL && tItemCount > 9 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE) @@ -1122,7 +1122,7 @@ static void Task_ReturnToItemListAfterItemPurchase(u8 taskId) static void Task_ReturnToItemListAfterDecorationPurchase(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BuyMenuReturnToItemList(taskId); diff --git a/src/slot_machine.c b/src/slot_machine.c index cc001bcc9..285b110af 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -252,8 +252,8 @@ struct SlotMachine /*0x0E*/ s16 payout; /*0x10*/ s16 netCoinLoss; // coins lost to machine (but never goes below 0) /*0x12*/ s16 bet; - /*0x14*/ s16 reelTimePixelOffset; - /*0x16*/ s16 reelTimePosition; + /*0x14*/ s16 reeltimePixelOffset; + /*0x16*/ s16 reeltimePosition; /*0x18*/ s16 currReel; /*0x1A*/ s16 reelIncrement; // speed of reel /*0x1C*/ s16 reelPixelOffsets[NUM_REELS]; @@ -584,7 +584,7 @@ static const u16 *const sDigitalDisplay_Pal; static const s16 sInitialReelPositions[NUM_REELS][2]; static const u8 sLuckyFlagProbabilities_Top3[][6]; static const u8 sLuckyFlagProbabilities_NotTop3[][6]; -static const u8 sReelTimeProbabilities_UnluckyGame[][17]; +static const u8 sReeltimeProbabilities_UnluckyGame[][17]; static const u8 sReelTimeProbabilities_LuckyGame[][17]; static const u8 sSymToMatch[]; static const u8 sReelTimeTags[]; @@ -682,7 +682,7 @@ static const struct WindowTemplate sWindowTemplate_InfoBox = .baseBlock = 1 }; -static const u8 sColors_ReelTimeHelp[] = {TEXT_COLOR_LIGHT_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY}; +static const u8 sColors_ReeltimeHelp[] = {TEXT_COLOR_LIGHT_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY}; static bool8 (*const sSlotActions[])(struct Task *task) = { @@ -985,7 +985,7 @@ static void PlaySlotMachine_Internal(u8 slotMachineIndex, MainCallback exitCallb { struct Task *task = &gTasks[CreateTask(SlotMachineDummyTask, 0xFF)]; task->data[0] = slotMachineIndex; - StoreWordInTwoHalfwords((u16 *)&task->data[1], (intptr_t)exitCallback); + StoreWordInTwoHalfwords(&task->data[1], (intptr_t)exitCallback); } @@ -1744,13 +1744,13 @@ static u8 AttemptsAtLuckyFlags_NotTop3(void) static u8 GetReelTimeProbability(u8 reelTimeDraw) { - if (!sSlotMachine->luckyGame) - return sReelTimeProbabilities_UnluckyGame[reelTimeDraw][sSlotMachine->pikaPower]; - - return sReelTimeProbabilities_LuckyGame[reelTimeDraw][sSlotMachine->pikaPower]; + if (sSlotMachine->luckyGame == FALSE) + return sReeltimeProbabilities_UnluckyGame[reelTimeDraw][sSlotMachine->pikaPower]; + else + return sReelTimeProbabilities_LuckyGame[reelTimeDraw][sSlotMachine->pikaPower]; } -static void GetReelTimeDraw(void) +static void GetReeltimeDraw(void) { u8 rval; s16 reelTimeDraw; @@ -1773,13 +1773,15 @@ static bool8 ShouldReelTimeMachineExplode(u16 i) u16 rval = Random() & 0xff; if (rval < sReelTimeExplodeProbability[i]) return TRUE; - return FALSE; + else + return FALSE; } static u16 SlowReelSpeed(void) { u8 i = 0; - u8 rval, value; + u8 rval; + u8 value; if (sSlotMachine->netCoinLoss >= 300) i = 4; else if (sSlotMachine->netCoinLoss >= 250) @@ -1909,7 +1911,8 @@ static bool8 IsFinalTask_RunAwardPayoutActions(void) { if (FindTaskIdByFunc(RunAwardPayoutActions) == TAIL_SENTINEL) return TRUE; - return FALSE; + else + return FALSE; } static void RunAwardPayoutActions(u8 taskId) @@ -1942,7 +1945,7 @@ static bool8 AwardPayoutAction_GivePayoutToPlayer(struct Task *task) if (sSlotMachine->coins < MAX_COINS) sSlotMachine->coins++; task->data[1] = 8; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) task->data[1] = 4; } if (IsFanfareTaskInactive() && JOY_NEW(START_BUTTON)) @@ -1997,7 +2000,7 @@ static u8 GetTag(u8 reel, s16 offset) static u8 GetNearbyReelTimeTag(s16 n) { - s16 newPosition = (sSlotMachine->reelTimePosition + n) % 6; + s16 newPosition = (sSlotMachine->reeltimePosition + n) % 6; if (newPosition < 0) newPosition += 6; return sReelTimeTags[newPosition]; @@ -2023,22 +2026,22 @@ s16 AdvanceSlotReelToNextTag(u8 reelIndex, s16 value) return offset; } -static void AdvanceReelTimeReel(s16 value) +static void AdvanceReeltimeReel(s16 value) { - sSlotMachine->reelTimePixelOffset += value; - sSlotMachine->reelTimePixelOffset %= 120; - sSlotMachine->reelTimePosition = 6 - sSlotMachine->reelTimePixelOffset / 20; + sSlotMachine->reeltimePixelOffset += value; + sSlotMachine->reeltimePixelOffset %= 120; + sSlotMachine->reeltimePosition = 6 - sSlotMachine->reeltimePixelOffset / 20; } -s16 AdvanceReelTimeReelToNextTag(s16 value) +s16 AdvanceReeltimeReelToNextTag(s16 value) { - s16 offset = sSlotMachine->reelTimePixelOffset % 20; + s16 offset = sSlotMachine->reeltimePixelOffset % 20; if (offset != 0) { if (offset < value) value = offset; - AdvanceReelTimeReel(value); - offset = sSlotMachine->reelTimePixelOffset % 20; + AdvanceReeltimeReel(value); + offset = sSlotMachine->reeltimePixelOffset % 20; } return offset; } @@ -3077,8 +3080,8 @@ static void Task_ReelTime(u8 taskId) static void ReelTime_Init(struct Task *task) { sSlotMachine->reelTimeSpinsLeft = 0; - sSlotMachine->reelTimePixelOffset = 0; - sSlotMachine->reelTimePosition = 0; + sSlotMachine->reeltimePixelOffset = 0; + sSlotMachine->reeltimePosition = 0; task->tState++; task->data[1] = 0; task->data[2] = 30; @@ -3093,7 +3096,7 @@ static void ReelTime_Init(struct Task *task) CreateReelTimeNumberSprites(); CreateReelTimeShadowSprites(); CreateReelTimeNumberGapSprite(); - GetReelTimeDraw(); + GetReeltimeDraw(); StopMapMusic(); PlayNewMapMusic(MUS_ROULETTE); } @@ -3116,12 +3119,12 @@ static void ReelTime_WindowEnter(struct Task *task) task->tState++; task->data[3] = 0; } - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); } static void ReelTime_WaitStartPikachu(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); if (++task->data[5] >= 60) { task->tState++; @@ -3141,7 +3144,7 @@ static void ReelTime_PikachuSpeedUp1(struct Task *task) memcpy(reelTimeBoltDelays, sReelTimeBoltDelays, sizeof(sReelTimeBoltDelays)); memcpy(pikachuAuraFlashDelays, sPikachuAuraFlashDelays, sizeof(sPikachuAuraFlashDelays)); - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); // gradually slow down the reel task->data[4] -= 4; i = 4 - (task->data[4] >> 8); @@ -3159,7 +3162,7 @@ static void ReelTime_PikachuSpeedUp1(struct Task *task) static void ReelTime_PikachuSpeedUp2(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); if (++task->data[5] >= 80) { task->tState++; @@ -3171,7 +3174,7 @@ static void ReelTime_PikachuSpeedUp2(struct Task *task) static void ReelTime_WaitReel(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x80; if (++task->data[5] >= 80) { @@ -3182,7 +3185,7 @@ static void ReelTime_WaitReel(struct Task *task) static void ReelTime_CheckExplode(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x40; if (++task->data[5] >= 40) { @@ -3206,19 +3209,19 @@ static void ReelTime_CheckExplode(struct Task *task) static void ReelTime_LandOnOutcome(struct Task *task) { - s16 reelTimePixelOffset = sSlotMachine->reelTimePixelOffset % 20; - if (reelTimePixelOffset) + s16 reeltimePixelOffset = sSlotMachine->reeltimePixelOffset % 20; + if (reeltimePixelOffset) { - reelTimePixelOffset = AdvanceReelTimeReelToNextTag(task->data[4] >> 8); + reeltimePixelOffset = AdvanceReeltimeReelToNextTag(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x40; } else if (GetNearbyReelTimeTag(1) != sSlotMachine->reelTimeDraw) { - AdvanceReelTimeReel(task->data[4] >> 8); - reelTimePixelOffset = sSlotMachine->reelTimePixelOffset % 20; + AdvanceReeltimeReel(task->data[4] >> 8); + reeltimePixelOffset = sSlotMachine->reeltimePixelOffset % 20; task->data[4] = (u8)task->data[4] + 0x40; } - if (reelTimePixelOffset == 0 && GetNearbyReelTimeTag(1) == sSlotMachine->reelTimeDraw) + if (reeltimePixelOffset == 0 && GetNearbyReelTimeTag(1) == sSlotMachine->reelTimeDraw) { task->data[4] = 0; // stop moving task->tState++; @@ -3441,7 +3444,7 @@ static void InfoBox_DrawWindow(struct Task *task) static void InfoBox_AddText(struct Task *task) { - AddTextPrinterParameterized3(1, 1, 2, 5, sColors_ReelTimeHelp, 0, gText_ReelTimeHelp); + AddTextPrinterParameterized3(1, 1, 2, 5, sColors_ReeltimeHelp, 0, gText_ReelTimeHelp); CopyWindowToVram(1, 3); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB(0, 0, 0)); task->tState++; @@ -3771,7 +3774,7 @@ static void CreateReelTimeNumberSprites(void) static void SpriteCB_ReelTimeNumbers(struct Sprite *sprite) { - s16 r0 = (u16)(sSlotMachine->reelTimePixelOffset + sprite->data[7]); + s16 r0 = (u16)(sSlotMachine->reeltimePixelOffset + sprite->data[7]); r0 %= 40; sprite->pos1.y = r0 + 59; StartSpriteAnimIfDifferent(sprite, GetNearbyReelTimeTag(r0 / 20)); @@ -4827,7 +4830,7 @@ static const u8 sLuckyFlagProbabilities_NotTop3[][6] = { {40, 40, 35, 35, 40, 40} }; -static const u8 sReelTimeProbabilities_UnluckyGame[][17] = { +static const u8 sReeltimeProbabilities_UnluckyGame[][17] = { {243, 243, 243, 80, 80, 80, 80, 40, 40, 40, 40, 40, 40, 5, 5, 5, 5}, { 5, 5, 5, 150, 150, 150, 150, 130, 130, 130, 130, 130, 130, 100, 100, 100, 5}, { 4, 4, 4, 20, 20, 20, 20, 80, 80, 80, 80, 80, 80, 100, 100, 100, 40}, diff --git a/src/start_menu.c b/src/start_menu.c index fa51766e8..6a90946fe 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -462,7 +462,7 @@ static bool32 InitStartMenuStep(void) sInitStartMenuData[0]++; break; case 4: - if (PrintStartMenuActions((s8 *)&sInitStartMenuData[1], 2)) + if (PrintStartMenuActions(&sInitStartMenuData[1], 2)) sInitStartMenuData[0]++; break; case 5: @@ -550,19 +550,19 @@ void ShowStartMenu(void) static bool8 HandleStartMenuInput(void) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); sStartMenuCursorPos = Menu_MoveCursor(-1); } - if (JOY_NEW(DPAD_DOWN)) + if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); sStartMenuCursorPos = Menu_MoveCursor(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func.u8_void == StartMenuPokedexCallback) @@ -584,7 +584,7 @@ static bool8 HandleStartMenuInput(void) return FALSE; } - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { RemoveExtraStartMenuWindows(); HideStartMenu(); @@ -906,12 +906,12 @@ static bool8 SaveSuccesTimer(void) { sSaveDialogTimer--; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { PlaySE(SE_SELECT); return TRUE; } - if (sSaveDialogTimer == 0) + else if (sSaveDialogTimer == 0) { return TRUE; } @@ -925,7 +925,7 @@ static bool8 SaveErrorTimer(void) { sSaveDialogTimer--; } - else if (JOY_HELD(A_BUTTON)) + else if (gMain.heldKeys & A_BUTTON) { return TRUE; } diff --git a/src/title_screen.c b/src/title_screen.c index 1d6f90d74..108601685 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -727,24 +727,24 @@ static void Task_TitleScreenPhase2(u8 taskId) // Show Rayquaza silhouette and process main title screen input static void Task_TitleScreenPhase3(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(START_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & START_BUTTON)) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITEALPHA); SetMainCallback2(CB2_GoToMainMenu); } - else if (JOY_HELD(CLEAR_SAVE_BUTTON_COMBO) == CLEAR_SAVE_BUTTON_COMBO) + else if ((gMain.heldKeys & CLEAR_SAVE_BUTTON_COMBO) == CLEAR_SAVE_BUTTON_COMBO) { SetMainCallback2(CB2_GoToClearSaveDataScreen); } - else if (JOY_HELD(RESET_RTC_BUTTON_COMBO) == RESET_RTC_BUTTON_COMBO + else if ((gMain.heldKeys & RESET_RTC_BUTTON_COMBO) == RESET_RTC_BUTTON_COMBO && CanResetRTC() == TRUE) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); SetMainCallback2(CB2_GoToResetRtcScreen); } - else if (JOY_HELD(BERRY_UPDATE_BUTTON_COMBO) == BERRY_UPDATE_BUTTON_COMBO) + else if ((gMain.heldKeys & BERRY_UPDATE_BUTTON_COMBO) == BERRY_UPDATE_BUTTON_COMBO) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); diff --git a/src/trade.c b/src/trade.c index 5ba26842f..e61066dc5 100644 --- a/src/trade.c +++ b/src/trade.c @@ -1352,24 +1352,24 @@ static void SetReadyToTrade(void) static void TradeMenuProcessInput(void) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 0); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 1); } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 2); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 3); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -1450,7 +1450,7 @@ static void TradeMenuProcessInput_SelectedMon(void) static void ChooseMonAfterButtonPress(void) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); TradeMenuChooseMon(); @@ -1625,7 +1625,7 @@ static void RedrawTradeMenuAfterPressA(void) { int i; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); rbox_fill_rectangle(0); @@ -1697,7 +1697,7 @@ static void LinkTradeWaitForQueue(void) static void PartnersMonWasInvalid(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; @@ -3727,7 +3727,7 @@ static bool8 AnimateTradeSequenceCable(void) { return TRUE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { sTradeData->state++; } @@ -4242,7 +4242,7 @@ static bool8 AnimateTradeSequenceWireless(void) { return TRUE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { sTradeData->state++; } diff --git a/src/trainer_card.c b/src/trainer_card.c index 2d9ec2b09..9d6838176 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -438,13 +438,13 @@ static void Task_TrainerCard(u8 taskId) DrawTrainerCardWindow(1); sData->timeColonNeedDraw = FALSE; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FlipTrainerCard(); PlaySE(SE_RG_CARD_FLIP); sData->mainState = STATE_WAIT_FLIP_TO_BACK; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { @@ -465,7 +465,7 @@ static void Task_TrainerCard(u8 taskId) } break; case STATE_HANDLE_INPUT_BACK: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { @@ -483,7 +483,7 @@ static void Task_TrainerCard(u8 taskId) PlaySE(SE_RG_CARD_FLIP); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 1116051d3..75271cab0 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -355,7 +355,7 @@ static void SetUpDataStruct(void) { if (sHillData == NULL) { - sHillData = AllocZeroed(sizeof(struct TrHillStruct2)); + sHillData = AllocZeroed(sizeof(*sHillData)); sHillData->floorId = gMapHeader.mapLayoutId - LAYOUT_TRAINER_HILL_1F; CpuCopy32(sDataPerTag[gSaveBlock1Ptr->trainerHill.tag], &sHillData->tag, sizeof(sHillData->tag) + 4 * sizeof(struct TrHillFloor)); nullsub_2(); @@ -671,14 +671,14 @@ bool32 LoadTrainerHillFloorObjectEventScripts(void) return TRUE; } -static u16 GetMetatileForFloor(u8 floorId, u32 x, u32 y, u32 stride) // stride is always 16 +static u32 GetMetatileForFloor(u8 floorId, u32 bit, u32 arg2, u32 arg3) { bool8 impassable; u16 metatile; u16 elevation; - impassable = (sHillData->floors[floorId].display.collisionData[y] >> (15 - x) & 1); - metatile = sHillData->floors[floorId].display.metatileData[stride * y + x] + 0x200; + impassable = (sHillData->floors[floorId].display.collisionData[arg2] >> (15 - bit)) & 1; + metatile = sHillData->floors[floorId].display.metatileData[arg2 * arg3 + bit] + 0x200; elevation = 0x3000; return (((impassable << 10) & METATILE_COLLISION_MASK) | elevation) | (metatile & METATILE_ID_MASK); diff --git a/src/trainer_see.c b/src/trainer_see.c index c37f37262..4f4aaea08 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -603,7 +603,7 @@ static void sub_80B44C8(u8 taskId) struct ObjectEvent *objEvent; // another objEvent loaded into by loadword? - LoadWordFromTwoHalfwords((u16*)&task->data[1], (u32 *)&objEvent); + LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&objEvent); if (!task->data[7]) { ObjectEventClearHeldMovement(objEvent); @@ -624,7 +624,7 @@ static void sub_80B44C8(u8 taskId) void sub_80B4578(struct ObjectEvent *var) { - StoreWordInTwoHalfwords((u16 *)&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); + StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); } void EndTrainerApproach(void) diff --git a/src/union_room.c b/src/union_room.c index b247a69e3..cb9c4018e 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -444,7 +444,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) break; case LL_STATE_AWAIT_PLAYERS: Leader_SetStateIfMemberListChanged(data, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT, LL_STATE_MEMBER_LEFT); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (data->playerCount == 1) data->state = LL_STATE_SHUTDOWN_AND_FAIL; @@ -457,7 +457,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) && data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1 && GROUP_MAX(sPlayerActivityGroupSize) != 0 && sub_8012240() - && JOY_NEW(START_BUTTON)) + && gMain.newKeys & START_BUTTON) { data->state = LL_STATE_MEMBERS_OK_PROMPT; LinkRfu_StopManagerAndFinalizeSlots(); @@ -1004,7 +1004,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; case 0: id = ListMenu_ProcessInput(data->listTaskId); - if (JOY_NEW(A_BUTTON) && id != -1) + if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match u32 activity = data->field_0->arr[id].gname_uname.gname.activity; @@ -1031,7 +1031,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) PlaySE(SE_WALL_HIT); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = LG_STATE_CANCEL_CHOOSE_LEADER; } @@ -1134,7 +1134,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; } - if (RfuGetStatus() == RFU_STATUS_OK && JOY_NEW(B_BUTTON)) + if (RfuGetStatus() == RFU_STATUS_OK && gMain.newKeys & B_BUTTON) data->state = LG_STATE_ASK_LEAVE_GROUP; break; case LG_STATE_ASK_LEAVE_GROUP: @@ -1888,7 +1888,7 @@ static void Task_MEvent_Leader(u8 taskId) break; case 4: Leader_SetStateIfMemberListChanged(data, 5, 6); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { data->state = 13; DestroyWirelessStatusIndicatorSprite(); @@ -2103,7 +2103,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) break; case 0: id = ListMenu_ProcessInput(data->listTaskId); - if (JOY_NEW(A_BUTTON) && id != -1) + if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match u32 unusedVar; @@ -2125,7 +2125,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) PlaySE(SE_WALL_HIT); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = 6; } @@ -2288,7 +2288,7 @@ static void Task_CardOrNewsOverWireless(u8 taskId) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = 6; data->refreshTimer = 0; @@ -2546,7 +2546,7 @@ static void Task_RunUnionRoom(u8 taskId) } else if (ScriptContext2_IsEnabled() != TRUE) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (TryInteractWithUnionRoomMember(uroom->field_0, &taskData[0], &taskData[1], uroom->spriteIds)) { @@ -2880,7 +2880,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_HANDLE_CONTACT_DATA: ReceiveUnionRoomActivityPacket(uroom); - if (UnionRoom_HandleContactFromOtherPlayer(uroom) && JOY_NEW(B_BUTTON)) + if (UnionRoom_HandleContactFromOtherPlayer(uroom) && gMain.newKeys & B_BUTTON) { sub_8011DE0(1); StringCopy(gStringVar4, sText_ChatEnded); @@ -3753,7 +3753,7 @@ static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str printerTemplate.y = y; printerTemplate.currentX = x; printerTemplate.currentY = y; - printerTemplate.style = 0; + printerTemplate.unk = 0; gTextFlags.useAlternateDownArrow = FALSE; switch (colorIdx) diff --git a/src/union_room_chat.c b/src/union_room_chat.c index ed39d3acf..fd2a95791 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -1017,12 +1017,12 @@ static void Chat_HandleInput(void) switch (sChat->funcState) { case 0: - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) { if (sChat->bufferCursorPos) SetChatFunction(CHAT_FUNC_SEND); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { SetChatFunction(CHAT_FUNC_SWITCH); } @@ -1039,14 +1039,14 @@ static void Chat_HandleInput(void) SetChatFunction(CHAT_FUNC_ASK_QUIT); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { AppendTextToMessage(); StartDisplaySubtask(CHATDISPLAY_FUNC_UPDATE_MSG, 0); StartDisplaySubtask(CHATDISPLAY_FUNC_CURSOR_BLINK, 1); sChat->funcState = 1; } - else if (JOY_NEW(R_BUTTON)) + else if (gMain.newKeys & R_BUTTON) { if (sChat->currentPage != UNION_ROOM_KB_PAGE_REGISTER) { @@ -1100,7 +1100,7 @@ static void Chat_Switch(void) shouldSwitchPages = FALSE; break; case MENU_NOTHING_CHOSEN: - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1420,13 +1420,13 @@ static void Chat_Register(void) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { RegisterTextAtRow(); StartDisplaySubtask(CHATDISPLAY_FUNC_RETURN_TO_KB, 0); sChat->funcState = 3; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StartDisplaySubtask(CHATDISPLAY_FUNC_CANCEL_REGISTER, 0); sChat->funcState = 4; @@ -1457,7 +1457,7 @@ static void Chat_Register(void) sChat->funcState = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { StartDisplaySubtask(CHATDISPLAY_FUNC_DESTROY_YESNO, 0); sChat->funcState = 4; @@ -1591,7 +1591,7 @@ static bool32 HandleDPadInput(void) { do { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sChat->currentRow > 0) sChat->currentRow--; @@ -1599,7 +1599,7 @@ static bool32 HandleDPadInput(void) sChat->currentRow = sKeyboardPageMaxRow[sChat->currentPage]; break; } - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sChat->currentRow < sKeyboardPageMaxRow[sChat->currentPage]) sChat->currentRow++; @@ -1609,7 +1609,7 @@ static bool32 HandleDPadInput(void) } if (sChat->currentPage != UNION_ROOM_KB_PAGE_REGISTER) { - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sChat->currentCol > 0) sChat->currentCol--; @@ -1617,7 +1617,7 @@ static bool32 HandleDPadInput(void) sChat->currentCol = 4; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sChat->currentCol < 4) sChat->currentCol++; @@ -2121,7 +2121,7 @@ static void Task_ReceiveChatMessage(u8 taskId) static bool8 TryAllocDisplay(void) { - sDisplay = Alloc(sizeof(struct UnionRoomChatDisplay)); + sDisplay = Alloc(sizeof(*sDisplay)); if (sDisplay && TryAllocSprites()) { ResetBgsAndClearDma3BusyFlags(0); diff --git a/src/unk_text_util_2.c b/src/unk_text_util_2.c index b92b34fbd..22db293e9 100644 --- a/src/unk_text_util_2.c +++ b/src/unk_text_util_2.c @@ -19,14 +19,14 @@ u16 Font6Func(struct TextPrinter *textPrinter) switch (textPrinter->state) { case 0: - if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp) + if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp) { textPrinter->delayCounter = 0; } if (textPrinter->delayCounter && textPrinter->textSpeed) { textPrinter->delayCounter --; - if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON)) + if (gTextFlags.canABSpeedUpPrint && gMain.newKeys & (A_BUTTON | B_BUTTON)) { subStruct->hasPrintBeenSpedUp = TRUE; textPrinter->delayCounter = 0; diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 2b11add76..4b617e3b8 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -118,8 +118,8 @@ static u8 GetLetterTableId(u8 letter) static bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase) { s32 i; - u8 array[9]; - u8 charsByTableId[15]; + ALIGNED(2) u8 array[12]; + u8 charsByTableId[16]; u16 *ptr; if (StringLength(phrase) != 15) diff --git a/src/wallclock.c b/src/wallclock.c index c38dd99e3..bed04928e 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -795,7 +795,7 @@ static void Task_SetClock_HandleInput(u8 taskId) { gTasks[taskId].tMinuteHandAngle = gTasks[taskId].tMinutes * 6; gTasks[taskId].tHourHandAngle = (gTasks[taskId].tHours % 12) * 30 + (gTasks[taskId].tMinutes / 10) * 5; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gTasks[taskId].func = Task_SetClock_AskConfirm; } @@ -803,10 +803,10 @@ static void Task_SetClock_HandleInput(u8 taskId) { gTasks[taskId].tMoveDir = MOVE_NONE; - if (JOY_HELD(DPAD_LEFT)) + if (gMain.heldKeys & DPAD_LEFT) gTasks[taskId].tMoveDir = MOVE_BACKWARD; - if (JOY_HELD(DPAD_RIGHT)) + if (gMain.heldKeys & DPAD_RIGHT) gTasks[taskId].tMoveDir = MOVE_FORWARD; if (gTasks[taskId].tMoveDir != MOVE_NONE) @@ -878,7 +878,7 @@ static void Task_ViewClock_WaitFadeIn(u8 taskId) static void Task_ViewClock_HandleInput(u8 taskId) { InitClockWithRtc(taskId); - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) gTasks[taskId].func = Task_ViewClock_FadeOut; } diff --git a/src/wireless_communication_status_screen.c b/src/wireless_communication_status_screen.c index 81fa16720..87b200f14 100644 --- a/src/wireless_communication_status_screen.c +++ b/src/wireless_communication_status_screen.c @@ -237,7 +237,7 @@ static void PrintHeaderTexts(void) FillWindowPixelBuffer(1, PIXEL_FILL(0)); FillWindowPixelBuffer(2, PIXEL_FILL(0)); WCSS_AddTextPrinterParameterized(0, 1, sHeaderTexts[0], GetStringCenterAlignXOffset(1, sHeaderTexts[0], 0xC0), 6, COLORMODE_GREEN); - for (i = 0; i < (int)ARRAY_COUNT(sHeaderTexts[0]) - 1; i++) + for (i = 0; i < (int)ARRAY_COUNT(*sHeaderTexts) - 1; i++) { WCSS_AddTextPrinterParameterized(1, 1, sHeaderTexts[i + 1], 0, 30 * i + 8, COLORMODE_WHITE_LGRAY); } @@ -362,12 +362,12 @@ static u32 CountPlayersInGroupAndGetActivity(struct UnkStruct_x20 * unk20, u32 * { if (group_players(i) == 0) { - k = 0; //Should just be 1 without the increment after the loop ends but that doesn't match. + k = 0; for (j = 0; j < RFU_CHILD_MAX; j++) { if (unk20->gname_uname.gname.child_sprite_gender[j] != 0) k++; } - k++; //See above comment. + k++; groupCounts[group_type(i)] += k; } else |