Skip to content

Commit e1b7b8a

Browse files
authored
Use constants for PP masks instead of magic numbers (#504)
1 parent 18df084 commit e1b7b8a

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

constants/pokemon_data_constants.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ DEF NUM_GROWTH_RATES EQU const_value
9898
; wild data (see data/wild/maps/*.asm)
9999
DEF NUM_WILDMONS EQU 10
100100
DEF WILDDATA_LENGTH EQU 1 + NUM_WILDMONS * 2
101+
102+
; PP in box_struct (see macros/ram.asm)
103+
DEF PP_UP_MASK EQU %11000000 ; number of PP Up used
104+
DEF PP_MASK EQU %00111111 ; currently remaining PP

engine/battle/core.asm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ SelectMenuItem:
26442644
ld b, $0
26452645
add hl, bc
26462646
ld a, [hl]
2647-
and $3f
2647+
and PP_MASK
26482648
jr z, .noPP
26492649
ld a, [wPlayerDisabledMove]
26502650
swap a
@@ -2724,7 +2724,7 @@ AnyMoveToSelect:
27242724
or [hl]
27252725
inc hl
27262726
or [hl]
2727-
and $3f
2727+
and PP_MASK
27282728
ret nz
27292729
jr .noMovesLeft
27302730
.handleDisabledMove
@@ -2878,7 +2878,7 @@ PrintMenuItem:
28782878
ld hl, wBattleMonPP
28792879
add hl, bc
28802880
ld a, [hl]
2881-
and $3f
2881+
and PP_MASK
28822882
ld [wBattleMenuCurrentPP], a
28832883
; print TYPE/<type> and <curPP>/<maxPP>
28842884
hlcoord 1, 9
@@ -4071,18 +4071,18 @@ CheckForDisobedience:
40714071
ld hl, wBattleMonPP
40724072
push hl
40734073
ld a, [hli]
4074-
and $3f
4074+
and PP_MASK
40754075
ld b, a
40764076
ld a, [hli]
4077-
and $3f
4077+
and PP_MASK
40784078
add b
40794079
ld b, a
40804080
ld a, [hli]
4081-
and $3f
4081+
and PP_MASK
40824082
add b
40834083
ld b, a
40844084
ld a, [hl]
4085-
and $3f
4085+
and PP_MASK
40864086
add b
40874087
pop hl
40884088
push af
@@ -4091,7 +4091,7 @@ CheckForDisobedience:
40914091
ld b, $0
40924092
add hl, bc
40934093
ld a, [hl]
4094-
and $3f
4094+
and PP_MASK
40954095
ld b, a
40964096
pop af
40974097
cp b

engine/battle/effects.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ DisableEffect:
13321332
or [hl]
13331333
inc hl
13341334
or [hl]
1335-
and $3f
1335+
and PP_MASK
13361336
pop hl ; wBattleMonPP or wEnemyMonPP
13371337
jr z, .moveMissedPopHL ; nothing to do if all moves have no PP left
13381338
add hl, bc

engine/events/heal_party.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ HealParty:
5050
push bc
5151
ld b, a
5252
ld a, [hl]
53-
and $c0
53+
and PP_UP_MASK
5454
add b
5555
ld [hl], a
5656
pop bc

engine/items/item_effects.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,7 +2058,7 @@ ItemUsePPRestore:
20582058
cp MAX_ETHER
20592059
jr z, .fullyRestorePP
20602060
ld a, [hl] ; move PP
2061-
and %00111111 ; lower 6 bit bits store current PP
2061+
and PP_MASK
20622062
cp b ; does current PP equal max PP?
20632063
ret z ; if so, return
20642064
add 10 ; increase current PP by 10
@@ -2071,7 +2071,7 @@ ItemUsePPRestore:
20712071
ld b, a
20722072
.storeNewAmount
20732073
ld a, [hl] ; move PP
2074-
and %11000000 ; PP Up counter bits
2074+
and PP_UP_MASK
20752075
add b
20762076
ld [hl], a
20772077
ret
@@ -2403,7 +2403,7 @@ RestoreBonusPP:
24032403
jr nz, .nextMove
24042404
.skipMenuItemIDCheck
24052405
ld a, [hl]
2406-
and %11000000 ; have any PP Ups been used?
2406+
and PP_UP_MASK
24072407
call nz, AddBonusPP ; if so, add bonus PP
24082408
.nextMove
24092409
inc hl
@@ -2509,7 +2509,7 @@ GetMaxPP:
25092509
.addPPOffset
25102510
add hl, bc
25112511
ld a, [hl] ; a = current PP
2512-
and %11000000 ; get PP Up count
2512+
and PP_UP_MASK
25132513
pop bc
25142514
or b ; place normal max PP in 6 lower bits of a
25152515
ASSERT wMoveData + MOVE_PP + 1 == wPPUpCountAndMaxPP
@@ -2521,7 +2521,7 @@ GetMaxPP:
25212521
ld [wUsingPPUp], a
25222522
call AddBonusPP ; add bonus PP from PP Ups
25232523
ld a, [hl]
2524-
and %00111111 ; mask out the PP Up count
2524+
and PP_MASK
25252525
ld [wMaxPP], a ; store max PP
25262526
ret
25272527

engine/pokemon/status_screen.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ StatusScreen2:
364364
ld bc, wPartyMon1PP - wPartyMon1Moves - 1
365365
add hl, bc
366366
ld a, [hl]
367-
and $3f
367+
and PP_MASK
368368
ld [wStatusScreenCurrentPP], a
369369
ld h, d
370370
ld l, e

0 commit comments

Comments
 (0)