summaryrefslogtreecommitdiff
path: root/src/pokedex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pokedex.c')
-rw-r--r--src/pokedex.c268
1 files changed, 165 insertions, 103 deletions
diff --git a/src/pokedex.c b/src/pokedex.c
index d375a0afc..54f256509 100644
--- a/src/pokedex.c
+++ b/src/pokedex.c
@@ -172,16 +172,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];
@@ -1673,7 +1673,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);
@@ -1682,7 +1682,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;
@@ -1690,7 +1690,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);
@@ -1704,7 +1704,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;
@@ -1737,7 +1737,7 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId)
}
else
{
- if (JOY_NEW(A_BUTTON))
+ if (gMain.newKeys & A_BUTTON)
{
switch (sPokedexView->menuCursorPos)
{
@@ -1768,18 +1768,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);
@@ -1873,7 +1873,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;
@@ -1885,7 +1885,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;
@@ -1893,7 +1893,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();
@@ -1902,7 +1902,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;
@@ -1934,7 +1934,7 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId)
}
else
{
- if (JOY_NEW(A_BUTTON))
+ if (gMain.newKeys & A_BUTTON)
{
switch (sPokedexView->menuCursorPos)
{
@@ -1970,18 +1970,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);
@@ -2060,10 +2060,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);
@@ -2590,7 +2590,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);
@@ -2598,7 +2598,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);
@@ -2606,7 +2606,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;
@@ -2617,7 +2617,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++)
@@ -2666,7 +2666,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)
@@ -2689,7 +2689,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)
@@ -3186,10 +3186,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();
@@ -3356,14 +3356,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)
{
@@ -3400,8 +3400,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--;
@@ -3409,8 +3409,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++;
@@ -3630,7 +3630,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));
@@ -3638,7 +3638,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);
@@ -3647,8 +3647,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);
@@ -3657,8 +3657,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)
{
@@ -3810,15 +3810,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;
@@ -3951,8 +3951,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;
@@ -4010,7 +4010,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,18 +4167,21 @@ static void PrintMonHeight(u16 height, u8 left, u8 top)
static void PrintMonWeight(u16 weight, u8 left, u8 top)
{
+#ifndef NONMATCHING
+ asm("":::"r9");
+{
+#endif
u8 buffer[16];
- u8 i;
bool8 output;
+ u8 i = 0;
u32 lbs = (weight * 100000) / 4536;
if (lbs % 10u >= 5)
lbs += 10;
-
- i = 0;
output = FALSE;
- if ((buffer[i] = (lbs / 100000) + CHAR_0) == CHAR_0 && !output)
+ buffer[i] = (lbs / 100000) + CHAR_0;
+ if (buffer[i] == CHAR_0)
{
buffer[i++] = 0x77;
}
@@ -4189,7 +4192,8 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top)
}
lbs %= 100000;
- if ((buffer[i] = (lbs / 10000) + CHAR_0) == CHAR_0 && !output)
+ buffer[i] = (lbs / 10000) + CHAR_0;
+ if (buffer[i] == CHAR_0 && !output)
{
buffer[i++] = 0x77;
}
@@ -4200,13 +4204,13 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top)
}
lbs %= 10000;
- if ((buffer[i] = (lbs / 1000) + CHAR_0) == CHAR_0 && !output)
+ buffer[i] = (lbs / 1000) + CHAR_0;
+ if (buffer[i] == CHAR_0 && !output)
{
buffer[i++] = 0x77;
}
else
{
- output = TRUE;
i++;
}
@@ -4222,6 +4226,9 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top)
buffer[i++] = CHAR_PERIOD;
buffer[i++] = EOS;
PrintInfoScreenText(buffer, left, top);
+#ifndef NONMATCHING
+}
+#endif
}
const u8 *GetPokedexCategoryName(u16 dexNum) // unused
@@ -4229,19 +4236,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;
@@ -4819,10 +4820,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);
@@ -4906,13 +4907,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)
{
@@ -4933,7 +4934,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--;
@@ -4941,7 +4942,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++;
@@ -4980,14 +4981,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)
{
@@ -5022,7 +5023,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];
@@ -5030,7 +5031,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];
@@ -5038,7 +5039,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];
@@ -5046,7 +5047,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];
@@ -5090,7 +5091,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)
{
@@ -5116,9 +5117,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);
@@ -5143,7 +5144,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();
@@ -5153,7 +5154,7 @@ static void Task_HandleSearchParameterInput(u8 taskId)
CopyBgTilemapBufferToVram(3);
return;
}
- if (JOY_NEW(B_BUTTON))
+ if (gMain.newKeys & B_BUTTON)
{
PlaySE(SE_BALL);
ClearSearchParameterBoxText();
@@ -5166,7 +5167,7 @@ static void Task_HandleSearchParameterInput(u8 taskId)
return;
}
moved = FALSE;
- if (JOY_REPEAT(DPAD_UP))
+ if (gMain.newAndRepeatedKeys & DPAD_UP)
{
if (*cursorPos != 0)
{
@@ -5192,7 +5193,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)
{
@@ -5235,24 +5236,83 @@ static void Task_ExitSearchWaitForFade(u8 taskId)
}
}
+#ifdef NONMATCHING
+// This doesn't match because gcc flips the naming of the r7 and r6
+// registers. It also does one of the additions backwards.
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* ptr = GetBgTilemapBuffer(3);
+ u16* temp;
for (i = 0; i < width; i++)
{
- temp = *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2);
- temp &= 0x0fff;
- temp |= (flags << 12);
- *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2) = temp;
+ // This addition is supposed to be done in this order; however,
+ // gcc will always do it in ptr + (y * 32) order.
+ temp = (y * 32) + ptr;
+ temp[x + i] %= 0x1000;
+ temp[x + i] |= flags * 0x1000;
- temp = *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2);
- temp &= 0x0fff;
- temp |= (flags << 12);
- *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2) = temp;
+ temp[x + i + 32] %= 0x1000;
+ temp[x + i + 32] |= flags * 0x1000;
}
}
+#else
+NAKED
+void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width)
+{
+ asm_unified(
+ "push {r4-r7,lr}\n\
+ mov r7, r8\n\
+ push {r7}\n\
+ adds r4, r3, 0\n\
+ lsls r0, 24\n\
+ lsrs r6, r0, 24\n\
+ lsls r1, 24\n\
+ lsrs r1, 24\n\
+ mov r8, r1\n\
+ lsls r2, 24\n\
+ lsrs r5, r2, 24\n\
+ lsls r4, 24\n\
+ lsrs r4, 24\n\
+ movs r0, 0x3\n\
+ bl GetBgTilemapBuffer\n\
+ adds r2, r0, 0\n\
+ movs r3, 0\n\
+ cmp r3, r4\n\
+ bcs _080C1DEC\n\
+ lsls r0, r5, 6\n\
+ adds r7, r0, r2\n\
+ ldr r5, =0x00000fff\n\
+ lsls r2, r6, 12\n\
+_080C1DC8:\n\
+ mov r0, r8\n\
+ adds r1, r0, r3\n\
+ lsls r1, 1\n\
+ adds r1, r7\n\
+ ldrh r0, [r1]\n\
+ ands r0, r5\n\
+ orrs r0, r2\n\
+ strh r0, [r1]\n\
+ adds r1, 0x40\n\
+ ldrh r0, [r1]\n\
+ ands r0, r5\n\
+ orrs r0, r2\n\
+ strh r0, [r1]\n\
+ adds r0, r3, 0x1\n\
+ lsls r0, 16\n\
+ lsrs r3, r0, 16\n\
+ cmp r3, r4\n\
+ bcc _080C1DC8\n\
+_080C1DEC:\n\
+ pop {r3}\n\
+ mov r8, r3\n\
+ pop {r4-r7}\n\
+ pop {r0}\n\
+ bx r0\n\
+ .pool");
+}
+#endif
#define SEARCH_BG_SEARCH SEARCH_TOPBAR_SEARCH
#define SEARCH_BG_SHIFT SEARCH_TOPBAR_SHIFT
@@ -5452,8 +5512,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();
@@ -5542,7 +5602,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)
@@ -5553,7 +5614,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]