diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2020-12-31 00:40:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-31 00:40:45 -0500 |
commit | ec85c01e7c6d15060eddcc653db33a4b317646d2 (patch) | |
tree | 4266c43bcdc1c80c52def44e1470182d3f1c665c /src/pokedex.c | |
parent | 093610b46e99b517a416ccd5a572054dff09801b (diff) | |
parent | 0c74e2097ffbe8395d6f3659c2a49fc829d69b99 (diff) |
Merge branch 'master' into doc-factscreen
Diffstat (limited to 'src/pokedex.c')
-rw-r--r-- | src/pokedex.c | 250 |
1 files changed, 95 insertions, 155 deletions
diff --git a/src/pokedex.c b/src/pokedex.c index a86c22153..691abd649 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -28,7 +28,6 @@ #include "window.h" #include "constants/rgb.h" #include "constants/songs.h" -#include "constants/species.h" enum { @@ -1673,7 +1672,7 @@ static void Task_HandlePokedexInput(u8 taskId) } else { - if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { UpdateSelectedMonSpriteId(); BeginNormalPaletteFade(~(1 << (gSprites[sPokedexView->selectedMonSpriteId].oam.paletteNum + 16)), 0, 0, 0x10, RGB_BLACK); @@ -1682,7 +1681,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (gMain.newKeys & START_BUTTON) + else if (JOY_NEW(START_BUTTON)) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1690,7 +1689,7 @@ static void Task_HandlePokedexInput(u8 taskId) gTasks[taskId].func = Task_HandlePokedexStartMenuInput; PlaySE(SE_SELECT); } - else if (gMain.newKeys & SELECT_BUTTON) + else if (JOY_NEW(SELECT_BUTTON)) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); @@ -1704,7 +1703,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ClosePokedex; @@ -1737,7 +1736,7 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } else { - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { switch (sPokedexView->menuCursorPos) { @@ -1768,18 +1767,18 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (gMain.newKeys & (START_BUTTON | B_BUTTON)) + if (JOY_NEW(START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandlePokedexInput; PlaySE(SE_SELECT); } - else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos != 0) + else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos != 0) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 3) + else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 3) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -1873,7 +1872,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) } else { - if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { u32 a; @@ -1885,7 +1884,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (gMain.newKeys & START_BUTTON) + else if (JOY_NEW(START_BUTTON)) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1893,7 +1892,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) gTasks[taskId].func = Task_HandleSearchResultsStartMenuInput; PlaySE(SE_SELECT); } - else if (gMain.newKeys & SELECT_BUTTON) + else if (JOY_NEW(SELECT_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].tTaskId = LoadSearchMenu(); @@ -1902,7 +1901,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (gMain.newKeys & B_BUTTON) + else if (JOY_NEW(B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ReturnToPokedexFromSearchResults; @@ -1934,7 +1933,7 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } else { - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { switch (sPokedexView->menuCursorPos) { @@ -1970,18 +1969,18 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (gMain.newKeys & (START_BUTTON | B_BUTTON)) + if (JOY_NEW(START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandleSearchResultsInput; PlaySE(SE_SELECT); } - else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos) + else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 4) + else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 4) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -2060,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(0x800)); - SetBgTilemapBuffer(2, AllocZeroed(0x800)); - SetBgTilemapBuffer(1, AllocZeroed(0x800)); - SetBgTilemapBuffer(0, AllocZeroed(0x800)); + SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(1, gPokedexList_Tilemap, 0, 0); CopyToBgTilemapBuffer(3, gPokedexListUnderlay_Tilemap, 0, 0); @@ -2590,7 +2589,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) u16 startingPos; u8 scrollDir = 0; - if ((gMain.heldKeys & DPAD_UP) && (selectedMon > 0)) + if ((JOY_HELD(DPAD_UP)) && (selectedMon > 0)) { scrollDir = 1; selectedMon = GetNextPosition(1, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2598,7 +2597,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(1, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if ((gMain.heldKeys & DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((JOY_HELD(DPAD_DOWN)) && (selectedMon < sPokedexView->pokemonListCount - 1)) { scrollDir = 2; selectedMon = GetNextPosition(0, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2606,7 +2605,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(2, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if ((gMain.newKeys & DPAD_LEFT) && (selectedMon > 0)) + else if ((JOY_NEW(DPAD_LEFT)) && (selectedMon > 0)) { startingPos = selectedMon; @@ -2617,7 +2616,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonSpritesAtPos(selectedMon, 0xE); PlaySE(SE_DEX_PAGE); } - else if ((gMain.newKeys & DPAD_RIGHT) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((JOY_NEW(DPAD_RIGHT)) && (selectedMon < sPokedexView->pokemonListCount - 1)) { startingPos = selectedMon; for (i = 0; i < 7; i++) @@ -2666,7 +2665,7 @@ static bool8 TryDoInfoScreenScroll(void) u16 nextPokemon; u16 selectedPokemon = sPokedexView->selectedPokemon; - if ((gMain.newKeys & DPAD_UP) && selectedPokemon) + if ((JOY_NEW(DPAD_UP)) && selectedPokemon) { nextPokemon = selectedPokemon; while (nextPokemon != 0) @@ -2689,7 +2688,7 @@ static bool8 TryDoInfoScreenScroll(void) return TRUE; } } - else if ((gMain.newKeys & DPAD_DOWN) && selectedPokemon < sPokedexView->pokemonListCount - 1) + else if ((JOY_NEW(DPAD_DOWN)) && selectedPokemon < sPokedexView->pokemonListCount - 1) { nextPokemon = selectedPokemon; while (nextPokemon < sPokedexView->pokemonListCount - 1) @@ -3038,7 +3037,15 @@ static void SpriteCB_PokedexListMonSprite(struct Sprite *sprite) u32 var; sprite->pos2.y = gSineTable[(u8)sprite->data[5]] * 76 / 256; + // UB: possible division by zero +#ifdef UBFIX + if (gSineTable[sprite->data[5] + 64] != 0) + var = 0x10000 / gSineTable[sprite->data[5] + 64]; + else + var = 0xFFFF; +#else var = 0x10000 / gSineTable[sprite->data[5] + 64]; +#endif //UBFIX if (var > 0xFFFF) var = 0xFFFF; SetOamMatrix(sprite->data[1] + 1, 0x100, 0, 0, var); @@ -3186,10 +3193,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(0x800)); - SetBgTilemapBuffer(2, AllocZeroed(0x800)); - SetBgTilemapBuffer(1, AllocZeroed(0x800)); - SetBgTilemapBuffer(0, AllocZeroed(0x800)); + SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); InitWindows(sInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); @@ -3356,14 +3363,14 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_SCROLL); return; } - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_ExitInfoScreen; PlaySE(SE_PC_OFF); return; } - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { switch (sPokedexView->selectedScreen) { @@ -3400,8 +3407,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) } return; } - if (((gMain.newKeys & DPAD_LEFT) - || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((JOY_NEW(DPAD_LEFT)) + || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen > 0) { sPokedexView->selectedScreen--; @@ -3409,8 +3416,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if (((gMain.newKeys & DPAD_RIGHT) - || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((JOY_NEW(DPAD_RIGHT)) + || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen < CANCEL_SCREEN) { sPokedexView->selectedScreen++; @@ -3630,7 +3637,7 @@ static void Task_HandleCryScreenInput(u8 taskId) else LoadPlayArrowPalette(FALSE); - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { LoadPlayArrowPalette(TRUE); CryScreenPlayButton(NationalPokedexNumToSpecies(sPokedexListItem->dexNum)); @@ -3638,7 +3645,7 @@ static void Task_HandleCryScreenInput(u8 taskId) } else if (!gPaletteFade.active) { - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3647,8 +3654,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_PC_OFF); return; } - if ((gMain.newKeys & DPAD_LEFT) - || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((JOY_NEW(DPAD_LEFT)) + || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3657,8 +3664,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if ((gMain.newKeys & DPAD_RIGHT) - || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((JOY_NEW(DPAD_RIGHT)) + || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { if (!sPokedexListItem->owned) { @@ -3810,15 +3817,15 @@ static void Task_LoadSizeScreen(u8 taskId) static void Task_HandleSizeScreenInput(u8 taskId) { - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 1; gTasks[taskId].func = Task_SwitchScreensFromSizeScreen; PlaySE(SE_PC_OFF); } - else if ((gMain.newKeys & DPAD_LEFT) - || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if ((JOY_NEW(DPAD_LEFT)) + || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 2; @@ -3951,8 +3958,8 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) ResetOtherVideoRegisters(DISPCNT_BG0_ON); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sNewEntryInfoScreen_BgTemplate, ARRAY_COUNT(sNewEntryInfoScreen_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(0x800)); - SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); InitWindows(sNewEntryInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); gTasks[taskId].tState = 1; @@ -4010,7 +4017,7 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) static void Task_HandleCaughtMonPageInput(u8 taskId) { - if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + if (JOY_NEW(A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0x0000FFFF, 0, 0, 16, RGB_BLACK); gSprites[gTasks[taskId].tMonSpriteId].callback = SpriteCB_SlideCaughtMonToCenter; @@ -4167,21 +4174,17 @@ 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]; bool8 output; - u8 i = 0; + u8 i; u32 lbs = (weight * 100000) / 4536; if (lbs % 10u >= 5) lbs += 10; + i = 0; output = FALSE; - buffer[i] = (lbs / 100000) + CHAR_0; - if (buffer[i] == CHAR_0) + if ((buffer[i] = (lbs / 100000) + CHAR_0) == CHAR_0 && !output) { buffer[i++] = 0x77; } @@ -4192,8 +4195,7 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) } lbs %= 100000; - buffer[i] = (lbs / 10000) + CHAR_0; - if (buffer[i] == CHAR_0 && !output) + if ((buffer[i] = (lbs / 10000) + CHAR_0) == CHAR_0 && !output) { buffer[i++] = 0x77; } @@ -4204,13 +4206,13 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) } lbs %= 10000; - buffer[i] = (lbs / 1000) + CHAR_0; - if (buffer[i] == CHAR_0 && !output) + if ((buffer[i] = (lbs / 1000) + CHAR_0) == CHAR_0 && !output) { buffer[i++] = 0x77; } else { + output = TRUE; i++; } @@ -4226,9 +4228,6 @@ 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 @@ -4820,10 +4819,10 @@ static void Task_LoadSearchMenu(u8 taskId) ResetOtherVideoRegisters(0); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sSearchMenu_BgTemplate, ARRAY_COUNT(sSearchMenu_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(0x800)); - SetBgTilemapBuffer(2, AllocZeroed(0x800)); - SetBgTilemapBuffer(1, AllocZeroed(0x800)); - SetBgTilemapBuffer(0, AllocZeroed(0x800)); + SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); InitWindows(sSearchMenu_WindowTemplate); DeactivateAllTextPrinters(); PutWindowTilemap(0); @@ -4907,13 +4906,13 @@ static void Task_SwitchToSearchMenuTopBar(u8 taskId) static void Task_HandleSearchTopBarInput(u8 taskId) { - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { PlaySE(SE_PC_OFF); gTasks[taskId].func = Task_ExitSearch; return; } - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { switch (gTasks[taskId].tTopBarItem) { @@ -4934,7 +4933,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) } return; } - if ((gMain.newKeys & DPAD_LEFT) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) + if ((JOY_NEW(DPAD_LEFT)) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem--; @@ -4942,7 +4941,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((gMain.newKeys & DPAD_RIGHT) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) + if ((JOY_NEW(DPAD_RIGHT)) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem++; @@ -4981,14 +4980,14 @@ static void Task_HandleSearchMenuInput(u8 taskId) movementMap = sSearchMovementMap_SearchNatDex; } - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { PlaySE(SE_BALL); SetDefaultSearchModeAndOrder(taskId); gTasks[taskId].func = Task_SwitchToSearchMenuTopBar; return; } - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { if (gTasks[taskId].tMenuItem == SEARCH_OK) { @@ -5023,7 +5022,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) return; } - if ((gMain.newKeys & DPAD_LEFT) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) + if ((JOY_NEW(DPAD_LEFT)) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][0]; @@ -5031,7 +5030,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((gMain.newKeys & DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) + if ((JOY_NEW(DPAD_RIGHT)) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][1]; @@ -5039,7 +5038,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((gMain.newKeys & DPAD_UP) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) + if ((JOY_NEW(DPAD_UP)) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][2]; @@ -5047,7 +5046,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((gMain.newKeys & DPAD_DOWN) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) + if ((JOY_NEW(DPAD_DOWN)) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][3]; @@ -5091,7 +5090,7 @@ static void Task_WaitAndCompleteSearch(u8 taskId) static void Task_SearchCompleteWaitForInput(u8 taskId) { - if (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { if (sPokedexView->pokemonListCount != 0) { @@ -5117,9 +5116,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); @@ -5144,7 +5143,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 (gMain.newKeys & A_BUTTON) + if (JOY_NEW(A_BUTTON)) { PlaySE(SE_PIN); ClearSearchParameterBoxText(); @@ -5154,7 +5153,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) CopyBgTilemapBufferToVram(3); return; } - if (gMain.newKeys & B_BUTTON) + if (JOY_NEW(B_BUTTON)) { PlaySE(SE_BALL); ClearSearchParameterBoxText(); @@ -5167,7 +5166,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) return; } moved = FALSE; - if (gMain.newAndRepeatedKeys & DPAD_UP) + if (JOY_REPEAT(DPAD_UP)) { if (*cursorPos != 0) { @@ -5193,7 +5192,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) } return; } - if (gMain.newAndRepeatedKeys & DPAD_DOWN) + if (JOY_REPEAT(DPAD_DOWN)) { if (*cursorPos < MAX_SEARCH_PARAM_CURSOR_POS && *cursorPos < maxOption) { @@ -5236,84 +5235,25 @@ 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; - u16* ptr = GetBgTilemapBuffer(3); + u16 temp; //should be a pointer, but does not match as one + u32 ptr = (u32)GetBgTilemapBuffer(3); //same as above - u16* temp; for (i = 0; i < width; i++) { - // 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[x + i + 32] %= 0x1000; - temp[x + i + 32] |= flags * 0x1000; + temp = *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2); + 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); + *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2) = temp; } } -#else -__attribute__((naked)) -void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) -{ - asm(".syntax unified\n\ - 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\n\ - .syntax divided\n"); -} -#endif #define SEARCH_BG_SEARCH SEARCH_TOPBAR_SEARCH #define SEARCH_BG_SHIFT SEARCH_TOPBAR_SHIFT |