From 8349bfd8e646002105dfd6a7f997c26cf0e0624b Mon Sep 17 00:00:00 2001 From: Yoann Fievez Date: Fri, 5 Nov 2021 20:40:15 +0100 Subject: Refactorize check button pressed (#340) --- home/hidden_objects.asm | 2 +- home/list_menu.asm | 16 ++++++++-------- home/overworld.asm | 12 ++++++------ home/pokemon.asm | 2 +- home/print_text.asm | 4 ++-- home/start_menu.asm | 6 +++--- home/text_script.asm | 2 +- home/window.asm | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) (limited to 'home') diff --git a/home/hidden_objects.asm b/home/hidden_objects.asm index eccf1c8f..6e7d980a 100644 --- a/home/hidden_objects.asm +++ b/home/hidden_objects.asm @@ -5,7 +5,7 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor:: ldh a, [hLoadedROMBank] push af ldh a, [hJoyHeld] - bit 0, a ; A button + bit BIT_A_BUTTON, a jr z, .nothingFound ; A button is pressed ld a, BANK(CheckForHiddenObject) diff --git a/home/list_menu.asm b/home/list_menu.asm index d6bf43b2..77e75012 100644 --- a/home/list_menu.asm +++ b/home/list_menu.asm @@ -84,7 +84,7 @@ DisplayListMenuIDLoop:: push af call PlaceMenuCursor pop af - bit 0, a ; was the A button pressed? + bit BIT_A_BUTTON, a jp z, .checkOtherKeys .buttonAPressed ld a, [wCurrentMenuItem] @@ -168,12 +168,12 @@ DisplayListMenuIDLoop:: res 6, [hl] ; turn on letter printing delay jp BankswitchBack .checkOtherKeys ; check B, SELECT, Up, and Down keys - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a jp nz, ExitListMenu ; if so, exit the menu - bit 2, a ; was the select button pressed? + bit BIT_SELECT, a jp nz, HandleItemListSwapping ; if so, allow the player to swap menu entries ld b, a - bit 7, b ; was Down pressed? + bit BIT_D_DOWN, b ld hl, wListScrollOffset jr z, .upPressed .downPressed @@ -220,13 +220,13 @@ DisplayChooseQuantityMenu:: .waitForKeyPressLoop call JoypadLowSensitivity ldh a, [hJoyPressed] ; newly pressed buttons - bit 0, a ; was the A button pressed? + bit BIT_A_BUTTON, a jp nz, .buttonAPressed - bit 1, a ; was the B button pressed? + bit BIT_B_BUTTON, a jp nz, .buttonBPressed - bit 6, a ; was Up pressed? + bit BIT_D_UP, a jr nz, .incrementQuantity - bit 7, a ; was Down pressed? + bit BIT_D_DOWN, a jr nz, .decrementQuantity jr .waitForKeyPressLoop .incrementQuantity diff --git a/home/overworld.asm b/home/overworld.asm index eb6f2ddb..74c97cb7 100644 --- a/home/overworld.asm +++ b/home/overworld.asm @@ -72,14 +72,14 @@ OverworldLoopLessDelay:: .notSimulating ldh a, [hJoyPressed] .checkIfStartIsPressed - bit 3, a ; start button + bit BIT_START, a jr z, .startButtonNotPressed ; if START is pressed xor a ; TEXT_START_MENU ldh [hSpriteIndexOrTextID], a jp .displayDialogue .startButtonNotPressed - bit 0, a ; A button + bit BIT_A_BUTTON, a jp z, .checkIfDownButtonIsPressed ; if A is pressed ld a, [wd730] @@ -146,7 +146,7 @@ OverworldLoopLessDelay:: .checkIfDownButtonIsPressed ldh a, [hJoyHeld] ; current joypad state - bit 7, a ; down button + bit BIT_D_DOWN, a jr z, .checkIfUpButtonIsPressed ld a, 1 ld [wSpritePlayerStateData1YStepVector], a @@ -154,7 +154,7 @@ OverworldLoopLessDelay:: jr .handleDirectionButtonPress .checkIfUpButtonIsPressed - bit 6, a ; up button + bit BIT_D_UP, a jr z, .checkIfLeftButtonIsPressed ld a, -1 ld [wSpritePlayerStateData1YStepVector], a @@ -162,7 +162,7 @@ OverworldLoopLessDelay:: jr .handleDirectionButtonPress .checkIfLeftButtonIsPressed - bit 5, a ; left button + bit BIT_D_LEFT, a jr z, .checkIfRightButtonIsPressed ld a, -1 ld [wSpritePlayerStateData1XStepVector], a @@ -170,7 +170,7 @@ OverworldLoopLessDelay:: jr .handleDirectionButtonPress .checkIfRightButtonIsPressed - bit 4, a ; right button + bit BIT_D_RIGHT, a jr z, .noDirectionButtonsPressed ld a, 1 ld [wSpritePlayerStateData1XStepVector], a diff --git a/home/pokemon.asm b/home/pokemon.asm index 4e6e080b..3e63de35 100644 --- a/home/pokemon.asm +++ b/home/pokemon.asm @@ -274,7 +274,7 @@ HandlePartyMenuInput:: scf ret .swappingPokemon - bit 1, b ; was the B button pressed? + bit BIT_B_BUTTON, b jr z, .handleSwap ; if not, handle swapping the pokemon .cancelSwap ; if the B button was pressed farcall ErasePartyMenuCursors diff --git a/home/print_text.asm b/home/print_text.asm index 049ddfb4..962ae519 100644 --- a/home/print_text.asm +++ b/home/print_text.asm @@ -25,11 +25,11 @@ PrintLetterDelay:: call Joypad ldh a, [hJoyHeld] .checkAButton - bit 0, a ; is the A button pressed? + bit BIT_A_BUTTON, a jr z, .checkBButton jr .endWait .checkBButton - bit 1, a ; is the B button pressed? + bit BIT_B_BUTTON, a jr z, .buttonsNotPressed .endWait call DelayFrame diff --git a/home/start_menu.asm b/home/start_menu.asm index 5b29f67a..ed3d9470 100644 --- a/home/start_menu.asm +++ b/home/start_menu.asm @@ -15,7 +15,7 @@ RedisplayStartMenu:: call HandleMenuInput ld b, a .checkIfUpPressed - bit 6, a ; was Up pressed? + bit BIT_D_UP, a jr z, .checkIfDownPressed ld a, [wCurrentMenuItem] ; menu selection and a @@ -54,7 +54,7 @@ RedisplayStartMenu:: ld a, [wCurrentMenuItem] ld [wBattleAndStartSavedMenuItem], a ; save current menu selection ld a, b - and %00001010 ; was the Start button or B button pressed? + and B_BUTTON | START ; was the Start button or B button pressed? jp nz, CloseStartMenu call SaveScreenTilesToBuffer2 ; copy background from wTileMap to wTileMapBackup2 CheckEvent EVENT_GOT_POKEDEX @@ -79,7 +79,7 @@ RedisplayStartMenu:: CloseStartMenu:: call Joypad ldh a, [hJoyPressed] - bit 0, a ; was A button newly pressed? + bit BIT_A_BUTTON, a jr nz, CloseStartMenu call LoadTextBoxTilePatterns jp CloseTextDisplay diff --git a/home/text_script.asm b/home/text_script.asm index a6881dc5..39bc3f5b 100644 --- a/home/text_script.asm +++ b/home/text_script.asm @@ -98,7 +98,7 @@ AfterDisplayingTextID:: HoldTextDisplayOpen:: call Joypad ldh a, [hJoyHeld] - bit 0, a ; is the A button being pressed? + bit BIT_A_BUTTON, a jr nz, HoldTextDisplayOpen CloseTextDisplay:: diff --git a/home/window.asm b/home/window.asm index 0182bdd3..45b207a8 100644 --- a/home/window.asm +++ b/home/window.asm @@ -50,7 +50,7 @@ HandleMenuInput_:: ld [wCheckFor180DegreeTurn], a ldh a, [hJoy5] ld b, a - bit 6, a ; pressed Up key? + bit BIT_D_UP, a jr z, .checkIfDownPressed .upPressed ld a, [wCurrentMenuItem] ; selected menu item -- cgit v1.3.1-sl0p From f68af5c6e95a11daa3bc8daaf28c4e9a779615b9 Mon Sep 17 00:00:00 2001 From: Yoann Fievez Date: Sat, 6 Nov 2021 00:45:09 +0100 Subject: Add some constants for options (#344) Co-authored-by: Rangi <35663410+Rangi42@users.noreply.github.com> --- constants/misc_constants.asm | 9 +++++++++ engine/battle/animations.asm | 2 +- engine/battle/core.asm | 2 +- engine/battle/move_effects/substitute.asm | 2 +- engine/debug/debug_menu.asm | 2 +- engine/menus/main_menu.asm | 13 ++++++------- home/start_menu.asm | 2 +- home/window.asm | 2 +- 8 files changed, 21 insertions(+), 13 deletions(-) (limited to 'home') diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm index 1bb32f8e..4aff58da 100644 --- a/constants/misc_constants.asm +++ b/constants/misc_constants.asm @@ -7,3 +7,12 @@ TRUE EQU 1 const FLAG_RESET ; 0 const FLAG_SET ; 1 const FLAG_TEST ; 2 + +; wOptions +TEXT_DELAY_FAST EQU %001 ; 1 +TEXT_DELAY_MEDIUM EQU %011 ; 3 +TEXT_DELAY_SLOW EQU %101 ; 5 + + const_def 6 + const BIT_BATTLE_SHIFT ; 6 + const BIT_BATTLE_ANIMATION ; 7 diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index a93af9e9..476e937f 100644 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -395,7 +395,7 @@ MoveAnimation: .moveAnimation ; check if battle animations are disabled in the options ld a, [wOptions] - bit 7, a + bit BIT_BATTLE_ANIMATION, a jr nz, .animationsDisabled call ShareMoveAnimations call PlayAnimation diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 6c0585b6..efcba34b 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1372,7 +1372,7 @@ EnemySendOutFirstMon: cp LINK_STATE_BATTLING jr z, .next4 ld a, [wOptions] - bit 6, a + bit BIT_BATTLE_SHIFT, a jr nz, .next4 ld hl, TrainerAboutToUseText call PrintText diff --git a/engine/battle/move_effects/substitute.asm b/engine/battle/move_effects/substitute.asm index 860b76b6..b1fd8ac2 100644 --- a/engine/battle/move_effects/substitute.asm +++ b/engine/battle/move_effects/substitute.asm @@ -45,7 +45,7 @@ SubstituteEffect_: ld l, c set HAS_SUBSTITUTE_UP, [hl] ld a, [wOptions] - bit 7, a ; battle animation is enabled? + bit BIT_BATTLE_ANIMATION, a ld hl, PlayCurrentMoveAnimation ld b, BANK(PlayCurrentMoveAnimation) jr z, .animationEnabled diff --git a/engine/debug/debug_menu.asm b/engine/debug/debug_menu.asm index 02280db0..f2297129 100644 --- a/engine/debug/debug_menu.asm +++ b/engine/debug/debug_menu.asm @@ -26,7 +26,7 @@ IF DEF(_DEBUG) ld de, DebugMenuOptions call PlaceString - ld a, 3 ; medium speed + ld a, TEXT_DELAY_MEDIUM ld [wOptions], a ld a, A_BUTTON | B_BUTTON | START diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm index c3366b8e..7e4cc9be 100644 --- a/engine/menus/main_menu.asm +++ b/engine/menus/main_menu.asm @@ -125,9 +125,9 @@ MainMenu: jp SpecialEnterMap InitOptions: - ld a, 1 ; no delay + ld a, TEXT_DELAY_FAST ld [wLetterPrintingDelayFlags], a - ld a, 3 ; medium speed + ld a, TEXT_DELAY_MEDIUM ld [wOptions], a ret @@ -678,11 +678,10 @@ SetCursorPositionsFromOptions: ; 00: X coordinate of menu cursor ; 01: delay after printing a letter (in frames) TextSpeedOptionData: - db 14, 5 ; Slow - db 7, 3 ; Medium - db 1, 1 ; Fast - db 7 ; default X coordinate (Medium) - db -1 ; end + db 14, TEXT_DELAY_SLOW + db 7, TEXT_DELAY_MEDIUM + db 1, TEXT_DELAY_FAST + db 7, -1 ; end (default X coordinate) CheckForPlayerNameInSRAM: ; Check if the player name data in SRAM has a string terminator character diff --git a/home/start_menu.asm b/home/start_menu.asm index ed3d9470..5a531744 100644 --- a/home/start_menu.asm +++ b/home/start_menu.asm @@ -33,7 +33,7 @@ RedisplayStartMenu:: call EraseMenuCursor jr .loop .checkIfDownPressed - bit 7, a + bit BIT_D_DOWN, a jr z, .buttonPressed ; if the player pressed tried to go past the bottom item, wrap around to the top CheckEvent EVENT_GOT_POKEDEX diff --git a/home/window.asm b/home/window.asm index 45b207a8..0abe366d 100644 --- a/home/window.asm +++ b/home/window.asm @@ -68,7 +68,7 @@ HandleMenuInput_:: ld [wCurrentMenuItem], a ; wrap to the bottom of the menu jr .checkOtherKeys .checkIfDownPressed - bit 7, a + bit BIT_D_DOWN, a jr z, .checkOtherKeys .downPressed ld a, [wCurrentMenuItem] -- cgit v1.3.1-sl0p From 09e92c554c7563b52a9484b26d96d903c7635b0d Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 23 Nov 2021 21:00:07 -0500 Subject: Use ~X instead of $ff ^ X --- Makefile | 2 +- engine/battle/core.asm | 4 ++-- engine/battle/move_effects/haze.asm | 2 +- engine/debug/debug_party.asm | 2 +- home/lcd.asm | 2 +- scripts/ViridianCity.asm | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'home') diff --git a/Makefile b/Makefile index 6d432ec9..fb1122ca 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ tools: $(MAKE) -C tools/ -RGBASMFLAGS = -h -L -Weverything +RGBASMFLAGS = -h -L -Weverything -Wnumeric-string=2 -Wtruncation=1 # Create a sym/map for debug purposes if `make` run with `DEBUG=1` ifeq ($(DEBUG),1) RGBASMFLAGS += -E diff --git a/engine/battle/core.asm b/engine/battle/core.asm index efcba34b..4a166f7e 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -3433,7 +3433,7 @@ CheckPlayerStatusConditions: ld hl, wPlayerBattleStatus1 ld a, [hl] ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage) - and $ff ^ ((1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << CHARGING_UP) | (1 << USING_TRAPPING_MOVE)) + and ~((1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << CHARGING_UP) | (1 << USING_TRAPPING_MOVE)) ld [hl], a ld a, [wPlayerMoveEffect] cp FLY_EFFECT @@ -5940,7 +5940,7 @@ CheckEnemyStatusConditions: ld hl, wEnemyBattleStatus1 ld a, [hl] ; clear bide, thrashing about, charging up, and multi-turn moves such as warp - and $ff ^ ((1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << CHARGING_UP) | (1 << USING_TRAPPING_MOVE)) + and ~((1 << STORING_ENERGY) | (1 << THRASHING_ABOUT) | (1 << CHARGING_UP) | (1 << USING_TRAPPING_MOVE)) ld [hl], a ld a, [wEnemyMoveEffect] cp FLY_EFFECT diff --git a/engine/battle/move_effects/haze.asm b/engine/battle/move_effects/haze.asm index 915eeed8..c15c848b 100644 --- a/engine/battle/move_effects/haze.asm +++ b/engine/battle/move_effects/haze.asm @@ -51,7 +51,7 @@ CureVolatileStatuses: inc hl ; BATTSTATUS2 ld a, [hl] ; clear USING_X_ACCURACY, PROTECTED_BY_MIST, GETTING_PUMPED, and SEEDED statuses - and $ff ^((1 << USING_X_ACCURACY) | (1 << PROTECTED_BY_MIST) | (1 << GETTING_PUMPED) | (1 << SEEDED)) + and ~((1 << USING_X_ACCURACY) | (1 << PROTECTED_BY_MIST) | (1 << GETTING_PUMPED) | (1 << SEEDED)) ld [hli], a ; BATTSTATUS3 ld a, [hl] and %11110000 | (1 << TRANSFORMED) ; clear Bad Poison, Reflect and Light Screen statuses diff --git a/engine/debug/debug_party.asm b/engine/debug/debug_party.asm index 17baa7ef..36eb8e6f 100644 --- a/engine/debug/debug_party.asm +++ b/engine/debug/debug_party.asm @@ -46,7 +46,7 @@ IF DEF(_DEBUG) ld [wTownVisitedFlag + 1], a ; Get all badges except Earth Badge. - ld a, $ff ^ (1 << BIT_EARTHBADGE) + ld a, ~(1 << BIT_EARTHBADGE) ld [wObtainedBadges], a call SetIshiharaTeam diff --git a/home/lcd.asm b/home/lcd.asm index 72fc70ed..5c496824 100644 --- a/home/lcd.asm +++ b/home/lcd.asm @@ -12,7 +12,7 @@ DisableLCD:: jr nz, .wait ldh a, [rLCDC] - and $ff ^ rLCDC_ENABLE_MASK + and ~rLCDC_ENABLE_MASK ldh [rLCDC], a ld a, b ldh [rIE], a diff --git a/scripts/ViridianCity.asm b/scripts/ViridianCity.asm index 96e58a19..532451c9 100644 --- a/scripts/ViridianCity.asm +++ b/scripts/ViridianCity.asm @@ -18,7 +18,7 @@ ViridianCityScript_1900b: CheckEvent EVENT_VIRIDIAN_GYM_OPEN ret nz ld a, [wObtainedBadges] - cp $ff ^ (1 << BIT_EARTHBADGE) + cp ~(1 << BIT_EARTHBADGE) jr nz, .gym_closed SetEvent EVENT_VIRIDIAN_GYM_OPEN ret @@ -148,7 +148,7 @@ ViridianCityText1: ViridianCityText2: text_asm ld a, [wObtainedBadges] - cp $ff ^ (1 << BIT_EARTHBADGE) + cp ~(1 << BIT_EARTHBADGE) ld hl, ViridianCityText_19127 jr z, .done CheckEvent EVENT_BEAT_VIRIDIAN_GYM_GIOVANNI -- cgit v1.3.1-sl0p