diff options
Diffstat (limited to 'src')
35 files changed, 1716 insertions, 311 deletions
diff --git a/src/battle_2.c b/src/battle_2.c new file mode 100644 index 000000000..a9f0fd57a --- /dev/null +++ b/src/battle_2.c @@ -0,0 +1,977 @@ +#include "global.h" +#include "battle.h" +#include "main.h" +#include "text.h" +#include "palette.h" +#include "sprite.h" +#include "task.h" +#include "pokemon.h" +#include "species.h" +#include "link.h" +#include "name_string_util.h" +#include "battle_setup.h" + +struct UnknownStruct5 +{ + u32 unk0; + u32 unk4; + u32 unk8; +}; + +struct UnknownStruct6 +{ + u16 unk0[0xA0]; + u8 fillerA0[0x640]; + u16 unk780[0xA0]; +}; + +struct UnknownStruct7 +{ + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; +}; + +struct UnknownStruct8 +{ + u8 unk0[7]; + u8 unk7; + u8 unk8[18]; + u8 unk1A; +}; + +struct UnknownPokemonStruct2 +{ + /*0x00*/ u16 species; + /*0x02*/ u16 heldItem; + /*0x04*/ u8 nickname[11]; + /*0x0F*/ u8 level; + /*0x10*/ u16 hp; + /*0x12*/ u16 maxhp; + /*0x14*/ u32 status; + /*0x18*/ u32 personality; + /*0x1C*/ u8 gender; + /*0x1D*/ u8 language; +}; + +extern const struct UnknownStruct5 gUnknown_081F9674; +extern const u8 gUnknown_081F96C8[]; +extern const struct Trainer gTrainers[]; +extern const u8 gSpeciesNames[][11]; +extern const struct BattleMove gBattleMoves[]; + +extern u8 ewram[]; +#define ewram0 (*(struct UnknownStruct7 *)(ewram + 0x0)) +#define ewram4 (*(struct UnknownStruct8 *)(ewram + 0x4)) +#define ewram160CB (ewram[0x160CB]) +#define ewram1D000 ((struct Pokemon *)(ewram + 0x1D000)) + +extern struct UnknownPokemonStruct2 gUnknown_02023A00[]; +extern u8 gUnknown_02024D1E[]; +extern u8 gUnknown_02024D1F[]; // I don't actually know what type this is. +extern u16 gUnknown_030041B0; +extern u16 gUnknown_030041B4; +extern u16 gUnknown_030041B8; +extern struct Window gUnknown_030041D0; +extern struct Window gUnknown_03004210; +extern struct Window gUnknown_03004250; +extern u16 gUnknown_03004240; +extern u16 gUnknown_03004280; +extern u16 gUnknown_03004288; +extern u16 gUnknown_030042A0; +extern u16 gUnknown_030042A4; +extern u16 gUnknown_030042C0; +extern u16 gUnknown_030042C4; +extern MainCallback gUnknown_030042D0; +extern struct UnknownStruct6 gUnknown_03004DE0; +//extern u16 gUnknown_03004DE0[][0xA0]; // possibly? +extern u16 gBattleTypeFlags; +extern s8 gBattleTerrain; // I'm not sure if this is supposed to be s8 or u8. Regardless, it must have the same type as the return value of GetBattleTerrain. +extern u8 gReservedSpritePaletteCount; +extern u16 gTrainerBattleOpponent; +extern struct BattleEnigmaBerry gEnigmaBerries[]; +extern u16 gBlockRecvBuffer[MAX_LINK_PLAYERS][BLOCK_BUFFER_SIZE / 2]; + +extern void sub_800B858(void); +extern void dp12_8087EA4(void); +extern void sub_80895F8(); +extern void sub_800D6D4(); +extern void sub_800DAB8(); +extern void sub_800E23C(); +extern void setup_poochyena_battle(); +extern void SetWildMonHeldItem(void); +extern void AdjustFriendship(struct Pokemon *, u8); +extern void sub_800DE30(u8); +extern void sub_800B950(void); +extern u8 battle_load_something(); +extern void OpenPartyMenu(); + +void sub_800E7F8(void); +void sub_800EC9C(void); +void sub_800F104(void); +void sub_800F298(void); +void sub_800F808(void); +void sub_800F838(struct Sprite *); +u8 CreateNPCTrainerParty(struct Pokemon *, u16); +void sub_800FCFC(void); +void sub_8010824(void); + +void sub_800E7C4(void) +{ + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) + { + sub_800B858(); + SetMainCallback2(sub_800F104); + gUnknown_02024D1E[0] = 0; + } + else + { + sub_800E7F8(); + } +} + +void sub_800E7F8(void) +{ + s32 i; + + SetHBlankCallback(NULL); + SetVBlankCallback(NULL); + + CpuFill32(0, (void *)VRAM, VRAM_SIZE); + + REG_MOSAIC = 0; + REG_WIN0H = 0xF0; + REG_WIN0V = 0x5051; + REG_WININ = 0; + REG_WINOUT = 0; + gUnknown_030042C4 = 0xF0; + gUnknown_03004240 = 0x5051; + dp12_8087EA4(); + + for (i = 0; i < 80; i++) + { + gUnknown_03004DE0.unk0[i] = 0xF0; + gUnknown_03004DE0.unk780[i] = 0xF0; + } + for (i = 80; i < 160; i++) + { + asm(""::"r"(i)); // Needed to stop the compiler from optimizing out the loop counter + gUnknown_03004DE0.unk0[i] = 0xFF10; + gUnknown_03004DE0.unk780[i] = 0xFF10; + } + sub_80895F8(gUnknown_081F9674.unk0, gUnknown_081F9674.unk4, gUnknown_081F9674.unk8); + SetUpWindowConfig(&gWindowConfig_81E6C58); + ResetPaletteFade(); + gUnknown_030042A4 = 0; + gUnknown_030042A0 = 0; + gUnknown_030042C0 = 0; + gUnknown_030041B4 = 0; + gUnknown_03004288 = 0; + gUnknown_03004280 = 0; + gUnknown_030041B0 = 0; + gUnknown_030041B8 = 0; + gBattleTerrain = GetBattleTerrain(); + InitWindowFromConfig(&gUnknown_03004210, &gWindowConfig_81E6C58); + InitWindowFromConfig(&gUnknown_030041D0, &gWindowConfig_81E71D0); + InitWindowFromConfig(&gUnknown_03004250, &gWindowConfig_81E71EC); + sub_800D6D4(); + sub_800DAB8(); + ResetSpriteData(); + ResetTasks(); + sub_800E23C(); + FreeAllSpritePalettes(); + gReservedSpritePaletteCount = 4; + SetVBlankCallback(sub_800FCFC); + setup_poochyena_battle(); + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) + SetMainCallback2(sub_800F298); + else + SetMainCallback2(sub_800EC9C); + if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) + { + CreateNPCTrainerParty(gEnemyParty, gTrainerBattleOpponent); + SetWildMonHeldItem(); + } + gMain.inBattle = TRUE; + for (i = 0; i < 6; i++) + AdjustFriendship(&gPlayerParty[i], 3); + gUnknown_02024D1E[0] = 0; +} + +void sub_800E9EC(void) +{ + u16 r6 = 0; + u16 species; + u16 hp; + u32 status; + s32 i; + + for (i = 0; i < 6; i++) + { + species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + hp = GetMonData(&gPlayerParty[i], MON_DATA_HP); + status = GetMonData(&gPlayerParty[i], MON_DATA_STATUS); + + if (species == 0) + continue; + if (species != SPECIES_EGG && hp != 0 && status == 0) + r6 |= 1 << i * 2; + + if (species == 0) + continue; + if (hp != 0 && (species == SPECIES_EGG || status != 0)) + r6 |= 2 << i * 2; + + if (species == 0) + continue; + if (species != SPECIES_EGG && hp == 0) + r6 |= 3 << i * 2; + } + ewram0.unk2 = r6; + ewram0.unk3 = r6 >> 8; +} + +void sub_800EAAC(void) +{ + s32 i; + struct UnknownStruct8 *_ewram4 = &ewram4; + + for (i = 0; i < 7; i++) + _ewram4->unk0[i] = gSaveBlock1.enigmaBerry.berry.name[i]; + for (i = 0; i < 18; i++) + _ewram4->unk8[i] = gSaveBlock1.enigmaBerry.itemEffect[i]; + _ewram4->unk7 = gSaveBlock1.enigmaBerry.holdEffect; + _ewram4->unk1A = gSaveBlock1.enigmaBerry.holdEffectParam; +} + +void sub_800EB08(void) +{ + s32 i; + s32 j; + + if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) + { + for (i = 0; i < 7; i++) + { + gEnigmaBerries[0].name[i] = gSaveBlock1.enigmaBerry.berry.name[i]; + gEnigmaBerries[2].name[i] = gSaveBlock1.enigmaBerry.berry.name[i]; + } + for (i = 0; i < 18; i++) + { + gEnigmaBerries[0].itemEffect[i] = gSaveBlock1.enigmaBerry.itemEffect[i]; + gEnigmaBerries[2].itemEffect[i] = gSaveBlock1.enigmaBerry.itemEffect[i]; + } + gEnigmaBerries[0].holdEffect = gSaveBlock1.enigmaBerry.holdEffect; + gEnigmaBerries[2].holdEffect = gSaveBlock1.enigmaBerry.holdEffect; + gEnigmaBerries[0].holdEffectParam = gSaveBlock1.enigmaBerry.holdEffectParam; + gEnigmaBerries[2].holdEffectParam = gSaveBlock1.enigmaBerry.holdEffectParam; + } + else + { + s32 numPlayers; + struct BattleEnigmaBerry *src; + u8 r4; + + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) + numPlayers = 4; + else + numPlayers = 2; + for (i = 0; i < numPlayers; i++) + { + src = (struct BattleEnigmaBerry *)(gBlockRecvBuffer[i] + 2); + r4 = gLinkPlayers[i].lp_field_18; + + for (j = 0; j < 7; j++) + gEnigmaBerries[r4].name[j] = src->name[j]; + for (j = 0; j < 18; j++) + gEnigmaBerries[r4].itemEffect[j] = src->itemEffect[j]; + gEnigmaBerries[r4].holdEffect = src->holdEffect; + gEnigmaBerries[r4].holdEffectParam = src->holdEffectParam; + } + } +} + +void shedinja_something(struct Pokemon *pkmn) +{ + u8 nickname[POKEMON_NAME_LENGTH + 1]; + u8 language = 1; + + if (GetMonData(pkmn, MON_DATA_SPECIES) == SPECIES_SHEDINJA + && GetMonData(pkmn, MON_DATA_LANGUAGE) != language) + { + GetMonData(pkmn, MON_DATA_NICKNAME, nickname); + if (StringCompareWithoutExtCtrlCodes(nickname, gUnknown_081F96C8) == 0) + SetMonData(pkmn, MON_DATA_LANGUAGE, &language); + } +} + +void sub_800EC9C(void) +{ + u8 playerId; + u8 enemyId; + + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + playerId = GetMultiplayerId(); + ewram160CB = playerId; + enemyId = playerId ^ 1; + + switch (gUnknown_02024D1E[0]) + { + case 0: + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + { + ewram0.unk0 = 1; + ewram0.unk1 = 1; + sub_800E9EC(); + sub_800EAAC(); + SendBlock(bitmask_all_link_players_but_self(), &ewram0, 32); + gUnknown_02024D1E[0] = 1; + } + } + else + { + gBattleTypeFlags |= BATTLE_TYPE_WILD; + gUnknown_02024D1E[0] = 8; + sub_800EB08(); + } + break; + case 1: + if ((GetBlockReceivedStatus() & 3) == 3) + { + s32 id; + u8 taskId; + + ResetBlockReceivedFlags(); + id = 0; + if (gBlockRecvBuffer[0][0] == 0x100) + { + if (playerId == 0) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + id++; + } + if (id == 0) + { + if (gBlockRecvBuffer[0][0] == gBlockRecvBuffer[1][0]) + { + if (playerId == 0) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + id++; + } + if (id == 0) + { + while (id < 2) + { + if (gBlockRecvBuffer[id][0] > 0x0101 && id != playerId) + break; + id++; + } + if (id == 2) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + } + } + sub_800EB08(); + taskId = CreateTask(sub_800DE30, 0); + gTasks[taskId].data[1] = 0x10E; + gTasks[taskId].data[2] = 0x5A; + gTasks[taskId].data[5] = 0; + gTasks[taskId].data[3] = ewram0.unk2 | (ewram0.unk3 << 8); + gTasks[taskId].data[4] = gBlockRecvBuffer[enemyId][1]; + gUnknown_02024D1E[0]++; + } + break; + case 2: + if (sub_8007ECC()) + { + SendBlock(bitmask_all_link_players_but_self(), gPlayerParty, sizeof(*gPlayerParty) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 3: + if ((GetBlockReceivedStatus() & 3) == 3) + { + ResetBlockReceivedFlags(); + memcpy(gEnemyParty, gBlockRecvBuffer[enemyId], sizeof(*gEnemyParty) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 4: + if (sub_8007ECC()) + { + SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 2, sizeof(*gPlayerParty) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 5: + if ((GetBlockReceivedStatus() & 3) == 3) + { + ResetBlockReceivedFlags(); + memcpy(gEnemyParty + 2, gBlockRecvBuffer[enemyId], sizeof(*gEnemyParty) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 6: + if (sub_8007ECC()) + { + SendBlock(bitmask_all_link_players_but_self(), gPlayerParty + 4, sizeof(*gPlayerParty) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 7: + if ((GetBlockReceivedStatus() & 3) == 3) + { + ResetBlockReceivedFlags(); + memcpy(gEnemyParty + 4, gBlockRecvBuffer[enemyId], sizeof(*gEnemyParty) * 2); + shedinja_something(&gEnemyParty[0]); + shedinja_something(&gEnemyParty[1]); + shedinja_something(&gEnemyParty[2]); + shedinja_something(&gEnemyParty[3]); + shedinja_something(&gEnemyParty[4]); + shedinja_something(&gEnemyParty[5]); + gUnknown_02024D1E[0]++; + } + break; + case 8: + sub_800B950(); + gUnknown_02024D1E[0]++; + gUnknown_02024D1E[1] = 0; + gUnknown_02024D1E[2] = 0; + break; + case 9: + if (battle_load_something(gUnknown_02024D1F, gUnknown_02024D1F + 1) != 0) + { + gUnknown_030042D0 = gMain.callback1; + gMain.callback1 = sub_8010824; + SetMainCallback2(sub_800F808); + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + gTrainerBattleOpponent = 0x800; + gBattleTypeFlags |= BATTLE_TYPE_20; + } + } + break; + } +} + +void sub_800F02C(void) +{ + s32 i; + + for (i = 0; i < 3; i++) + { + u8 *nickname = gUnknown_02023A00[i].nickname; + + gUnknown_02023A00[i].species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES); + gUnknown_02023A00[i].heldItem = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM); + GetMonData(&gPlayerParty[i], MON_DATA_NICKNAME, nickname); + gUnknown_02023A00[i].level = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); + gUnknown_02023A00[i].hp = GetMonData(&gPlayerParty[i], MON_DATA_HP); + gUnknown_02023A00[i].maxhp = GetMonData(&gPlayerParty[i], MON_DATA_MAX_HP); + gUnknown_02023A00[i].status = GetMonData(&gPlayerParty[i], MON_DATA_STATUS); + gUnknown_02023A00[i].personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); + gUnknown_02023A00[i].gender = GetMonGender(&gPlayerParty[i]); + StripExtCtrlCodes(nickname); + gUnknown_02023A00[i].language = GetMonData(&gPlayerParty[i], MON_DATA_LANGUAGE); + if (gUnknown_02023A00[i].language != 1) + PadNameString(nickname, 0); + } + memcpy(ewram, gUnknown_02023A00, 0x60); +} + +void sub_800F104(void) +{ + u8 playerId; + MainCallback *pSavedCallback; + u16 *pSavedBattleTypeFlags; + + playerId = GetMultiplayerId(); + ewram160CB = playerId; + // Seriously, Game Freak? + pSavedCallback = (MainCallback *)(ewram + 0x160C4); + pSavedBattleTypeFlags = (u16 *)(ewram + 0x160C2); + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + + switch (gUnknown_02024D1E[0]) + { + case 0: + if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + { + sub_800F02C(); + SendBlock(bitmask_all_link_players_but_self(), ewram, 0x60); + gUnknown_02024D1E[0]++; + } + break; + case 1: + if ((GetBlockReceivedStatus() & 0xF) == 0xF) + { + s32 i; + + ResetBlockReceivedFlags(); + for (i = 0; i < 4; i++) + { + if (i != playerId) + { + if ((!(gLinkPlayers[i].lp_field_18 & 1) && !(gLinkPlayers[playerId].lp_field_18 & 1)) + || ((gLinkPlayers[i].lp_field_18 & 1) && (gLinkPlayers[playerId].lp_field_18 & 1))) + memcpy(gUnknown_02023A00, gBlockRecvBuffer[i], 0x60); + } + } + gUnknown_02024D1E[0]++; + *pSavedCallback = gMain.savedCallback; + *pSavedBattleTypeFlags = gBattleTypeFlags; + gMain.savedCallback = sub_800F104; + OpenPartyMenu(5, 0); + } + break; + case 2: + if (!gPaletteFade.active) + { + gUnknown_02024D1E[0] = 3; + sub_800832C(); + } + break; + case 3: + if (gReceivedRemoteLinkPlayers == 0) + { + gBattleTypeFlags = *pSavedBattleTypeFlags; + gMain.savedCallback = *pSavedCallback; + SetMainCallback2(sub_800E7F8); + } + break; + } +} + +void sub_800F298(void) +{ + u8 playerId; + s32 id; + + playerId = GetMultiplayerId(); + ewram160CB = playerId; + RunTasks(); + AnimateSprites(); + BuildOamBuffer(); + switch (gUnknown_02024D1E[0]) + { + case 0: + if (gReceivedRemoteLinkPlayers != 0 && sub_8007ECC()) + { + ewram0.unk0 = 1; + ewram0.unk1 = 1; + sub_800E9EC(); + sub_800EAAC(); + SendBlock(bitmask_all_link_players_but_self(), ewram, 0x20); + gUnknown_02024D1E[0]++; + } + break; + case 1: + if ((GetBlockReceivedStatus() & 0xF) == 0xF) + { + u8 taskId; + + ResetBlockReceivedFlags(); + id = 0; + if (gBlockRecvBuffer[0][0] == 0x100) + { + if (playerId == 0) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + id++; + } + if (id == 0) + { + s32 i; + + for (i = 0; i < MAX_LINK_PLAYERS; i++) + { + if (gBlockRecvBuffer[0][0] != gBlockRecvBuffer[i][0]) + break; + } + if (i == MAX_LINK_PLAYERS) + { + if (playerId == 0) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + id++; + } + if (id == 0) + { + while (id < MAX_LINK_PLAYERS) + { + if (gBlockRecvBuffer[id][0] == 0x0101 && id != playerId) + if (id < playerId) + break; + if (gBlockRecvBuffer[id][0] > 0x0101 && id != playerId) + break; + id++; + } + if (id == MAX_LINK_PLAYERS) + gBattleTypeFlags |= 12; + else + gBattleTypeFlags |= 8; + } + } + sub_800EB08(); + memcpy(ewram1D000, gPlayerParty, sizeof(struct Pokemon) * 3); + taskId = CreateTask(sub_800DE30, 0); + gTasks[taskId].data[1] = 0x10E; + gTasks[taskId].data[2] = 0x5A; + gTasks[taskId].data[5] = 0; + gTasks[taskId].data[3] = 0; + gTasks[taskId].data[4] = 0; + for (id = 0; id < MAX_LINK_PLAYERS; id++) + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + gTasks[taskId].data[3] |= gBlockRecvBuffer[id][1] & 0x3F; + break; + case 1: + gTasks[taskId].data[4] |= gBlockRecvBuffer[id][1] & 0x3F; + break; + case 2: + gTasks[taskId].data[3] |= (gBlockRecvBuffer[id][1] & 0x3F) << 6; + break; + case 3: + gTasks[taskId].data[4] |= (gBlockRecvBuffer[id][1] & 0x3F) << 6; + break; + } + } + ZeroPlayerPartyMons(); + ZeroEnemyPartyMons(); + gUnknown_02024D1E[0]++; + goto step_2; + } + break; + case 2: + step_2: + if (sub_8007ECC()) + { + SendBlock(bitmask_all_link_players_but_self(), ewram1D000, sizeof(struct Pokemon) * 2); + gUnknown_02024D1E[0]++; + } + break; + case 3: + if ((GetBlockReceivedStatus() & 0xF) == 0xF) + { + ResetBlockReceivedFlags(); + for (id = 0; id < MAX_LINK_PLAYERS; id++) + { + if (id == playerId) + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gPlayerParty, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + case 1: + case 2: + memcpy(gPlayerParty + 3, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + } + } + else + { + if ((!(gLinkPlayers[id].lp_field_18 & 1) && !(gLinkPlayers[playerId].lp_field_18 & 1)) + || ((gLinkPlayers[id].lp_field_18 & 1) && (gLinkPlayers[playerId].lp_field_18 & 1))) + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gPlayerParty, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + case 1: + case 2: + memcpy(gPlayerParty + 3, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + } + } + else + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gEnemyParty, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + case 1: + case 2: + memcpy(gEnemyParty + 3, gBlockRecvBuffer[id], sizeof(struct Pokemon) * 2); + break; + } + } + } + } + gUnknown_02024D1E[0]++; + } + break; + case 4: + if (sub_8007ECC()) + { + SendBlock(bitmask_all_link_players_but_self(), ewram1D000 + 2, sizeof(struct Pokemon)); + gUnknown_02024D1E[0]++; + } + break; + case 5: + if ((GetBlockReceivedStatus() & 0xF) == 0xF) + { + ResetBlockReceivedFlags(); + for (id = 0; id < MAX_LINK_PLAYERS; id++) + { + if (id == playerId) + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gPlayerParty + 2, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + case 1: + case 2: + memcpy(gPlayerParty + 5, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + } + } + else + { + if ((!(gLinkPlayers[id].lp_field_18 & 1) && !(gLinkPlayers[playerId].lp_field_18 & 1)) + || ((gLinkPlayers[id].lp_field_18 & 1) && (gLinkPlayers[playerId].lp_field_18 & 1))) + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gPlayerParty + 2, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + case 1: + case 2: + memcpy(gPlayerParty + 5, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + } + } + else + { + switch (gLinkPlayers[id].lp_field_18) + { + case 0: + case 3: + memcpy(gEnemyParty + 2, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + case 1: + case 2: + memcpy(gEnemyParty + 5, gBlockRecvBuffer[id], sizeof(struct Pokemon)); + break; + } + } + } + } + + shedinja_something(&gPlayerParty[0]); + shedinja_something(&gPlayerParty[1]); + shedinja_something(&gPlayerParty[2]); + shedinja_something(&gPlayerParty[3]); + shedinja_something(&gPlayerParty[4]); + shedinja_something(&gPlayerParty[5]); + + shedinja_something(&gEnemyParty[0]); + shedinja_something(&gEnemyParty[1]); + shedinja_something(&gEnemyParty[2]); + shedinja_something(&gEnemyParty[3]); + shedinja_something(&gEnemyParty[4]); + shedinja_something(&gEnemyParty[5]); + + gUnknown_02024D1E[0]++; + } + break; + case 6: + sub_800B950(); + gUnknown_02024D1E[0]++; + gUnknown_02024D1E[1] = 0; + gUnknown_02024D1E[2] = 0; + break; + case 7: + if (battle_load_something(gUnknown_02024D1F, gUnknown_02024D1F + 1) != 0) + { + gUnknown_030042D0 = gMain.callback1; + gMain.callback1 = sub_8010824; + SetMainCallback2(sub_800F808); + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + { + gTrainerBattleOpponent = 0x800; + gBattleTypeFlags |= BATTLE_TYPE_20; + } + } + break; + } +} + +void sub_800F808(void) +{ + AnimateSprites(); + BuildOamBuffer(); + sub_800374C(&gUnknown_03004210); + UpdatePaletteFade(); + RunTasks(); +} + +void sub_800F828(struct Sprite *sprite) +{ + sprite->data0 = 0; + sprite->callback = sub_800F838; +} + +void sub_800F838(struct Sprite *sprite) +{ + u16 *arr = (u16 *)ewram; + + switch (sprite->data0) + { + case 0: + sprite->data0++; + sprite->data1 = 0; + sprite->data2 = 0x281; + sprite->data3 = 0; + sprite->data4 = 1; + // fall through + case 1: + sprite->data4--; + if (sprite->data4 == 0) + { + s32 i; + s32 r2; + s32 r0; + + sprite->data4 = 2; + r2 = sprite->data1 + sprite->data3 * 32; + r0 = sprite->data2 - sprite->data3 * 32; + for (i = 0; i < 29; i += 2) + { + arr[r2 + i] = 0x3D; + arr[r0 + i] = 0x3D; + } + sprite->data3++; + if (sprite->data3 == 21) + { + sprite->data0++; + sprite->data1 = 32; + } + } + break; + case 2: + sprite->data1--; + if (sprite->data1 == 20) + SetMainCallback2(sub_800E7C4); + break; + } +} + +u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum) +{ + u32 nameHash = 0; + s32 i; + + if (trainerNum == 0x400) + return 0; + + if ((gBattleTypeFlags & 0x908) == 8) + { + ZeroEnemyPartyMons(); + for (i = 0; i < gTrainers[trainerNum].partySize; i++) + { + u32 personalityValue; + s32 j; + u8 fixedIV; + + if (gTrainers[trainerNum].doubleBattle == TRUE) + personalityValue = 0x80; + else if (gTrainers[trainerNum].encounterMusic_gender & 0x80) + personalityValue = 0x78; + else + personalityValue = 0x88; + + for (j = 0; gTrainers[trainerNum].trainerName[j] != 0xFF; j++) + nameHash += gTrainers[trainerNum].trainerName[j]; + + switch (gTrainers[trainerNum].partyFlags) + { + case 0: + { + struct TrainerPartyMember0 *partyData = gTrainers[trainerNum].party; + + for (j = 0; gSpeciesNames[partyData[i].species][j] != 0xFF; j++) + nameHash += gSpeciesNames[partyData[i].species][j]; + personalityValue += nameHash << 8; + fixedIV = partyData[i].iv * 31 / 255; + CreateMon(&party[i], partyData[i].species, partyData[i].level, fixedIV, TRUE, personalityValue, 2, 0); + break; + } + case 1: + { + struct TrainerPartyMember1 *partyData = gTrainers[trainerNum].party; + + for (j = 0; gSpeciesNames[partyData[i].species][j] != 0xFF; j++) + nameHash += gSpeciesNames[partyData[i].species][j]; + personalityValue += nameHash << 8; + fixedIV = partyData[i].iv * 31 / 255; + CreateMon(&party[i], partyData[i].species, partyData[i].level, fixedIV, TRUE, personalityValue, 2, 0); + + for (j = 0; j < 4; j++) + { + SetMonData(&party[i], MON_DATA_MOVE1 + j, (u8 *)&partyData[i].moves[j]); + SetMonData(&party[i], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); + } + break; + } + case 2: + { + struct TrainerPartyMember2 *partyData = gTrainers[trainerNum].party; + + for (j = 0; gSpeciesNames[partyData[i].species][j] != 0xFF; j++) + nameHash += gSpeciesNames[partyData[i].species][j]; + personalityValue += nameHash << 8; + fixedIV = partyData[i].iv * 31 / 255; + CreateMon(&party[i], partyData[i].species, partyData[i].level, fixedIV, TRUE, personalityValue, 2, 0); + + SetMonData(&party[i], MON_DATA_HELD_ITEM, (u8 *)&partyData[i].heldItem); + break; + } + case 3: + { + struct TrainerPartyMember3 *partyData = gTrainers[trainerNum].party; + + for (j = 0; gSpeciesNames[partyData[i].species][j] != 0xFF; j++) + nameHash += gSpeciesNames[partyData[i].species][j]; + personalityValue += nameHash << 8; + fixedIV = partyData[i].iv * 31 / 255; + CreateMon(&party[i], partyData[i].species, partyData[i].level, fixedIV, TRUE, personalityValue, 2, 0); + + SetMonData(&party[i], MON_DATA_HELD_ITEM, (u8 *)&partyData[i].heldItem); + for (j = 0; j < 4; j++) + { + SetMonData(&party[i], MON_DATA_MOVE1 + j, (u8 *)&partyData[i].moves[j]); + SetMonData(&party[i], MON_DATA_PP1 + j, &gBattleMoves[partyData[i].moves[j]].pp); + } + break; + } + } + } + gBattleTypeFlags |= gTrainers[trainerNum].doubleBattle; + } + return gTrainers[trainerNum].partySize; +}
\ No newline at end of file diff --git a/src/battle_811DA74.c b/src/battle_811DA74.c index 4d66910ba..328b45f49 100644 --- a/src/battle_811DA74.c +++ b/src/battle_811DA74.c @@ -69,7 +69,6 @@ extern void c3_0802FDF4(u8); extern void sub_8031F88(); extern void sub_8141828(); extern void c2_8011A1C(void); -extern void sub_800832C(); extern void dp01_prepare_buffer_wireless_probably(); extern void dp01_build_cmdbuf_x1D_1D_numargs_varargs(int, u16, void *); diff --git a/src/battle_anim.c b/src/battle_anim.c index b9aa5b898..bdb34365f 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -65,7 +65,6 @@ extern u8 sub_8078874(u8); extern void sub_8078914(); extern u8 sub_80AEB1C(); extern void sub_80E4EF8(int, int, int, int, u16, u8, int); -extern void sub_800D238(); extern u8 sub_80789BC(); extern void sub_80AB2AC(void); extern void sub_800D7B8(void); diff --git a/src/battle_interface.c b/src/battle_interface.c index d097598b5..9938c4b54 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1498,7 +1498,7 @@ u8 sub_8044804(u8 a, const struct UnknownStruct8 *b, u8 c, u8 d) { for (i = 0; i < 6; i++) //_08044A9A { - if (gBattleTypeFlags & BATTLE_TYPE_40) // && b[i] != 0xFFFF && b[i] + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) // && b[i] != 0xFFFF && b[i] { if (b[i].unk0 == 0xFFFF) { @@ -1546,7 +1546,7 @@ u8 sub_8044804(u8 a, const struct UnknownStruct8 *b, u8 c, u8 d) // Mismatch occurrs in this loop initialization for (i = 0; i < 6; i++) { - if (gBattleTypeFlags & BATTLE_TYPE_40) + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { if (b[i].unk0 == 0xFFFF) { diff --git a/src/berry.c b/src/berry.c index 6c12af053..257248e5c 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1130,7 +1130,7 @@ bool32 BerryTreeGrow(struct BerryTree *tree) return TRUE; } -void BerryTreeTimeUpdate(int time) +void BerryTreeTimeUpdate(s32 minutes) { int i; struct BerryTree *tree; @@ -1141,27 +1141,27 @@ void BerryTreeTimeUpdate(int time) if (tree->berry && tree->stage && !tree->growthSparkle) { - if (time >= GetStageDurationByBerryType(tree->berry) * 71) + if (minutes >= GetStageDurationByBerryType(tree->berry) * 71) { *tree = gBlankBerryTree; } else { - int time2 = time; + s32 time = minutes; - while (time2 != 0) + while (time != 0) { - if (tree->secondsUntilNextStage > time2) + if (tree->minutesUntilNextStage > time) { - tree->secondsUntilNextStage -= time2; + tree->minutesUntilNextStage -= time; break; } - time2 -= tree->secondsUntilNextStage; - tree->secondsUntilNextStage = GetStageDurationByBerryType(tree->berry); + time -= tree->minutesUntilNextStage; + tree->minutesUntilNextStage = GetStageDurationByBerryType(tree->berry); if (!BerryTreeGrow(tree)) break; if (tree->stage == 5) - tree->secondsUntilNextStage *= 4; + tree->minutesUntilNextStage *= 4; } } } @@ -1174,12 +1174,12 @@ void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 sparkle) *tree = gBlankBerryTree; tree->berry = berry; - tree->secondsUntilNextStage = GetStageDurationByBerryType(berry); + tree->minutesUntilNextStage = GetStageDurationByBerryType(berry); tree->stage = stage; if (stage == 5) { tree->berryYield = CalcBerryYield(tree); - tree->secondsUntilNextStage *= 4; + tree->minutesUntilNextStage *= 4; } if (!sparkle) { diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c index 103f0a85e..511b88c5a 100644 --- a/src/berry_tag_screen.c +++ b/src/berry_tag_screen.c @@ -178,9 +178,9 @@ void BerryTagScreen_814625C(u8 taskId) static void sub_8146288(void) { - REG_BG1CNT = 0x502; - REG_BG2CNT = 0x600; - REG_BG3CNT = 0x703; + REG_BG1CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(5) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG2CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(6) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; gUnknown_030041B4 = 0; } diff --git a/src/cable_club.c b/src/cable_club.c new file mode 100644 index 000000000..45fb347f3 --- /dev/null +++ b/src/cable_club.c @@ -0,0 +1,304 @@ +#include "global.h" +#include "asm.h" +#include "field_message_box.h" +#include "link.h" +#include "main.h" +#include "script.h" +#include "songs.h" +#include "sound.h" +#include "string_util.h" +#include "task.h" +#include "text.h" +#include "trainer_card.h" + +extern u16 gScriptResult; +extern struct TrainerCard gTrainerCards[4]; + +extern u8 gUnknown_03004860; +extern u8 gFieldLinkPlayerCount; + +extern u8 gUnknown_081A4932[]; +extern const u8 gUnknown_081A4975[]; + +void sub_8082D4C(); +void sub_8082D60(u8, u8); +u16 sub_8082D9C(u8, u8); +u32 sub_8082DF4(u8); +u32 sub_8082E28(u8); +u32 sub_8082EB8(u8); +void sub_8082FEC(u8 taskId); +static void sub_80830E4(u8 taskId); +void sub_8083188(u8 taskId); +static void sub_8083288(u8 taskId); +static void sub_8083314(u8 taskId); +void sub_80833C4(u8 taskId); +void sub_8083418(u8 taskId); +u8 sub_8083444(u8 taskId); + +void sub_808303C(u8 taskId) { + s32 linkPlayerCount; + s16 *taskData; + + taskData = gTasks[taskId].data; + + linkPlayerCount = GetLinkPlayerCount_2(); + + if (sub_8082E28(taskId) == 1 || + sub_8082EB8(taskId) == 1 || + sub_8082DF4(taskId) == 1) + { + return; + } + + sub_8082D60(taskId, linkPlayerCount); + + if (!(gMain.newKeys & A_BUTTON)) + { + return; + } + + if (linkPlayerCount < taskData[1]) + { + return; + } + + sub_80081C8(linkPlayerCount); + sub_8082D4C(); + ConvertIntToDecimalStringN(gStringVar1, linkPlayerCount, STR_CONV_MODE_LEFT_ALIGN, 1); // r5 + ShowFieldAutoScrollMessage((u8 *) gUnknown_081A4975); + gTasks[taskId].func = sub_80830E4; +} + +#ifdef NONMATCHING +static void sub_80830E4(u8 taskId) { + if (sub_8082E28(taskId) == 1 || + sub_8082EB8(taskId) == 1 || + sub_8082DF4(taskId) == 1 || + GetFieldMessageBoxMode()) + { + return; + } + + if (sub_800820C() == GetLinkPlayerCount_2() && + !(gMain.heldKeys & B_BUTTON)) + { + ShowFieldAutoScrollMessage(gUnknown_081A4932); + gTasks[taskId].func = sub_8082FEC; + return; + } + + if (gMain.heldKeys & A_BUTTON) + { + PlaySE(SE_SELECT); + sub_8007F4C(); + gTasks[(u32) taskId].func = sub_8083188; + } +} +#else +__attribute__((naked)) +static void sub_80830E4(u8 taskId) { + asm(".syntax unified\n\ + push {r4-r6,lr}\n\ + lsls r0, 24\n\ + lsrs r5, r0, 24\n\ + adds r6, r5, 0\n\ + adds r0, r5, 0\n\ + bl sub_8082E28\n\ + cmp r0, 0x1\n\ + beq _08083178\n\ + adds r0, r5, 0\n\ + bl sub_8082EB8\n\ + cmp r0, 0x1\n\ + beq _08083178\n\ + adds r0, r5, 0\n\ + bl sub_8082DF4\n\ + cmp r0, 0x1\n\ + beq _08083178\n\ + bl GetFieldMessageBoxMode\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _08083178\n\ + bl sub_800820C\n\ + adds r4, r0, 0\n\ + bl GetLinkPlayerCount_2\n\ + lsls r4, 24\n\ + lsls r0, 24\n\ + cmp r4, r0\n\ + bne _08083132\n\ + ldr r0, _08083148 @ =gMain\n\ + ldrh r1, [r0, 0x2C]\n\ + movs r0, 0x2\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _08083158\n\ +_08083132:\n\ + ldr r0, _0808314C @ =gUnknown_081A4932\n\ + bl ShowFieldAutoScrollMessage\n\ + ldr r1, _08083150 @ =gTasks\n\ + lsls r0, r5, 2\n\ + adds r0, r5\n\ + lsls r0, 3\n\ + adds r0, r1\n\ + ldr r1, _08083154 @ =sub_8082FEC\n\ + str r1, [r0]\n\ + b _08083178\n\ + .align 2, 0\n\ +_08083148: .4byte gMain\n\ +_0808314C: .4byte gUnknown_081A4932\n\ +_08083150: .4byte gTasks\n\ +_08083154: .4byte sub_8082FEC\n\ +_08083158:\n\ + movs r0, 0x1\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _08083178\n\ + movs r0, 0x5\n\ + bl PlaySE\n\ + bl sub_8007F4C\n\ + ldr r0, _08083180 @ =gTasks\n\ + lsls r1, r6, 2\n\ + adds r1, r6\n\ + lsls r1, 3\n\ + adds r1, r0\n\ + ldr r0, _08083184 @ =sub_8083188\n\ + str r0, [r1]\n\ +_08083178:\n\ + pop {r4-r6}\n\ + pop {r0}\n\ + bx r0\n\ + .align 2, 0\n\ +_08083180: .4byte gTasks\n\ +_08083184: .4byte sub_8083188\n\ + .syntax divided\n"); +} +#endif + +void sub_8083188(u8 taskId) { + u8 local1, local2; + u16 *result; + + local1 = gTasks[taskId].data[1]; + local2 = gTasks[taskId].data[2]; + + + if (sub_8082DF4(taskId) == 1 || + sub_8083444(taskId) == 1) + { + return; + } + + if (GetLinkPlayerCount_2() != sub_800820C()) + { + gTasks[taskId].func = sub_8083418; + return; + } + + result = &gScriptResult; + *result = sub_8082D9C(local1, local2); + if (*result) + { + gTasks[taskId].func = sub_8083288; + } +} + +void sub_80831F8(u8 taskId) { + u8 local1, local2; + u16 *result; + + local1 = gTasks[taskId].data[1]; + local2 = gTasks[taskId].data[2]; + + if (sub_8082E28(taskId) == 1 || + sub_8082DF4(taskId) == 1) + { + return; + } + + result = &gScriptResult; + *result = sub_8082D9C(local1, local2); + if (*result == 0) + { + return; + } + + + if (*result == 3) + { + sub_800832C(); + HideFieldMessageBox(); + gTasks[taskId].func = sub_80833C4; + } + else + { + gFieldLinkPlayerCount = GetLinkPlayerCount_2(); + gUnknown_03004860 = GetMultiplayerId(); + sub_80081C8(gFieldLinkPlayerCount); + sub_8093390((struct TrainerCard *) gBlockSendBuffer); + gTasks[taskId].func = sub_8083314; + } +} + +static void sub_8083288(u8 taskId) { + if (sub_8082DF4(taskId) == 1) + { + return; + } + + if (gScriptResult == 3) + { + sub_800832C(); + HideFieldMessageBox(); + gTasks[taskId].func = sub_80833C4; + } + else + { + gFieldLinkPlayerCount = GetLinkPlayerCount_2(); + gUnknown_03004860 = GetMultiplayerId(); + sub_80081C8(gFieldLinkPlayerCount); + sub_8093390((struct TrainerCard *) gBlockSendBuffer); + gTasks[taskId].func = sub_8083314; + sub_8007E9C(2); + } +} + +static void sub_8083314(u8 taskId) { + u8 index; + + struct TrainerCard *trainerCards; + + if (sub_8082DF4(taskId) == 1) + { + return; + } + + if (GetBlockReceivedStatus() != sub_8008198()) + { + return; + } + + index = 0; + trainerCards = gTrainerCards; + for (index = 0; index < GetLinkPlayerCount(); index++) + { + void *src; + src = gBlockRecvBuffer[index]; + memcpy(&trainerCards[index], src, sizeof(struct TrainerCard)); + } + + SetSuppressLinkErrorMessage(FALSE); + ResetBlockReceivedFlags(); + HideFieldMessageBox(); + + if (gScriptResult == 1) + { + u16 linkType; + linkType = gLinkType; + sub_8082D4C(0x00004411, linkType); + EnableBothScriptContexts(); + DestroyTask(taskId); + return; + } + + sub_800832C(); + gTasks[taskId].func = sub_80833C4; +} diff --git a/src/clear_save_data_menu.c b/src/clear_save_data_menu.c index 6b0cc821a..21cd643ef 100644 --- a/src/clear_save_data_menu.c +++ b/src/clear_save_data_menu.c @@ -41,7 +41,7 @@ static void Task_InitMenu(u8 taskId) { ResetSpriteData(); - REG_DISPCNT = DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; SetVBlankCallback(VBlankCB_ClearSaveDataScreen); MenuDrawTextWindow(2, 14, 27, 19); @@ -148,8 +148,8 @@ static u8 InitClearSaveDataScreen(void) SetVBlankCallback(VBlankCB_InitClearSaveDataScreen); - REG_BG3CNT = 0x0703; - REG_DISPCNT = 0x0900; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_BG0_ON | DISPCNT_BG3_ON; gMain.state = 1; return 0; case 1: diff --git a/src/clock.c b/src/clock.c index 4ec49807c..b263e99ae 100644 --- a/src/clock.c +++ b/src/clock.c @@ -8,17 +8,17 @@ #include "rtc.h" #include "wallclock.h" -extern void sub_80FA220(u16); -extern void sub_80BE8C4(u16); -extern void sub_8080834(u16); +extern void UpdateDewfordTrendPerDay(u16); +extern void UpdateTVShowsPerDay(u16); +extern void UpdateWeatherPerDay(u16); extern void UpdatePartyPokerusTime(u16); extern void UpdateMirageRnd(u16); extern void UpdateBirchState(u16); -extern void sub_810F618(u16); +extern void SetShoalItemFlag(u16); static void InitTimeBasedEvents(void); static void UpdatePerDay(struct Time *time); -static void UpdatePerSecond(struct Time *time); +static void UpdatePerMinute(struct Time *time); static void ReturnFromStartWallClock(void); static void InitTimeBasedEvents(void) @@ -35,7 +35,7 @@ void DoTimeBasedEvents(void) { RtcCalcLocalTime(); UpdatePerDay(&gLocalTime); - UpdatePerSecond(&gLocalTime); + UpdatePerMinute(&gLocalTime); } } @@ -49,32 +49,32 @@ static void UpdatePerDay(struct Time *time) { newDays = time->days - days; ClearUpperFlags(); - sub_80FA220(newDays); - sub_80BE8C4(newDays); - sub_8080834(newDays); + UpdateDewfordTrendPerDay(newDays); + UpdateTVShowsPerDay(newDays); + UpdateWeatherPerDay(newDays); UpdatePartyPokerusTime(newDays); UpdateMirageRnd(newDays); UpdateBirchState(newDays); - sub_810F618(newDays); + SetShoalItemFlag(newDays); SetRandomLotteryNumber(newDays); *varPtr = time->days; } } -static void UpdatePerSecond(struct Time *time) +static void UpdatePerMinute(struct Time *time) { struct Time newTime; - s32 totalSeconds; + s32 minutes; CalcTimeDifference(&newTime, &gSaveBlock2.lastBerryTreeUpdate, time); - totalSeconds = 1440 * newTime.days + 60 * newTime.hours + newTime.minutes; + minutes = 1440 * newTime.days + 60 * newTime.hours + newTime.minutes; // there's no way to get the correct assembly other than with this nested if check. so dumb. - if (totalSeconds != 0) + if (minutes != 0) { - if (totalSeconds >= 0) + if (minutes >= 0) { - BerryTreeTimeUpdate(totalSeconds); + BerryTreeTimeUpdate(minutes); gSaveBlock2.lastBerryTreeUpdate = *time; } } diff --git a/src/contest_painting.c b/src/contest_painting.c index 08244597e..2ef50ee17 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -336,8 +336,8 @@ static void ContestPaintingInitBG(void) { REG_DISPCNT = 0; REG_IE |= INTR_FLAG_VBLANK; - REG_BG0CNT = 0x0C42; - REG_BG1CNT = 0x0A45; + REG_BG0CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(12) | BGCNT_MOSAIC | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(10) | BGCNT_MOSAIC | BGCNT_16COLOR | BGCNT_TXT256x256; REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; @@ -367,7 +367,7 @@ static void ContestPaintingMosaic(void) return; } - REG_BG1CNT = 0xA45; + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(10) | BGCNT_MOSAIC | BGCNT_16COLOR | BGCNT_TXT256x256; gUnknown_03000752 = gUnknown_03000754 / 2; REG_MOSAIC = (gUnknown_03000752 << 12) | (gUnknown_03000752 << 8) | (gUnknown_03000752 << 4) | (gUnknown_03000752 << 0); diff --git a/src/credits.c b/src/credits.c index 17d3507aa..01af78bce 100644 --- a/src/credits.c +++ b/src/credits.c @@ -474,8 +474,8 @@ void task_a_8143D04(u8 taskIdA) BeginNormalPaletteFade(-1, 0, 16, 0, 0); REG_BG3HOFS = 0; REG_BG3VOFS = 32; - REG_BG3CNT = 0x703; - REG_DISPCNT = 0x1940; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; gMain.state = 0; gUnknown_0203935C = 0; @@ -518,13 +518,13 @@ static void task_a_8143F3C(u8 taskIdA) FreeAllSpritePalettes(); BeginNormalPaletteFade(-1, 8, 16, 0, 0); - REG_BG0CNT = 0x700; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; backup = REG_IME; REG_IME = 0; REG_IE |= INTR_FLAG_VBLANK; REG_IME = backup; REG_DISPSTAT |= DISPSTAT_VBLANK_INTR; - REG_DISPCNT = 0x140; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON; gTasks[taskIdA].data[TDA_0] = 0x100; gTasks[taskIdA].func = task_a_8143FDC; diff --git a/src/dewford_trend.c b/src/dewford_trend.c index fe9311655..e4ce0c0c7 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -19,7 +19,7 @@ static bool8 SB1ContainsWords(u16 *a); static bool8 IsEasyChatPairEqual(u16 *words1, u16 *words2); static s16 sub_80FA828(struct EasyChatPair *a, u16 b); -void InitDewfordTrends(void) +void InitDewfordTrend(void) { u16 i; @@ -38,244 +38,63 @@ void InitDewfordTrends(void) sub_80FA46C(gSaveBlock1.easyChatPairs, 5, 0); } -#ifdef NONMATCHING -void sub_80FA220(u16 a) +void UpdateDewfordTrendPerDay(u16 a) { u16 i; - u32 sp0; - u32 sp4; if (a != 0) { - sp0 = a * 5; + u32 sp0 = a * 5; for (i = 0; i < 5; i++) { //_080FA24A - u32 r2 = sp0; u32 r4; + u32 r2 = sp0; + struct EasyChatPair *r5 = &gSaveBlock1.easyChatPairs[i]; - if (gSaveBlock1.easyChatPairs[i].unk1_6 == 0) + if (r5->unk1_6 == 0) { - if (gSaveBlock1.easyChatPairs[i].unk0_0 >= r2) + if (r5->unk0_0 >= (u16)r2) { - gSaveBlock1.easyChatPairs[i].unk0_0 -= r2; - if (gSaveBlock1.easyChatPairs[i].unk0_0 == 0) - gSaveBlock1.easyChatPairs[i].unk1_6 = 1; + r5->unk0_0 -= r2; + if (r5->unk0_0 == 0) + r5->unk1_6 = 1; continue; } //_080FA290 - r2 -= gSaveBlock1.easyChatPairs[i].unk0_0; - gSaveBlock1.easyChatPairs[i].unk1_6 = 1; + r2 -= r5->unk0_0; + r5->unk0_0 = 0; + r5->unk1_6 = 1; } //_080FA2A0 - r4 = gSaveBlock1.easyChatPairs[i].unk0_0 + r2; - if (r4 > gSaveBlock1.easyChatPairs[i].unk0_7) + r4 = r5->unk0_0 + r2; + if ((u16)r4 > r5->unk0_7) { - sp4 = r4 % gSaveBlock1.easyChatPairs[i].unk0_7; - r4 = r4 / gSaveBlock1.easyChatPairs[i].unk0_7; + u32 sp4 = r4 % r5->unk0_7; + r4 = r4 / r5->unk0_7; - if (r4 == 0) - gSaveBlock1.easyChatPairs[i].unk1_6 = 1; + r5->unk1_6 = r4 ^ 1; + if (r5->unk1_6) + r5->unk0_0 = sp4; else - gSaveBlock1.easyChatPairs[i].unk1_6 = 0; - - - if (gSaveBlock1.easyChatPairs[i].unk1_6) - { - gSaveBlock1.easyChatPairs[i].unk0_0 += sp4; - continue; - } //_080FA2FA - gSaveBlock1.easyChatPairs[i].unk0_7 -= sp4; - continue; + r5->unk0_0 = r5->unk0_7 - sp4; } - //_080FA310 - gSaveBlock1.easyChatPairs[i].unk0_0 = r4; + else + { + //_080FA310 + r5->unk0_0 = r4; - if (gSaveBlock1.easyChatPairs[i].unk0_0 == gSaveBlock1.easyChatPairs[i].unk0_7) - gSaveBlock1.easyChatPairs[i].unk1_6 = 0; + if (r5->unk0_0 == r5->unk0_7) + r5->unk1_6 = 0; + } } sub_80FA46C(gSaveBlock1.easyChatPairs, 5, 0); } //_080FA34E } -#else -__attribute__((naked)) -void sub_80FA220(u16 a) -{ - asm(".syntax unified\n\ - push {r4-r7,lr}\n\ - mov r7, r10\n\ - mov r6, r9\n\ - mov r5, r8\n\ - push {r5-r7}\n\ - sub sp, 0x8\n\ - lsls r0, 16\n\ - lsrs r1, r0, 16\n\ - cmp r1, 0\n\ - bne _080FA236\n\ - b _080FA34E\n\ -_080FA236:\n\ - lsls r0, r1, 2\n\ - adds r0, r1\n\ - str r0, [sp]\n\ - movs r0, 0\n\ - mov r10, r0\n\ - movs r1, 0x7F\n\ - mov r9, r1\n\ - movs r2, 0x80\n\ - negs r2, r2\n\ - mov r8, r2\n\ -_080FA24A:\n\ - ldr r2, [sp]\n\ - mov r4, r10\n\ - lsls r0, r4, 3\n\ - ldr r1, _080FA28C @ =gSaveBlock1 + 0x2DD4\n\ - adds r5, r0, r1\n\ - ldrb r6, [r5, 0x1]\n\ - movs r0, 0x40\n\ - ands r0, r6\n\ - cmp r0, 0\n\ - bne _080FA2A0\n\ - ldrb r4, [r5]\n\ - lsls r3, r4, 25\n\ - lsrs r1, r3, 25\n\ - lsls r0, r2, 16\n\ - lsrs r0, 16\n\ - cmp r1, r0\n\ - bcc _080FA290\n\ - adds r0, r1, 0\n\ - subs r0, r2\n\ - mov r2, r9\n\ - ands r0, r2\n\ - mov r1, r8\n\ - ands r1, r4\n\ - orrs r1, r0\n\ - strb r1, [r5]\n\ - movs r0, 0x7F\n\ - ands r1, r0\n\ - cmp r1, 0\n\ - bne _080FA336\n\ - movs r0, 0x40\n\ - orrs r0, r6\n\ - b _080FA334\n\ - .align 2, 0\n\ -_080FA28C: .4byte gSaveBlock1 + 0x2DD4\n\ -_080FA290:\n\ - lsrs r0, r3, 25\n\ - subs r2, r0\n\ - mov r0, r8\n\ - ands r0, r4\n\ - strb r0, [r5]\n\ - movs r0, 0x40\n\ - orrs r0, r6\n\ - strb r0, [r5, 0x1]\n\ -_080FA2A0:\n\ - ldrb r7, [r5]\n\ - lsls r0, r7, 25\n\ - lsrs r0, 25\n\ - adds r4, r0, r2\n\ - ldrh r0, [r5]\n\ - lsls r6, r0, 18\n\ - lsls r0, r4, 16\n\ - lsrs r0, 16\n\ - lsrs r1, r6, 25\n\ - cmp r0, r1\n\ - bls _080FA310\n\ - adds r0, r4, 0\n\ - bl __umodsi3\n\ - adds r3, r0, 0\n\ - lsrs r1, r6, 25\n\ - adds r0, r4, 0\n\ - str r3, [sp, 0x4]\n\ - bl __udivsi3\n\ - adds r4, r0, 0\n\ - movs r0, 0x1\n\ - eors r4, r0\n\ - ands r4, r0\n\ - lsls r2, r4, 6\n\ - ldrb r0, [r5, 0x1]\n\ - movs r4, 0x41\n\ - negs r4, r4\n\ - adds r1, r4, 0\n\ - ands r0, r1\n\ - orrs r0, r2\n\ - strb r0, [r5, 0x1]\n\ - movs r1, 0x40\n\ - ands r0, r1\n\ - ldr r3, [sp, 0x4]\n\ - cmp r0, 0\n\ - beq _080FA2FA\n\ - adds r1, r3, 0\n\ - mov r0, r9\n\ - ands r1, r0\n\ - mov r0, r8\n\ - ands r0, r7\n\ - orrs r0, r1\n\ - strb r0, [r5]\n\ - b _080FA336\n\ -_080FA2FA:\n\ - ldrh r0, [r5]\n\ - lsls r0, 18\n\ - lsrs r0, 25\n\ - subs r0, r3\n\ - mov r1, r9\n\ - ands r0, r1\n\ - mov r1, r8\n\ - ands r1, r7\n\ - orrs r1, r0\n\ - strb r1, [r5]\n\ - b _080FA336\n\ -_080FA310:\n\ - mov r2, r9\n\ - ands r4, r2\n\ - mov r0, r8\n\ - ands r0, r7\n\ - orrs r0, r4\n\ - strb r0, [r5]\n\ - lsls r0, 25\n\ - ldrh r1, [r5]\n\ - lsls r1, 18\n\ - lsrs r0, 25\n\ - lsrs r1, 25\n\ - cmp r0, r1\n\ - bne _080FA336\n\ - ldrb r0, [r5, 0x1]\n\ - movs r4, 0x41\n\ - negs r4, r4\n\ - adds r1, r4, 0\n\ - ands r0, r1\n\ -_080FA334:\n\ - strb r0, [r5, 0x1]\n\ -_080FA336:\n\ - mov r0, r10\n\ - adds r0, 0x1\n\ - lsls r0, 16\n\ - lsrs r0, 16\n\ - mov r10, r0\n\ - cmp r0, 0x4\n\ - bls _080FA24A\n\ - ldr r0, _080FA360 @ =gSaveBlock1 + 0x2DD4\n\ - movs r1, 0x5\n\ - movs r2, 0\n\ - bl sub_80FA46C\n\ -_080FA34E:\n\ - add sp, 0x8\n\ - pop {r3-r5}\n\ - mov r8, r3\n\ - mov r9, r4\n\ - mov r10, r5\n\ - pop {r4-r7}\n\ - pop {r0}\n\ - bx r0\n\ - .align 2, 0\n\ -_080FA360: .4byte gSaveBlock1 + 0x2DD4\n\ - .syntax divided\n"); -} -#endif - bool8 sub_80FA364(u16 *a) { struct EasyChatPair s = {0}; diff --git a/src/diploma.c b/src/diploma.c index 112647956..c32b72a70 100644 --- a/src/diploma.c +++ b/src/diploma.c @@ -87,7 +87,7 @@ void sub_8145D88(void) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG3CNT = 0x4603; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(6) | BGCNT_16COLOR | BGCNT_TXT512x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; CreateTask(Task_DiplomaFadeIn, 0); diff --git a/src/field_region_map.c b/src/field_region_map.c index db12eb6a5..ec630ad00 100644 --- a/src/field_region_map.c +++ b/src/field_region_map.c @@ -64,7 +64,7 @@ void CB2_FieldInitRegionMap(void) SetUpWindowConfig(&gWindowConfig_81E709C); InitMenuWindow(&gWindowConfig_81E709C); MenuZeroFillScreen(); - REG_BG0CNT = 7936; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; MenuDrawTextWindow(21, 0, 29, 3); sub_8072BD8(gOtherText_Hoenn, 0x16, 1, 0x38); MenuDrawTextWindow(16, 16, 29, 19); @@ -94,7 +94,7 @@ void sub_813EFDC(void) switch (unk_2000000.unk888) { case 0: - REG_DISPCNT = 5441; + REG_DISPCNT = DISPCNT_MODE_1 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_ON; unk_2000000.unk888++; break; case 1: diff --git a/src/link.c b/src/link.c index 336616f1a..224c0ae1c 100644 --- a/src/link.c +++ b/src/link.c @@ -207,13 +207,13 @@ static void InitLinkTestBG(u8 paletteNum, u8 bgNum, u8 screenBaseBlock, u8 charB switch (bgNum) { case 1: - REG_BG1CNT = 1 | (screenBaseBlock << 8) | (charBaseBlock << 2); + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock); break; case 2: - REG_BG2CNT = 1 | (screenBaseBlock << 8) | (charBaseBlock << 2); + REG_BG2CNT = BGCNT_PRIORITY(1) | BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock); break; case 3: - REG_BG3CNT = 1 | (screenBaseBlock << 8) | (charBaseBlock << 2); + REG_BG3CNT = BGCNT_PRIORITY(1) | BGCNT_SCREENBASE(screenBaseBlock) | BGCNT_CHARBASE(charBaseBlock); break; } } @@ -255,7 +255,7 @@ void LinkTestScreen(void) } InitLinkTestBG(0, 2, 4, 0); - REG_DISPCNT = DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_1D_MAP; CreateTask(Task_DestroySelf, 0); RunTasks(); AnimateSprites(); diff --git a/src/mail.c b/src/mail.c index 9964f2a79..807864332 100644 --- a/src/mail.c +++ b/src/mail.c @@ -273,11 +273,11 @@ static u8 sub_80F8A28(void) RETURN_SKIP_STATE; case 18: - REG_BG0CNT = 0x9F08; - REG_BG1CNT = 0x0801; - REG_BG2CNT = 0x0902; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x512; + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(8) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(9) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_BLDCNT = 0; - REG_DISPCNT = DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_ON; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_OBJ_ON; BeginNormalPaletteFade(-1, 0, 16, 0, 0); gPaletteFade.bufferTransferDisabled = 0; ewram0.varF0 = sub_80F8F58; diff --git a/src/main_menu.c b/src/main_menu.c index 294d33620..50fefc471 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -250,7 +250,8 @@ u32 InitMainMenu(u8 a1) SetVBlankCallback(VBlankCB_MainMenu); SetMainCallback2(CB2_MainMenu); - REG_DISPCNT = DISPCNT_OBJ_1D_MAP + REG_DISPCNT = DISPCNT_MODE_0 + | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_OBJ_ON | DISPCNT_WIN0_ON; @@ -747,8 +748,8 @@ static void Task_NewGameSpeech1(u8 taskId) FreeAllSpritePalettes(); AddBirchSpeechObjects(taskId); BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); - REG_BG1CNT = 0x00000703; - REG_DISPCNT = DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP; + REG_BG1CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP; gTasks[taskId].data[TD_BGHOFS] = 0; gTasks[taskId].func = Task_NewGameSpeech2; gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = 0xFF; @@ -1391,7 +1392,7 @@ void CB_ContinueNewGameSpeechPart2() SetVBlankCallback(VBlankCB_MainMenu); SetMainCallback2(CB2_MainMenu); - REG_BG1CNT = 1795; + REG_BG1CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON; } diff --git a/src/matsuda_debug_menu.c b/src/matsuda_debug_menu.c index 39c338658..d2ca754bb 100644 --- a/src/matsuda_debug_menu.c +++ b/src/matsuda_debug_menu.c @@ -64,7 +64,6 @@ extern u8* gMatsudaDebugMenuTextList3[]; extern u8 gMatsudaDebugMenuContestTopLeft[][2]; extern bool8 gReceivedRemoteLinkPlayers; -extern u16 gBlockRecvBuffer[MAX_LINK_PLAYERS][BLOCK_BUFFER_SIZE / 2]; extern struct MenuAction gMatsudaDebugMenuActions[]; @@ -290,7 +289,7 @@ static void sub_80A9F10(u8 taskId) static void sub_80A9F50(void) { - REG_DISPCNT = DISPCNT_OBJ_1D_MAP; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP; REG_DISPCNT |= DISPCNT_OBJ_ON | DISPCNT_BG0_ON; SetUpWindowConfig(&gWindowConfig_81E6C3C); InitWindowFromConfig(&gMenuWindow, &gWindowConfig_81E6C3C); @@ -1073,7 +1072,7 @@ void unref_sub_80AB084(u8 *text) REG_WIN0V = 0; REG_WIN1H = 0; REG_WIN1V = 0; - REG_DISPCNT = 0x1F40; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON; savedIme = REG_IME; REG_IME = 0; diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c index 693b28948..97deb348c 100644 --- a/src/mystery_event_menu.c +++ b/src/mystery_event_menu.c @@ -54,7 +54,7 @@ void CB2_InitMysteryEventMenu(void) SetUpWindowConfig(&gWindowConfig_81E6CE4); InitMenuWindow(&gWindowConfig_81E6CE4); MenuZeroFillScreen(); - REG_DISPCNT = 320; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON; REG_BLDCNT = 0; CreateTask(Task_DestroySelf, 0); StopMapMusic(); diff --git a/src/naming_screen.c b/src/naming_screen.c index f00a9bd3e..b14c690e2 100644 --- a/src/naming_screen.c +++ b/src/naming_screen.c @@ -298,10 +298,10 @@ static void NamingScreen_SetUpVideoRegs(void) REG_BG2VOFS = 0; REG_BG3HOFS = 0; REG_BG3VOFS = 0; - REG_BG0CNT = 0x1F00; - REG_BG1CNT = 0x1C01; - REG_BG2CNT = 0x1D0A; - REG_BG3CNT = 0x1E03; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(28) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(29) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(30) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_BLDCNT = 0x640; REG_BLDALPHA = 0x80C; } diff --git a/src/new_game.c b/src/new_game.c index 6d2722c44..12e04a4ef 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -145,7 +145,7 @@ void NewGameInitData(void) ClearDecorationInventories(); InitEasyChatPhrases(); SetMauvilleOldMan(); - InitDewfordTrends(); + InitDewfordTrend(); ResetFanClub(); ResetLotteryCorner(); WarpToTruck(); diff --git a/src/pokedex.c b/src/pokedex.c index d31d649e0..5ea1f9938 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -789,10 +789,10 @@ bool8 sub_808D344(u8 a) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG3CNT = 0xF03; - REG_BG1CNT = 0xD01; - REG_BG0CNT = 0xC00; - REG_DISPCNT = 0x9F40; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(15) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG1CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(13) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(12) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON | DISPCNT_OBJWIN_ON; gMain.state++; break; case 6: @@ -2296,8 +2296,8 @@ void Task_InitPageScreenMultistep(u8 taskId) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG3CNT = 0xF03; - REG_BG1CNT = 0xD00; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(15) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG1CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(13) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; gMain.state++; break; @@ -2422,7 +2422,7 @@ void Task_InitAreaScreenMultistep(u8 taskId) sub_8090540(0xD); sub_8090644(1, 0xD); sub_808D640(); - REG_BG1CNT = 0xD00; + REG_BG1CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(13) | BGCNT_16COLOR | BGCNT_TXT256x256; gMain.state++; break; case 2: @@ -2544,10 +2544,10 @@ void Task_InitCryScreenMultistep(u8 taskId) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG2CNT = 0xE02; - REG_BG0CNT = 0x1F07; - REG_BG1CNT = 0xD00; - REG_DISPCNT = 0x1F07 + 0x39; + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(14) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG0CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG1CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(13) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG_ALL_ON | DISPCNT_OBJ_ON; gMain.state++; break; case 10: @@ -2715,8 +2715,8 @@ void Task_InitSizeScreenMultistep(u8 taskId) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG2CNT = 0xE03; - REG_DISPCNT = 0x1E40; + REG_BG2CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(14) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG1_ON | DISPCNT_BG2_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; gMain.state++; break; case 9: @@ -3156,8 +3156,8 @@ void sub_8090750(u8 taskId) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG3CNT = 0xF07; - REG_DISPCNT = 0x1C40; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(1) | BGCNT_SCREENBASE(15) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG2_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; gTasks[taskId].data[0]++; break; case 6: diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c new file mode 100644 index 000000000..679ec0bc4 --- /dev/null +++ b/src/pokemon_storage_system.c @@ -0,0 +1,93 @@ +#include "global.h" +#include "menu.h" +#include "string_util.h" + +struct StorageAction { + u8 *text; + u8 format; +}; + +extern const struct StorageAction gUnknown_083B6DF4[]; + +extern const u8 unk_2000000[]; + +#define gUnk2002694 (u8 *)(&unk_2000000[0x2694]) +#define gUnk20026A6 (u8 *)(&unk_2000000[0x26a6]) +#define gUnk20011fa (u8 *)(&unk_2000000[0x11fa]) +#define gUnk20026e4 (u8 *)(&unk_2000000[0x26e4]) + +void sub_8098898(u8 index) { + u8 *ptr; + + MenuDrawTextWindow(10, 16, 29, 19); + + switch (gUnknown_083B6DF4[index].format) + { + + case 2: + ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); + ptr = StringCopy(ptr, gUnk20011fa); + break; + + case 5: + ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); + ptr = StringCopy(ptr, gUnk20026e4); + break; + + case 1: + // {var} + " is selected." + ptr = StringCopy(gUnk2002694, gUnk20011fa); + ptr = StringCopy(ptr, gUnknown_083B6DF4[index].text); + break; + + case 4: + // TODO: fix for German + // {var} + " was released." + ptr = StringCopy(gUnk2002694, gUnk20026e4); + ptr = StringCopy(ptr, gUnknown_083B6DF4[index].text); + break; + + case 3: + { + u8 *stringLength; + u8 *text; + + text = gUnknown_083B6DF4[index].text; + stringLength = &text[StringLength(text)] + 1; + + ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); + ptr = StringCopy(ptr, gUnk20011fa); + ptr = StringCopy(ptr, stringLength); + } + break; + + case 6: + // "Bye-bye, ".substr(0, -1) + {var} + "Bye-bye, !".substr(-1, 1) + { + u8 *stringLength; + u8 *text; + + text = gUnknown_083B6DF4[index].text; + stringLength = &text[StringLength(text)] - 1; + + ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); + ptr = StringCopy(ptr - 1, gUnk20026e4); + ptr = StringCopy(ptr, stringLength); + } + break; + + case 0: + default: + ptr = StringCopy(gUnk2002694, gUnknown_083B6DF4[index].text); + break; + } + + while (ptr < gUnk20026A6) + { + ptr[0] = CHAR_SPACE; + ptr++; + } + + ptr[0] = EOS; + MenuPrint(gUnk2002694, 11, 17); +} diff --git a/src/pokenav.c b/src/pokenav.c new file mode 100644 index 000000000..60e7c73e1 --- /dev/null +++ b/src/pokenav.c @@ -0,0 +1,45 @@ +#include "global.h" +#include "battle.h" +#include "string_util.h" + +struct UnkPokenavStruct_Sub { + /*0x0*/ u16 unk0; + /*0x2*/ u8 filler2[6]; +}; + + +struct UnkPokenavStruct { + /*0x0000*/ u8 filler0000[0xCEE8]; + /*0xCEE8*/ struct UnkPokenavStruct_Sub unkCEE8[78]; + /*0xD158*/ u16 unkD158; + +}; + +extern struct UnkPokenavStruct *gUnknown_083DFEC4; + +extern const struct Trainer gTrainers[]; +extern const u8 gTrainerClassNames[][13]; + +void sub_80F700C(u8 *arg0, u16 arg1) { + struct Trainer *trainer; + u8 *ptr; + + trainer = (struct Trainer *) &gTrainers[gUnknown_083DFEC4->unkCEE8[arg1].unk0]; + + ptr = arg0; + if (arg1 < gUnknown_083DFEC4->unkD158) + { + ptr = StringCopy(ptr, gTrainerClassNames[trainer->trainerClass]); + + ptr[0] = 0xFC; + ptr[1] = 0x13; + ptr[2] = 0x4B; + ptr += 3; + ptr = StringCopy(ptr, trainer->trainerName); + } + + ptr[0] = 0xFC; + ptr[1] = 0x13; + ptr[2] = 0x80; + ptr[3] = 0xFF; +} diff --git a/src/record_mixing.c b/src/record_mixing.c index c08128637..76fe13059 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -31,8 +31,6 @@ extern u8 gUnknown_0300071C[]; extern u8 gOtherText_MixingComplete[]; extern u8 gOtherText_MixingRecordsWithFriend[]; extern bool8 gReceivedRemoteLinkPlayers; -extern u8 gBlockSendBuffer[BLOCK_BUFFER_SIZE]; -extern u16 gBlockRecvBuffer[MAX_LINK_PLAYERS][BLOCK_BUFFER_SIZE / 2]; #define BUFFER_CHUNK_SIZE 200 diff --git a/src/rom3.c b/src/rom3.c index b0ef7f088..0169128cb 100644 --- a/src/rom3.c +++ b/src/rom3.c @@ -13,7 +13,6 @@ extern u8 unk_2000000[]; #define EWRAM_15000 ((u8 *)(unk_2000000 + 0x15000)) extern u16 gBattleTypeFlags; -extern u16 gBlockRecvBuffer[MAX_LINK_PLAYERS][BLOCK_BUFFER_SIZE / 2]; extern const u32 gBitTable[]; extern u16 gBattleWeather; extern const struct BattleMove gBattleMoves[]; @@ -124,7 +123,7 @@ void sub_800B950(void) else sub_800B9A8(); sub_800BD54(); - if (!(gBattleTypeFlags & BATTLE_TYPE_40)) + if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { for (i = 0; i < gUnknown_02024A68; i++) sub_8094978(i, 0); @@ -188,7 +187,7 @@ void sub_800BA78(void) } return; } - if ((gBattleTypeFlags & (BATTLE_TYPE_40 | BATTLE_TYPE_DOUBLE)) == BATTLE_TYPE_DOUBLE) + if ((gBattleTypeFlags & (BATTLE_TYPE_MULTI | BATTLE_TYPE_DOUBLE)) == BATTLE_TYPE_DOUBLE) { if (gBattleTypeFlags & BATTLE_TYPE_WILD) { @@ -299,7 +298,7 @@ void sub_800BD54(void) int i; int j; - if (!(gBattleTypeFlags & BATTLE_TYPE_40)) + if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) { for (i = 0; i < gUnknown_02024A68; i++) { diff --git a/src/rom_800D42C.c b/src/rom_800D42C.c index 93fbce556..6f153c340 100644 --- a/src/rom_800D42C.c +++ b/src/rom_800D42C.c @@ -34,7 +34,7 @@ extern u8 BattleText_Tie[]; #define PRINT_MESSAGE_LEFT(text, tileDataStartOffset) PRINT_MESSAGE(text, tileDataStartOffset, LEFT_MESSAGE_X) #define PRINT_MESSAGE_RIGHT(text, tileDataStartOffset) PRINT_MESSAGE(text, tileDataStartOffset, RIGHT_MESSAGE_X) -void sub_800DC24(void) +void PrintLinkBattleWinLossTie(void) { if (gUnknown_02024D26 == 3) @@ -43,7 +43,7 @@ void sub_800DC24(void) return; } - if (gBattleTypeFlags & BATTLE_TYPE_40) + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { // Double battle? diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 102909779..d46abc74d 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -150,9 +150,9 @@ static void CB2_SaveFailedScreen(void) REG_IME = ime; REG_DISPSTAT |= DISPSTAT_VBLANK_INTR; SetVBlankCallback(VBlankCB); - REG_BG3CNT = 0x703; - REG_BG2CNT = 0x602; - REG_BG0CNT = 0x1f08; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(6) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_OBJ_ON | DISPCNT_BG3_ON | DISPCNT_BG2_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP | DISPCNT_MODE_0; gMain.state++; break; diff --git a/src/secret_base.c b/src/secret_base.c new file mode 100644 index 000000000..572dfaa1d --- /dev/null +++ b/src/secret_base.c @@ -0,0 +1,18 @@ +#include "global.h" +#include "string_util.h" +#include "strings.h" +#include "text.h" + +u8 sub_80BB8A8(void *); + +u8 *sub_80BC190(u8 *dest, u8 arg1) { + u8 local1; + u8 *str; + + local1 = sub_80BB8A8(gSaveBlock1.secretBases[arg1].sbr_field_2); + + str = StringCopyN(dest, gSaveBlock1.secretBases[arg1].sbr_field_2, local1); + str[0] = EOS; + + return StringAppend(dest, gOtherText_PlayersBase); +} diff --git a/src/slot_machine.c b/src/slot_machine.c new file mode 100644 index 000000000..c087bf6b4 --- /dev/null +++ b/src/slot_machine.c @@ -0,0 +1,154 @@ +#include "global.h" +#include "decompress.h" +#include "palette.h" +#include "task.h" + +struct UnkStruct2000000 { + /*0x00*/ u8 filler00[61]; + /*0x3D*/ u8 unk3D; +}; + +struct UnkStruct1 { + /*0x00*/ u8 unk00; + /*0x01*/ u8 unk01; + /*0x02*/ s16 unk02; +}; + +extern struct UnkStruct2000000 unk_2000000; + +extern struct UnkStruct1 *gUnknown_083ED048[]; +extern const u16 gPalette_83EDE24[]; + +extern const u8 gSlotMachine_Gfx[]; +#if ENGLISH +#define SLOTMACHINE_GFX_TILES 233 +#elif GERMAN +#define SLOTMACHINE_GFX_TILES 236 +#endif + +extern const u16 gUnknown_08E95A18[]; + +extern u16 gUnknown_08E95AB8[]; +extern u16 gUnknown_08E95FB8[]; + + +void sub_8104DA4(void); + +u8 sub_8105BB4(u8, u8, s16); + +static void LoadSlotMachineWheelOverlay(void); + +void sub_8104CAC(u8 arg0) { + u8 i; + struct Task *task; + + sub_8104DA4(); + + task = &gTasks[unk_2000000.unk3D]; + task->data[1] = arg0; + + i = 0; + while (gUnknown_083ED048[arg0][i].unk00 != 0xFF) + { + u8 spriteId; + spriteId = sub_8105BB4( + gUnknown_083ED048[arg0][i].unk00, + gUnknown_083ED048[arg0][i].unk01, + gUnknown_083ED048[arg0][i].unk02 + ); + task->data[4 + i] = spriteId; + +#ifdef GERMAN + if (arg0 == 5 && i <= 2) + { + gSprites[spriteId].invisible = TRUE; + } +#endif + + i += 1; + } +} + +asm(".section .text_b"); + +void sub_8106448(void) { + u32 offsetRead, offsetWrite; + u32 size; + + sub_800D238(gSlotMachine_Gfx, (void *) 0x02010000); + + offsetRead = 0x02010000; + offsetWrite = BG_VRAM; + size = SLOTMACHINE_GFX_TILES * 32; + while (TRUE) + { + DmaCopy16(3, offsetRead, (void *) (offsetWrite), 0x1000); + offsetRead += 0x1000; + offsetWrite += 0x1000; + size -= 0x1000; + if (size <= 0x1000) + { + DmaCopy16(3, offsetRead, (void *) (offsetWrite), size); + break; + } + } + + LoadPalette(gUnknown_08E95A18, 0, 160); + LoadPalette(gPalette_83EDE24, 208, 32); +} + +void sub_81064B8(void) { + CpuCopy16(gUnknown_08E95AB8, (void *) BG_SCREEN_ADDR(29), 20 * 32 * 2); + LoadSlotMachineWheelOverlay(); +} + +static void LoadSlotMachineWheelOverlay(void) { + s16 x, y, dx; + u16 *screen; + + screen = (u16 *) BG_SCREEN_ADDR(30); + + for (x = 4; x < 18; x += 5) + { + for (dx = 0; dx < 4; dx++) + { + screen[5 * 32 + dx + x] = 0x2051; + screen[13 * 32 + dx + x] = 0x2851; + screen[6 * 32 + dx + x] = 0x2061; + screen[12 * 32 + dx + x] = 0x2861; + } + + screen[6 * 32 + x] = 0x20BE; + screen[12 * 32 + x] = 0x28BE; + + for (y = 7; y <= 11; y++) + { + screen[y * 32 + x] = 0x20BF; + } + } +} + +void sub_81065A8(s16 arg0, u16 arg1, u16 arg2, u16 arg3, u16 arg4) { + u16 *vram = (u16 *) BG_SCREEN_ADDR(29); + + vram[15 * 32 + arg0] = arg1; + vram[15 * 32 + 1 + arg0] = arg2; + vram[16 * 32 + arg0] = arg3; + vram[16 * 32 + 1 + arg0] = arg4; +} + +void sub_81065DC(void) { + s16 y, x; + u16 *screen; + + CpuCopy16(gUnknown_08E95FB8, (void *) BG_SCREEN_ADDR(29), 20 * 32 * 2); + + screen = (u16 *) BG_SCREEN_ADDR(30); + for (y = 0; y < 20; y++) + { + for (x = 0; x < 30; x++) + { + screen[x + y * 32] = 0; + } + } +} diff --git a/src/sound.c b/src/sound.c index 3256c4d67..ed69ca01d 100644 --- a/src/sound.c +++ b/src/sound.c @@ -339,7 +339,7 @@ void PlayCry4(u16 species, s8 pan, u8 mode) } else { - if (!(gBattleTypeFlags & BATTLE_TYPE_40)) + if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI)) m4aMPlayVolumeControl(&gMPlay_BGM, 0xFFFF, 85); PlayCryInternal(species, pan, 125, 10, mode); } diff --git a/src/start_menu.c b/src/start_menu.c index 4a3bcbbd3..37d361c0b 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -782,7 +782,7 @@ static bool32 sub_80719FC(u8 *step) case 2: SetUpWindowConfig(&gWindowConfig_81E6CE4); InitMenuWindow(&gWindowConfig_81E6CE4); - REG_DISPCNT = 0x100; + REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_BG0_ON; break; case 3: { diff --git a/src/starter_choose.c b/src/starter_choose.c index 63d153ebd..6ef410d21 100644 --- a/src/starter_choose.c +++ b/src/starter_choose.c @@ -325,9 +325,9 @@ void CB2_ChooseStarter(void) REG_BLDCNT = 0xFE; REG_BLDALPHA = 0; REG_BLDY = 0x7; - REG_BG3CNT = 0x703; - REG_BG2CNT = 0x602; - REG_BG0CNT = 0x1F08; + REG_BG3CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG2CNT = BGCNT_PRIORITY(2) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(6) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG2_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON | DISPCNT_WIN0_ON; taskId = CreateTask(Task_StarterChoose1, 0); @@ -256,7 +256,7 @@ void EndMassOutbreak(void) gSaveBlock1.outbreakUnk5 = 0; } -void sub_80BE8C4(u16 arg0) +void UpdateTVShowsPerDay(u16 arg0) { sub_80BE8EC(arg0); UpdateMassOutbreakTimeLeft(arg0); diff --git a/src/wallclock.c b/src/wallclock.c index 2f4d694a6..0f3665c65 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -256,8 +256,8 @@ static void WallClockInit(void) REG_BLDCNT = 0; REG_BLDALPHA = 0; REG_BLDY = 0; - REG_BG3CNT = 0x701; - REG_BG0CNT = 0x1F08; + REG_BG3CNT = BGCNT_PRIORITY(1) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; + REG_BG0CNT = BGCNT_PRIORITY(0) | BGCNT_CHARBASE(2) | BGCNT_SCREENBASE(31) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON | DISPCNT_OBJ_ON; } |