ref: 94d6a327218fc56753238b424df208245092d96c
parent: a436bbc23bb7ba723a7f897ddbe9d25830169612
author: Remy Oukaour <[email protected]>
date: Thu Jan 11 07:00:01 EST 2018
Use maskbits some more
--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -408,7 +408,7 @@
ret
.asm_e824d
- ld a, $3f
+ ld a, $3f ; sound length
ld [rNR31], a
xor a
ld [rNR30], a
@@ -1304,8 +1304,8 @@
ld [hl], a
; are we on the last channel? (noise sampling)
ld a, [CurChannel]
- and $3
- cp $3
+ maskbits NUM_MUSIC_CHANS +- 1
+ cp CHAN4
ret z
; update hi frequency from next param
call GetMusicByte
@@ -1320,8 +1320,8 @@
; load ptr to sample header in NoiseSampleAddress
; are we on the last channel?
ld a, [CurChannel]
- and $3
- cp $3
+ and NUM_MUSIC_CHANS +- 1
+ cp CHAN4
; ret if not
ret nz
; update note duration
@@ -1668,7 +1668,7 @@
; if ????, jump
; get channel
ld a, [CurChannel]
- and $3 ; ch0-3
+ maskbits NUM_MUSIC_CHANS +- 1
ld e, a
ld d, 0
; hl = Channel1JumpCondition + channel id
@@ -1966,8 +1966,8 @@
add hl, bc
ld [hl], a
ld a, [CurChannel]
- and $3
- cp CHAN8 & $3
+ maskbits NUM_MUSIC_CHANS +- 1
+ cp CHAN4
ret z
; intensity
call Music_Intensity
@@ -2414,7 +2414,7 @@
push de
; store current channel in de
ld a, [CurChannel]
- and $3
+ maskbits NUM_MUSIC_CHANS +- 1
ld e, a
ld d, 0
; get this channel's lr tracks
@@ -2449,7 +2449,7 @@
call LoadMusicByte ; store first byte of music header in a
rlca
rlca
- and $3 ; get number of channels
+ maskbits NUM_MUSIC_CHANS +- 1
inc a
.loop
; start playing channels
@@ -2505,7 +2505,7 @@
; Top 2 bits contain the number of channels
rlca
rlca
- and 3
+ maskbits NUM_MUSIC_CHANS +- 1
; For each channel:
inc a
@@ -2530,8 +2530,8 @@
; No tempo for channel 4
ld a, [CurChannel]
- and 3
- cp 3
+ maskbits NUM_MUSIC_CHANS +- 1
+ cp CHAN4
jr nc, .start
; Tempo is effectively length
@@ -2669,7 +2669,7 @@
call LoadMusicByte
rlca ; top 2
rlca ; bits
- and $3
+ maskbits NUM_MUSIC_CHANS +- 1
inc a ; # channels -> # loops
.startchannels
push af
@@ -2722,7 +2722,7 @@
call LoadMusicByte
rlca
rlca
- and 3 ; ch1-4
+ maskbits NUM_MUSIC_CHANS +- 1
inc a
.loop
@@ -2736,7 +2736,7 @@
push de
; get tracks for this channel
ld a, [CurChannel]
- and 3 ; ch1-4
+ maskbits NUM_MUSIC_CHANS +- 1
ld e, a
ld d, 0
call GetLRTracks
--- a/constants/item_data_constants.asm
+++ b/constants/item_data_constants.asm
@@ -9,21 +9,15 @@
const ITEMATTR_HELP
ITEMATTR_STRUCT_LENGTH EQU const_value
+; item types
+const_value set 1
+ const ITEM ; 1
+ const KEY_ITEM ; 2
+ const BALL ; 3
+ const TM_HM ; 4
-; pack pockets
-ITEM EQU 1
-KEY_ITEM EQU 2
-BALL EQU 3
-TM_HM EQU 4
-
-; pack pocket sizes
-MAX_ITEMS EQU 20
-MAX_KEY_ITEMS EQU 25
-MAX_BALLS EQU 12
-MAX_PC_ITEMS EQU 50
-
-
; item menu types
+; UseItem.dw indexes (see engine/pack.asm)
ITEMMENU_NOUSE EQU 0
ITEMMENU_CURRENT EQU 4
ITEMMENU_PARTY EQU 5
@@ -32,6 +26,20 @@
; item actions
CANT_SELECT EQU 1 << 6
CANT_TOSS EQU 1 << 7
+
+
+; pack pockets
+ const_def
+ const ITEM_POCKET ; 0
+ const BALL_POCKET ; 1
+ const KEY_ITEM_POCKET ; 2
+ const TM_HM_POCKET ; 3
+NUM_POCKETS EQU const_value +- 1
+
+MAX_ITEMS EQU 20
+MAX_BALLS EQU 12
+MAX_KEY_ITEMS EQU 25
+MAX_PC_ITEMS EQU 50
--- a/constants/landmark_constants.asm
+++ b/constants/landmark_constants.asm
@@ -100,3 +100,13 @@
const TOHJO_FALLS ; 5d
const ROUTE_28 ; 5e
const FAST_SHIP ; 5f
+
+; used in CaughtData
+GIFT_LOCATION EQU $7e
+EVENT_LOCATION EQU $7f
+
+
+; Regions
+ const_def
+ const JOHTO_REGION ; 0
+ const KANTO_REGION ; 1
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -86,3 +86,10 @@
; day-care
MAX_DAY_CARE_EXP EQU $500000
+
+; bug-catching contest
+BUG_CONTEST_MINUTES EQU 20
+BUG_CONTEST_SECONDS EQU 0
+BUG_CONTEST_PLAYER EQU 1
+NUM_BUG_CONTESTANTS EQU 10 ; not counting the player
+BUG_CONTESTANT_SIZE EQU 4
--- a/constants/music_constants.asm
+++ b/constants/music_constants.asm
@@ -111,6 +111,10 @@
; GetMapHeaderMusic picks music for this value (see home/map.asm)
MUSIC_MAHOGANY_MART EQU $64
+; ExitPokegearRadio_HandleMusic uses these values
+RESTART_MAP_MUSIC EQU $fe
+ENTER_MAP_MUSIC EQU $ff
+
; GetMapHeaderMusic picks music for this bit flag
RADIO_TOWER_MUSIC_F EQU 7
RADIO_TOWER_MUSIC EQU 1 << RADIO_TOWER_MUSIC_F
--- a/constants/npctrade_constants.asm
+++ b/constants/npctrade_constants.asm
@@ -19,3 +19,25 @@
const NPCTRADE_CHRIS ; 4
const NPCTRADE_KIM ; 5
const NPCTRADE_FOREST ; 6
+
+; trade gender limits
+TRADE_EITHER_GENDER EQU 0
+TRADE_MALE_ONLY EQU 1
+TRADE_FEMALE_ONLY EQU 2
+
+; TradeTexts indexes (see engine/npctrade.asm)
+
+; trade dialogs
+ const_def
+ const TRADE_INTRO
+ const TRADE_CANCEL
+ const TRADE_WRONG
+ const TRADE_COMPLETE
+ const TRADE_AFTER
+
+; trade dialog sets
+ const_def
+ const TRADE_DIALOG_COLLECTOR
+ const TRADE_DIALOG_HAPPY
+ const TRADE_DIALOG_NEWBIE
+ const TRADE_DIALOG_GIRL
--- a/constants/pokemon_data_constants.asm
+++ b/constants/pokemon_data_constants.asm
@@ -63,6 +63,10 @@
const NO_EGGS ; f
+; pokedex entries (see data/pokemon/dex_entries.asm)
+NUM_DEX_ENTRY_BANKS EQU 4
+
+
; party_struct members (see macros/wram.asm)
MON_SPECIES EQUS "(PartyMon1Species - PartyMon1)"
MON_ITEM EQUS "(PartyMon1Item - PartyMon1)"
@@ -96,6 +100,21 @@
BOXMON_STRUCT_LENGTH EQUS "(PartyMon1End - PartyMon1)"
PARTYMON_STRUCT_LENGTH EQUS "(PartyMon1StatsEnd - PartyMon1)"
REDMON_STRUCT_LENGTH EQU 44
+
+
+; caught data
+
+CAUGHT_TIME_MASK EQU %11000000
+CAUGHT_LEVEL_MASK EQU %00111111
+
+CAUGHT_GENDER_MASK EQU %10000000
+CAUGHT_LOCATION_MASK EQU %01111111
+
+CAUGHT_BY_UNKNOWN EQU 0
+CAUGHT_BY_GIRL EQU 1
+CAUGHT_BY_BOY EQU 2
+
+CAUGHT_EGG_LEVEL EQU 1
; maximum number of party pokemon
--- a/constants/wram_constants.asm
+++ b/constants/wram_constants.asm
@@ -52,6 +52,7 @@
const UP ; 1
const LEFT ; 2
const RIGHT ; 3
+NUM_DIRECTIONS EQU const_value
DOWN_MASK EQU 1 << DOWN
UP_MASK EQU 1 << UP
@@ -71,6 +72,7 @@
const DAY_F ; 1
const NITE_F ; 2
const DARKNESS_F ; 3
+NUM_DAYTIMES EQU const_value
MORN EQU 1 << MORN_F
DAY EQU 1 << DAY_F
--- /dev/null
+++ b/data/bug_contest_flags.asm
@@ -1,0 +1,13 @@
+BugCatchingContestantEventFlagTable: ; 139fe
+; there are NUM_BUG_CONTESTANTS entries
+ dw EVENT_BUG_CATCHING_CONTESTANT_1A
+ dw EVENT_BUG_CATCHING_CONTESTANT_2A
+ dw EVENT_BUG_CATCHING_CONTESTANT_3A
+ dw EVENT_BUG_CATCHING_CONTESTANT_4A
+ dw EVENT_BUG_CATCHING_CONTESTANT_5A
+ dw EVENT_BUG_CATCHING_CONTESTANT_6A
+ dw EVENT_BUG_CATCHING_CONTESTANT_7A
+ dw EVENT_BUG_CATCHING_CONTESTANT_8A
+ dw EVENT_BUG_CATCHING_CONTESTANT_9A
+ dw EVENT_BUG_CATCHING_CONTESTANT_10A
+; 13a12
--- a/data/bug_contest_winners.asm
+++ b/data/bug_contest_winners.asm
@@ -1,5 +1,6 @@
BugContestantPointers: ; 13783
- dw BugContestant_BugCatcherDon ; This reverts back to the player
+; there are NUM_BUG_CONTESTANTS + 1 entries
+ dw BugContestant_BugCatcherDon ; this reverts back to the player
dw BugContestant_BugCatcherDon
dw BugContestant_BugCatcherEd
dw BugContestant_CooltrainerMNick
@@ -11,6 +12,12 @@
dw BugContestant_YoungsterSamuel
dw BugContestant_SchoolboyKipp
; 13799
+
+; contestant format:
+; db class, id
+; dbw 1st-place mon, score
+; dbw 2nd-place mon, score
+; dbw 3rd-place mon, score
BugContestant_BugCatcherDon:
db BUG_CATCHER, DON
--- a/data/npc_trades.asm
+++ b/data/npc_trades.asm
@@ -1,7 +1,3 @@
-TRADE_EITHER_GENDER EQU 0
-TRADE_MALE_ONLY EQU 1
-TRADE_FEMALE_ONLY EQU 2
-
npctrade: MACRO
; dialog set, requested mon, offered mon, nickname, dvs, item, OT ID, OT name, gender requested
db \1, \2, \3, \4, \5, \6, \7
@@ -12,11 +8,11 @@
NPCTrades: ; fce58
; entries correspond to NPCTRADE_* constants
- npctrade 0, ABRA, MACHOP, "MUSCLE@@@@@", $37, $66, GOLD_BERRY, 37460, "MIKE@@@@@@@", TRADE_EITHER_GENDER
- npctrade 0, BELLSPROUT, ONIX, "ROCKY@@@@@@", $96, $66, BITTER_BERRY, 48926, "KYLE@@@@@@@", TRADE_EITHER_GENDER
- npctrade 1, KRABBY, VOLTORB, "VOLTY@@@@@@", $98, $88, PRZCUREBERRY, 29189, "TIM@@@@@@@@", TRADE_EITHER_GENDER
- npctrade 3, DRAGONAIR, DODRIO, "DORIS@@@@@@", $77, $66, SMOKE_BALL, 00283, "EMY@@@@@@@@", TRADE_FEMALE_ONLY
- npctrade 2, HAUNTER, XATU, "PAUL@@@@@@@", $96, $86, MYSTERYBERRY, 15616, "CHRIS@@@@@@", TRADE_EITHER_GENDER
- npctrade 3, CHANSEY, AERODACTYL, "AEROY@@@@@@", $96, $66, GOLD_BERRY, 26491, "KIM@@@@@@@@", TRADE_EITHER_GENDER
- npctrade 0, DUGTRIO, MAGNETON, "MAGGIE@@@@@", $96, $66, METAL_COAT, 50082, "FOREST@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_COLLECTOR, ABRA, MACHOP, "MUSCLE@@@@@", $37, $66, GOLD_BERRY, 37460, "MIKE@@@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_COLLECTOR, BELLSPROUT, ONIX, "ROCKY@@@@@@", $96, $66, BITTER_BERRY, 48926, "KYLE@@@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_HAPPY, KRABBY, VOLTORB, "VOLTY@@@@@@", $98, $88, PRZCUREBERRY, 29189, "TIM@@@@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_GIRL, DRAGONAIR, DODRIO, "DORIS@@@@@@", $77, $66, SMOKE_BALL, 00283, "EMY@@@@@@@@", TRADE_FEMALE_ONLY
+ npctrade TRADE_DIALOG_NEWBIE, HAUNTER, XATU, "PAUL@@@@@@@", $96, $86, MYSTERYBERRY, 15616, "CHRIS@@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_GIRL, CHANSEY, AERODACTYL, "AEROY@@@@@@", $96, $66, GOLD_BERRY, 26491, "KIM@@@@@@@@", TRADE_EITHER_GENDER
+ npctrade TRADE_DIALOG_COLLECTOR, DUGTRIO, MAGNETON, "MAGGIE@@@@@", $96, $66, METAL_COAT, 50082, "FOREST@@@@@", TRADE_EITHER_GENDER
; fcf38
--- a/engine/battle/ai/move.asm
+++ b/engine/battle/ai/move.asm
@@ -56,7 +56,7 @@
inc hl
ld a, [de]
inc de
- and $3f
+ and PP_MASK
jr nz, .CheckMovePP
ld [hl], 80
jr .CheckMovePP
@@ -186,7 +186,7 @@
.ChooseMove:
ld hl, Buffer1
call Random
- and 3
+ maskbits NUM_MOVES +- 1
ld c, a
ld b, 0
add hl, bc
--- a/engine/battle/battle_transition.asm
+++ b/engine/battle/battle_transition.asm
@@ -640,8 +640,8 @@
.cgb
ld hl, .daypals
ld a, [TimeOfDayPal]
- and $3
- cp 3
+ maskbits NUM_DAYTIMES +- 1
+ cp DARKNESS_F
jr nz, .daytime
ld hl, .nightpals
.daytime
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -730,7 +730,7 @@
ld b, 0
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
ret nz
.end_player_encore
@@ -754,7 +754,7 @@
ld b, 0
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
ret nz
.end_enemy_encore
@@ -1401,7 +1401,7 @@
and a
jr z, .quit
ld a, [de]
- and $3f
+ and PP_MASK
jr z, .restore
inc hl
inc de
@@ -5650,7 +5650,7 @@
ld b, 0
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
jr z, .no_pp_left
ld a, [PlayerDisableCount]
swap a
@@ -5849,7 +5849,7 @@
ld hl, BattleMonPP
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
ld [StringBuffer1], a
call .PrintPP
@@ -5912,7 +5912,7 @@
or [hl]
inc hl
or [hl]
- and $3f
+ and PP_MASK
ret nz
jr .force_struggle
@@ -5934,8 +5934,7 @@
.done
; Bug: this will result in a move with PP Up confusing the game.
- ; Replace with "and $3f" to fix.
- and a
+ and a ; should be "and PP_MASK"
ret nz
.force_struggle
@@ -6014,7 +6013,7 @@
cp [hl]
jr z, .disabled
ld a, [de]
- and $3f
+ and PP_MASK
jr nz, .enough_pp
.disabled
@@ -6032,7 +6031,7 @@
.loop2
ld hl, EnemyMonMoves
call BattleRandom
- and 3 ; TODO factor in NUM_MOVES
+ maskbits NUM_MOVES +- 1
ld c, a
ld b, 0
add hl, bc
@@ -6049,7 +6048,7 @@
add hl, bc
ld b, a
ld a, [hl]
- and $3f
+ and PP_MASK
jr z, .loop2
ld a, c
ld [CurEnemyMoveNum], a
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -846,19 +846,20 @@
.DoNothing:
+ ; 4 random choices
call BattleRandom
- and 3
+ and %11
ld hl, LoafingAroundText
- and a
+ and a ; 0
jr z, .Print
ld hl, WontObeyText
- dec a
+ dec a ; 1
jr z, .Print
ld hl, TurnedAwayText
- dec a
+ dec a ; 2
jr z, .Print
ld hl, IgnoredOrdersText
@@ -888,7 +889,7 @@
.GetTotalPP:
ld a, [hli]
- and $3f ; exclude pp up
+ and PP_MASK
add b
ld b, a
@@ -911,7 +912,7 @@
; Can't use another move if only one move has PP.
ld a, [hl]
- and $3f
+ and PP_MASK
cp b
jr z, .DoNothing
@@ -931,7 +932,7 @@
.RandomMove:
call BattleRandom
- and 3 ; TODO NUM_MOVES
+ maskbits NUM_MOVES +- 1
cp b
jr nc, .RandomMove
@@ -947,7 +948,7 @@
ld d, 0
add hl, de
ld a, [hl]
- and $3f
+ and PP_MASK
jr z, .RandomMove
@@ -1118,7 +1119,7 @@
ld b, 0
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
jr z, .out_of_pp
dec [hl]
ld b, 0
@@ -3906,7 +3907,7 @@
ld bc, BattleMonPP - BattleMonMoves - 1
add hl, bc
ld a, [hl]
- and $3f
+ and PP_MASK
jp z, .failed
ld a, [AttackMissed]
and a
@@ -4386,7 +4387,7 @@
.sample_move
push hl
call BattleRandom
- and 3 ; TODO factor in NUM_MOVES
+ maskbits NUM_MOVES +- 1
ld c, a
ld b, 0
add hl, bc
@@ -4550,17 +4551,18 @@
add hl, bc
pop bc
ld a, [hl]
- and $3f
+ and PP_MASK
jr z, .failed
push bc
call GetMoveName
+ ; lose 2-5 PP
call BattleRandom
- and 3
+ and %11
inc a
inc a
ld b, a
ld a, [hl]
- and $3f
+ and PP_MASK
cp b
jr nc, .deplete_pp
ld b, a
@@ -6208,13 +6210,12 @@
call BattleCommand_EffectChance
-; 1/3 chance of each status
.loop
+ ; 1/3 chance of each status
call BattleRandom
swap a
- and 3
+ and %11
jr z, .loop
-; jump
dec a
ld hl, .ptrs
rst JumpTable
@@ -7392,7 +7393,8 @@
bit SUBSTATUS_SUBSTITUTE, a
ret nz
call BattleRandom
- and 3
+ ; trapped for 2-5 turns
+ and %11
inc a
inc a
inc a
@@ -7590,8 +7592,9 @@
.got_confuse_count
set SUBSTATUS_CONFUSED, [hl]
+ ; confused for 2-5 turns
call BattleRandom
- and 3
+ and %11
inc a
inc a
ld [bc], a
@@ -8201,7 +8204,7 @@
.done
.loop3
call BattleRandom
- and 3 ; TODO factor in NUM_MOVES
+ maskbits NUM_MOVES +- 1
ld c, a
ld b, 0
ld hl, StringBuffer1
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -1207,7 +1207,7 @@
srl a
ld [wSFXDuration], a
call .GetCryTrack
- and 3
+ maskbits NUM_NOISE_CHANS +- 1
ld [CryTracks], a ; CryTracks
ld e, a
@@ -1244,7 +1244,7 @@
BattleAnimCmd_Cry: ; cc807 (33:4807)
call GetBattleAnimByte
- and 3
+ maskbits NUM_NOISE_CHANS +- 1
ld e, a
ld d, 0
ld hl, .CryData
--- a/engine/billspc.asm
+++ b/engine/billspc.asm
@@ -136,7 +136,7 @@
jp c, BillsPCDepositFuncCancel
ld a, [wMenuCursorY]
dec a
- and $3
+ and %11
ld e, a
ld d, 0
ld hl, BillsPCDepositJumptable
@@ -401,7 +401,7 @@
jp c, .cancel
ld a, [wMenuCursorY]
dec a
- and 3
+ and %11
ld e, a
ld d, 0
ld hl, .dw
@@ -663,7 +663,7 @@
jp c, .Cancel
ld a, [wMenuCursorY]
dec a
- and 3
+ and %11
ld e, a
ld d, 0
ld hl, .Jumptable2
--- a/engine/caught_data.asm
+++ b/engine/caught_data.asm
@@ -7,17 +7,17 @@
call GetBaseData
ld hl, PartyCount
ld a, [hl]
- cp 6
+ cp PARTY_LENGTH
jp nc, .TryAddToBox
inc a
ld [hl], a
ld c, a
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [wContestMon]
ld [hli], a
ld [CurSpecies], a
- ld a, $ff
+ ld a, -1
ld [hl], a
ld hl, PartyMon1Species
ld a, [PartyCount]
@@ -75,8 +75,8 @@
ld hl, PartyMon1CaughtLocation
call GetPartyLocation
ld a, [hl]
- and $80
- ld b, $13
+ and CAUGHT_GENDER_MASK
+ ld b, NATIONAL_PARK
or b
ld [hl], a
xor a
@@ -135,8 +135,8 @@
call GetSRAMBank
ld hl, sBoxMon1CaughtLocation
ld a, [hl]
- and $80
- ld b, $13
+ and CAUGHT_GENDER_MASK
+ ld b, NATIONAL_PARK
or b
ld [hl], a
call CloseSRAM
@@ -227,7 +227,7 @@
SetGiftMonCaughtData: ; 4dbaf
xor a
ld [hli], a
- ld a, $7e
+ ld a, GIFT_LOCATION
rrc b
or b
ld [hl], a
@@ -239,7 +239,7 @@
call GetPartyLocation
ld a, [CurPartyLevel]
push af
- ld a, $1
+ ld a, CAUGHT_EGG_LEVEL
ld [CurPartyLevel], a
call SetBoxmonOrEggmonCaughtData
pop af
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -1240,7 +1240,7 @@
ld l, a
; Futher refine by time of day
ld a, [TimeOfDayPal]
- and 3
+ maskbits NUM_DAYTIMES +- 1
add a
add a
add a
@@ -1286,7 +1286,7 @@
.got_pals
ld a, [TimeOfDayPal]
- and 3
+ maskbits NUM_DAYTIMES +- 1
ld bc, 8 palettes
ld hl, MapObjectPals
call AddNTimes
@@ -1310,7 +1310,7 @@
ld de, RoofPals
add hl, de
ld a, [TimeOfDayPal]
- and 3
+ maskbits NUM_DAYTIMES +- 1
cp NITE_F
jr c, .morn_day
rept 4
--- a/engine/credits.asm
+++ b/engine/credits.asm
@@ -504,7 +504,7 @@
.GetPalAddress:
; Each set of palette data is 24 bytes long.
ld a, [wCreditsBorderMon] ; scene
- and 3
+ and %11
add a
add a ; * 8
add a
@@ -549,13 +549,13 @@
cp $ff
jr z, .init
- and 3
+ and %11
ld e, a
inc a
- and 3
+ and %11
ld [hl], a
ld a, [wCreditsBorderMon]
- and 3
+ and %11
add a
add a
add e
--- a/engine/crystal_intro.asm
+++ b/engine/crystal_intro.asm
@@ -247,10 +247,10 @@
ld hl, SPRITEANIMSTRUCT_0D
add hl, bc
ld a, [hl]
- and $3f
- cp $20
+ and %111111
+ cp %100000
jr nc, .asm_e4723
- add $20
+ add %100000
.asm_e4723
ld e, a
farcall BattleAnim_Sine_e
@@ -1604,12 +1604,12 @@
inc hl
inc hl
ld a, [wcf65]
- and $3f
- cp $1f
+ and %111111
+ cp %011111
jr z, .okay
jr c, .okay
ld c, a
- ld a, $3f
+ ld a, %111111
sub c
.okay
--- a/engine/events/buena.asm
+++ b/engine/events/buena.asm
@@ -17,7 +17,7 @@
ld a, [MenuSelection]
ld c, a
ld a, [wBuenasPassword]
- and $3
+ maskbits NUM_PASSWORDS_PER_CATEGORY +- 1
cp c
jr nz, .wrong
ld b, $1
@@ -46,7 +46,7 @@
; 0x8afb4
.PasswordIndices: ; 8afb8
- db 3
+ db NUM_PASSWORDS_PER_CATEGORY
db 0, 1, 2
db -1
--- a/engine/events/bug_contest/contest_2.asm
+++ b/engine/events/bug_contest/contest_2.asm
@@ -2,7 +2,7 @@
; Select five random people to participate in the current contest.
; First we have to make sure that any old data is cleared away.
- ld c, 10 ; Number of people to choose from.
+ ld c, NUM_BUG_CONTESTANTS
ld hl, BugCatchingContestantEventFlagTable
.loop1
push bc
@@ -26,9 +26,9 @@
.next
; Choose a flag at uniform random to be set.
call Random
- cp 250
+ cp $ff / NUM_BUG_CONTESTANTS * NUM_BUG_CONTESTANTS
jr nc, .next
- ld c, 25
+ ld c, $ff / NUM_BUG_CONTESTANTS
call SimpleDivide
ld e, b
ld d, 0
@@ -59,7 +59,7 @@
Special_CheckBugContestContestantFlag: ; 139ed
; Checks the flag of the Bug Catching Contestant whose index is loaded in a.
-; Bug: If a >= 10 when this is called, it will read beyond the table.
+; Bug: If a >= NUM_BUG_CONTESTANTS when this is called, it will read beyond the table.
ld hl, BugCatchingContestantEventFlagTable
ld e, a
@@ -74,18 +74,7 @@
ret
; 139fe
-BugCatchingContestantEventFlagTable: ; 139fe
- dw EVENT_BUG_CATCHING_CONTESTANT_1A
- dw EVENT_BUG_CATCHING_CONTESTANT_2A
- dw EVENT_BUG_CATCHING_CONTESTANT_3A
- dw EVENT_BUG_CATCHING_CONTESTANT_4A
- dw EVENT_BUG_CATCHING_CONTESTANT_5A
- dw EVENT_BUG_CATCHING_CONTESTANT_6A
- dw EVENT_BUG_CATCHING_CONTESTANT_7A
- dw EVENT_BUG_CATCHING_CONTESTANT_8A
- dw EVENT_BUG_CATCHING_CONTESTANT_9A
- dw EVENT_BUG_CATCHING_CONTESTANT_10A
-; 13a12
+INCLUDE "data/bug_contest_flags.asm"
ContestDropOffMons: ; 13a12
ld hl, PartyMon1HP
@@ -101,7 +90,7 @@
ld a, [hl]
ld [wBugContestSecondPartySpecies], a
; ... and replacing it with the terminator byte
- ld [hl], $ff
+ ld [hl], -1
xor a
ld [ScriptVar], a
ret
@@ -118,7 +107,7 @@
ld a, [wBugContestSecondPartySpecies]
ld [hl], a
; Restore the party count, which must be recomputed.
- ld b, $1
+ ld b, 1
.loop
ld a, [hli]
cp -1
--- a/engine/events/bug_contest/judging.asm
+++ b/engine/events/bug_contest/judging.asm
@@ -77,9 +77,8 @@
; 0x13730
LoadContestantName: ; 13730
-
-; If a = 0, get your name.
- dec a
+; If a = 1, get your name.
+ dec a ; BUG_CONTEST_PLAYER
jr z, .player
; Find the pointer for the trainer class of the Bug Catching Contestant whose ID is in a.
ld c, a
@@ -141,11 +140,11 @@
BugContest_GetPlayersResult: ; 13807
ld hl, wBugContestThirdPlaceWinnerID
- ld de, -4
- ld b, 3
+ ld de, - BUG_CONTESTANT_SIZE
+ ld b, 3 ; 3rd, 2nd, or 1st
.loop
ld a, [hl]
- cp 1 ; Player
+ cp BUG_CONTEST_PLAYER
jr z, .done
add hl, de
dec b
@@ -159,7 +158,7 @@
call ClearContestResults
call ComputeAIContestantScores
ld hl, wBugContestTempWinnerID
- ld a, 1 ; Player
+ ld a, BUG_CONTEST_PLAYER
ld [hli], a
ld a, [wContestMon]
ld [hli], a
@@ -190,11 +189,11 @@
jr c, .not_first_place
ld hl, wBugContestSecondPlaceWinnerID
ld de, wBugContestThirdPlaceWinnerID
- ld bc, 4
+ ld bc, BUG_CONTESTANT_SIZE
call CopyBytes
ld hl, wBugContestFirstPlaceWinnerID
ld de, wBugContestSecondPlaceWinnerID
- ld bc, 4
+ ld bc, BUG_CONTESTANT_SIZE
call CopyBytes
ld hl, wBugContestFirstPlaceWinnerID
call CopyTempContestant
@@ -208,7 +207,7 @@
jr c, .not_second_place
ld hl, wBugContestSecondPlaceWinnerID
ld de, wBugContestThirdPlaceWinnerID
- ld bc, 4
+ ld bc, BUG_CONTESTANT_SIZE
call CopyBytes
ld hl, wBugContestSecondPlaceWinnerID
call CopyTempContestant
@@ -230,7 +229,7 @@
CopyTempContestant: ; 138a0
; Could've just called CopyBytes.
ld de, wBugContestTempWinnerID
-rept 3
+rept BUG_CONTESTANT_SIZE +- 1
ld a, [de]
inc de
ld [hli], a
@@ -264,6 +263,7 @@
inc hl
inc hl
.loop2
+ ; 0, 1, or 2 for 1st, 2nd, or 3rd
call Random
and 3
cp 3
@@ -278,8 +278,9 @@
ld a, [hli]
ld h, [hl]
ld l, a
+ ; randomly perturb score
call Random
- and 7
+ and %111
ld c, a
ld b, 0
add hl, bc
@@ -294,7 +295,7 @@
.done
inc e
ld a, e
- cp 10
+ cp NUM_BUG_CONTESTANTS
jr nz, .loop
ret
; 13900
@@ -337,7 +338,7 @@
; DVs
ld a, [wContestMonDVs + 0]
ld b, a
- and 2
+ and %0010
add a
add a
ld c, a
@@ -344,7 +345,7 @@
swap b
ld a, b
- and 2
+ and %0010
add a
add c
ld d, a
@@ -351,12 +352,12 @@
ld a, [wContestMonDVs + 1]
ld b, a
- and 2
+ and %0010
ld c, a
swap b
ld a, b
- and 2
+ and %0010
srl a
add c
add c
--- a/engine/events/fish.asm
+++ b/engine/events/fish.asm
@@ -80,7 +80,7 @@
endr
ld a, [TimeOfDay]
- and 3
+ maskbits NUM_DAYTIMES +- 1
cp NITE_F
jr c, .time_species
inc hl
--- a/engine/events/magnet_train.asm
+++ b/engine/events/magnet_train.asm
@@ -435,7 +435,7 @@
ld a, [wEnvironment]
push af
ld a, [TimeOfDay]
- and $3
+ maskbits NUM_DAYTIMES +- 1
ld [TimeOfDayPal], a
ld a, $1
ld [wEnvironment], a
--- a/engine/events/poisonstep_pals.asm
+++ b/engine/events/poisonstep_pals.asm
@@ -10,8 +10,8 @@
and a
jr nz, .cgb
ld a, [TimeOfDayPal]
- and $3
- cp $3
+ maskbits NUM_DAYTIMES +- 1
+ cp DARKNESS_F
ld a, %00000000
jr z, .convert_pals
ld a, %10101010
--- a/engine/events/poke_seer.asm
+++ b/engine/events/poke_seer.asm
@@ -20,7 +20,7 @@
call PrintSeerText
call JoyWaitAorB
- ld b, $6
+ ld b, PARTY_LENGTH
farcall SelectMonFromParty
jr c, .cancel
@@ -163,11 +163,11 @@
call ByteFill
; caught level
- ; Limited to between 1 and 63 for some reason.
+ ; Limited to between 1 and 63 since it's a 6-bit quantity.
ld a, [wSeerCaughtData]
- and $3f
+ and CAUGHT_LEVEL_MASK
jr z, .unknown
- cp 1 ; hatched from an egg
+ cp CAUGHT_EGG_LEVEL ; egg marker value
jr nz, .print
ld a, EGG_LEVEL ; egg hatch level
@@ -193,7 +193,7 @@
GetCaughtTime: ; 4f1c5
ld a, [wSeerCaughtData]
- and $c0
+ and CAUGHT_TIME_MASK
jr z, .none
rlca
@@ -233,11 +233,11 @@
GetCaughtLocation: ; 4f20a
ld a, [wSeerCaughtGender]
- and $7f
+ and CAUGHT_LOCATION_MASK
jr z, .Unknown
- cp $7f
+ cp EVENT_LOCATION
jr z, .event
- cp $7e
+ cp GIFT_LOCATION
jr z, .fail
ld e, a
farcall GetLandmarkName
@@ -440,22 +440,22 @@
add hl, bc
ld a, [hl]
- and $7f
+ and CAUGHT_LOCATION_MASK
jr z, .genderless
- cp $7f
+ cp EVENT_LOCATION
jr z, .genderless
ld a, [hl]
- and $80
+ and CAUGHT_GENDER_MASK
jr nz, .male
- ld c, 1
+ ld c, CAUGHT_BY_GIRL
ret
.male
- ld c, 2
+ ld c, CAUGHT_BY_BOY
ret
.genderless
- ld c, 0
+ ld c, CAUGHT_BY_UNKNOWN
ret
; 4f31c
--- a/engine/intro_menu.asm
+++ b/engine/intro_menu.asm
@@ -1333,7 +1333,7 @@
Function639b: ; unreferenced
; If bit 0 or 1 of [wTitleScreenTimer] is set, we don't need to be here.
ld a, [wTitleScreenTimer]
- and $3
+ and %00000011
ret nz
ld bc, SpriteAnim10
ld hl, SPRITEANIMSTRUCT_FRAME
--- a/engine/item_effects.asm
+++ b/engine/item_effects.asm
@@ -775,7 +775,7 @@
ld a, [EnemyMonSpecies]
rlca
rlca
- and 3
+ maskbits NUM_DEX_ENTRY_BANKS +- 1
ld hl, .PokedexEntryBanks
ld d, 0
ld e, a
@@ -786,12 +786,6 @@
ret
.PokedexEntryBanks:
-
-GLOBAL PokedexEntries1
-GLOBAL PokedexEntries2
-GLOBAL PokedexEntries3
-GLOBAL PokedexEntries4
-
db BANK(PokedexEntries1)
db BANK(PokedexEntries2)
db BANK(PokedexEntries3)
--- a/engine/landmarks.asm
+++ b/engine/landmarks.asm
@@ -80,8 +80,8 @@
jr c, .kanto
.johto
- ld e, 0
+ ld e, JOHTO_REGION
ret
.kanto
- ld e, 1
+ ld e, KANTO_REGION
ret
--- a/engine/map_objects.asm
+++ b/engine/map_objects.asm
@@ -894,7 +894,7 @@
ld hl, OBJECT_DIRECTION_WALKING
add hl, de
ld a, [hl]
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld d, 1 * 8 + 6
cp DOWN
jr z, .ok_13
--- a/engine/mystery_gift_2.asm
+++ b/engine/mystery_gift_2.asm
@@ -29,7 +29,7 @@
inc de ; wc80f
call CloseSRAM
call Random
- and $1
+ and 1
ld [de], a
inc de ; wc810
call .RandomSample
@@ -59,10 +59,10 @@
.RandomSample: ; 2c6ac (b:46ac)
push de
call Random
- cp $19 ; 10 percent
+ cp 10 percent
jr c, .tenpercent
call Random
- and $7
+ and %111
ld d, a
rl d
ld e, $80
@@ -80,10 +80,10 @@
.tenpercent
call Random
- cp $32 ; 20 percent
+ cp 20 percent - 1
jr c, .twopercent
call Random
- and $3
+ and %011
ld d, a
rl d
ld e, $80
@@ -102,7 +102,7 @@
.twopercent
call Random
- cp $32 ; 50 ; 20 percent
+ cp 20 percent - 1
jr c, .pointfourpercent
ld a, b
swap a
--- a/engine/npc_movement.asm
+++ b/engine/npc_movement.asm
@@ -70,7 +70,7 @@
ld e, [hl]
ld hl, OBJECT_PALETTE
add hl, bc
- bit 7, [hl]
+ bit OAM_PRIORITY, [hl]
jp nz, Function6fa1
ld hl, OBJECT_NEXT_TILE
add hl, bc
@@ -77,7 +77,7 @@
ld a, [hl]
ld d, a
call GetTileCollision
- and a ; land
+ and a ; LANDTILE
jr z, Function6f3e
scf
ret
@@ -106,7 +106,7 @@
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld e, a
ld d, 0
ld hl, .data_6f5b
@@ -131,7 +131,7 @@
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld e, a
ld d, 0
ld hl, .data_6f7b
@@ -178,49 +178,49 @@
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
- and 3
- jr z, .asm_6fb2
+ maskbits NUM_DIRECTIONS +- 1
+ jr z, .down
dec a
- jr z, .asm_6fb7
+ jr z, .up
dec a
- jr z, .asm_6fbb
- jr .asm_6fbf
+ jr z, .left
+ jr .right
-.asm_6fb2
+.down
inc e
push de
inc d
- jr .asm_6fc2
+ jr .continue
-.asm_6fb7
+.up
push de
inc d
- jr .asm_6fc2
+ jr .continue
-.asm_6fbb
+.left
push de
inc e
- jr .asm_6fc2
+ jr .continue
-.asm_6fbf
+.right
inc d
push de
inc e
-.asm_6fc2
+.continue
call GetCoordTile
call GetTileCollision
pop de
- and a ; land
- jr nz, .asm_6fd7
+ and a ; LANDTILE
+ jr nz, .not_land
call GetCoordTile
call GetTileCollision
- and a ; land
- jr nz, .asm_6fd7
+ and a ; LANDTILE
+ jr nz, .not_land
xor a
ret
-.asm_6fd7
+.not_land
scf
ret
; 6fd9
--- a/engine/npctrade.asm
+++ b/engine/npctrade.asm
@@ -1,11 +1,3 @@
-; Trade dialogs
- const_def
- const TRADE_INTRO
- const TRADE_CANCEL
- const TRADE_WRONG
- const TRADE_COMPLETE
- const TRADE_AFTER
-
NPCTrade:: ; fcba8
ld a, e
ld [wJumptableIndex], a
@@ -83,9 +75,9 @@
ld e, TRADE_GENDER
call GetTradeAttribute
ld a, [hl]
- and a
+ and a ; TRADE_EITHER_GENDER
jr z, .matching
- cp 1
+ cp TRADE_MALE_ONLY
jr z, .check_male
farcall GetGender
@@ -178,10 +170,10 @@
ld e, TRADE_DIALOG
call GetTradeAttribute
ld a, [hl]
- cp 3
- ld a, 1
+ cp TRADE_DIALOG_GIRL
+ ld a, CAUGHT_BY_GIRL
jr c, .okay
- ld a, 2
+ ld a, CAUGHT_BY_BOY
.okay
ld [wOTTrademonCaughtData], a
@@ -400,7 +392,7 @@
and a
ret z
- cp 1
+ cp TRADE_MALE_ONLY
ld a, "♂"
jr z, .done
ld a, "♀"
@@ -433,31 +425,28 @@
; fcf53
TradeTexts: ; fcf53
-; intro
+; entries correspond to TRADE_* × TRADE_DIALOG_* constants
+; TRADE_INTRO
dw TradeIntroText1
dw TradeIntroText2
dw TradeIntroText3
dw TradeIntroText4
-
-; cancel
+; TRADE_CANCEL
dw TradeCancelText1
dw TradeCancelText2
dw TradeCancelText3
dw TradeCancelText4
-
-; wrong mon
+; TRADE_WRONG
dw TradeWrongText1
dw TradeWrongText2
dw TradeWrongText3
dw TradeWrongText4
-
-; completed
+; TRADE_COMPLETE
dw TradeCompleteText1
dw TradeCompleteText2
dw TradeCompleteText3
dw TradeCompleteText4
-
-; after
+; TRADE_AFTER
dw TradeAfterText1
dw TradeAfterText2
dw TradeAfterText3
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -1,3 +1,17 @@
+; Pack.Jumptable and BattlePack.Jumptable indexes
+ const_def
+ const PACKSTATE_INITGFX ; 0
+ const PACKSTATE_INITITEMSPOCKET ; 1
+ const PACKSTATE_ITEMSPOCKETMENU ; 2
+ const PACKSTATE_INITBALLSPOCKET ; 3
+ const PACKSTATE_BALLSPOCKETMENU ; 4
+ const PACKSTATE_INITKEYITEMSPOCKET ; 5
+ const PACKSTATE_KEYITEMSPOCKETMENU ; 6
+ const PACKSTATE_INITTMHMPOCKET ; 7
+ const PACKSTATE_TMHMPOCKETMENU ; 8
+ const PACKSTATE_QUITNOSCRIPT ; 9
+ const PACKSTATE_QUITRUNSCRIPT ; 10
+
Pack: ; 10000
ld hl, Options
set NO_TEXT_SCROLL, [hl]
@@ -28,6 +42,7 @@
; 10030
.Jumptable: ; 10030 (4:4030)
+; entries correspond to PACKSTATE_* constants
dw .InitGFX ; 0
dw .InitItemsPocket ; 1
dw .ItemsPocketMenu ; 2
@@ -50,7 +65,7 @@
ret
.InitItemsPocket: ; 10056 (4:4056)
- xor a
+ xor a ; ITEM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -70,8 +85,8 @@
ld [wItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wItemsPocketCursor], a
- ld b, $7
- ld c, $3
+ ld b, PACKSTATE_INITTMHMPOCKET ; left
+ ld c, PACKSTATE_INITBALLSPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
@@ -78,7 +93,7 @@
ret
.InitKeyItemsPocket: ; 10094 (4:4094)
- ld a, $2
+ ld a, KEY_ITEM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -98,8 +113,8 @@
ld [wKeyItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wKeyItemsPocketCursor], a
- ld b, $3
- ld c, $7
+ ld b, PACKSTATE_INITBALLSPOCKET ; left
+ ld c, PACKSTATE_INITTMHMPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
@@ -106,7 +121,7 @@
ret
.InitTMHMPocket: ; 100d3 (4:40d3)
- ld a, $3
+ ld a, TM_HM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -118,8 +133,8 @@
.TMHMPocketMenu: ; 100e8 (4:40e8)
farcall TMHMPocket
- ld b, $5
- ld c, $1
+ ld b, PACKSTATE_INITKEYITEMSPOCKET ; left
+ ld c, PACKSTATE_INITITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
farcall _CheckTossableItem
@@ -162,7 +177,6 @@
; 0x10137
.Jumptable1: ; 10137
-
dw .UseItem
dw QuitItemSubmenu
@@ -211,7 +225,7 @@
ret
.InitBallsPocket: ; 10186 (4:4186)
- ld a, $1
+ ld a, BALL_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -231,8 +245,8 @@
ld [wBallsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wBallsPocketCursor], a
- ld b, $1
- ld c, $5
+ ld b, PACKSTATE_INITITEMSPOCKET ; left
+ ld c, PACKSTATE_INITKEYITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
@@ -327,7 +341,6 @@
; 0x1026a
Jumptable_UseGiveTossRegisterQuit: ; 1026a
-
dw UseItem
dw GiveItem
dw TossMenu
@@ -353,7 +366,6 @@
; 0x10291
Jumptable_UseGiveTossQuit: ; 10291
-
dw UseItem
dw GiveItem
dw TossMenu
@@ -376,7 +388,6 @@
; 0x102ac
Jumptable_UseQuit: ; 102ac
-
dw UseItem
dw QuitItemSubmenu
; 102b0
@@ -398,7 +409,6 @@
; 0x102c7
Jumptable_UseRegisterQuit: ; 102c7
-
dw UseItem
dw RegisterItem
dw QuitItemSubmenu
@@ -422,7 +432,6 @@
; 0x102ea
Jumptable_GiveTossRegisterQuit: ; 102ea
-
dw GiveItem
dw TossMenu
dw RegisterItem
@@ -446,7 +455,6 @@
; 0x1030b
Jumptable_GiveTossQuit: ; 1030b
-
dw GiveItem
dw TossMenu
dw QuitItemSubmenu
@@ -462,14 +470,14 @@
; 1031f
.dw ; 1031f (4:431f)
-
+; entries correspond to ITEMMENU_* constants
+ dw .Oak ; ITEMMENU_NOUSE
dw .Oak
dw .Oak
dw .Oak
- dw .Oak
- dw .Current
- dw .Party
- dw .Field
+ dw .Current ; ITEMMENU_CURRENT
+ dw .Party ; ITEMMENU_PARTY
+ dw .Field ; ITEMMENU_CLOSE
; 1035c
.Oak: ; 1032d (4:432d)
@@ -503,7 +511,7 @@
ld a, [wItemEffectSucceeded]
and a
jr z, .Oak
- ld a, $a
+ ld a, PACKSTATE_QUITRUNSCRIPT
ld [wJumptableIndex], a
ret
; 10364 (4:4364)
@@ -537,11 +545,11 @@
ResetPocketCursorPositions: ; 1039d
; unreferenced
ld a, [wCurrPocket]
- and a
+ and a ; ITEM_POCKET
jr z, .items
- dec a
+ dec a ; BALL_POCKET
jr z, .balls
- dec a
+ dec a ; KEY_ITEM_POCKET
jr z, .key
ret
@@ -693,6 +701,7 @@
; 104c3
.Jumptable: ; 104c3 (4:44c3)
+; entries correspond to PACKSTATE_* constants
dw .InitGFX ; 0
dw .InitItemsPocket ; 1
dw .ItemsPocketMenu ; 2
@@ -715,7 +724,7 @@
ret
.InitItemsPocket: ; 104e9 (4:44e9)
- xor a
+ xor a ; ITEM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -735,8 +744,8 @@
ld [wItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wItemsPocketCursor], a
- ld b, $7
- ld c, $3
+ ld b, PACKSTATE_INITTMHMPOCKET ; left
+ ld c, PACKSTATE_INITBALLSPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
@@ -743,7 +752,7 @@
ret
.InitKeyItemsPocket: ; 10527 (4:4527)
- ld a, $2
+ ld a, KEY_ITEM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -763,8 +772,8 @@
ld [wKeyItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wKeyItemsPocketCursor], a
- ld b, $3
- ld c, $7
+ ld b, PACKSTATE_INITBALLSPOCKET ; left
+ ld c, PACKSTATE_INITTMHMPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
@@ -771,7 +780,7 @@
ret
.InitTMHMPocket: ; 10566 (4:4566)
- ld a, $3
+ ld a, TM_HM_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -785,8 +794,8 @@
.TMHMPocketMenu: ; 10581 (4:4581)
farcall TMHMPocket
- ld b, $5
- ld c, $1
+ ld b, PACKSTATE_INITKEYITEMSPOCKET ; left
+ ld c, PACKSTATE_INITITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
xor a
@@ -794,7 +803,7 @@
ret
.InitBallsPocket: ; 10594 (4:4594)
- ld a, $1
+ ld a, BALL_POCKET
ld [wCurrPocket], a
call ClearPocketList
call DrawPocketName
@@ -814,8 +823,8 @@
ld [wBallsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wBallsPocketCursor], a
- ld b, $1
- ld c, $5
+ ld b, PACKSTATE_INITITEMSPOCKET ; left
+ ld c, PACKSTATE_INITKEYITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
@@ -893,13 +902,14 @@
ret
.ItemFunctionJumptable: ; 10637 (4:4637)
+; entries correspond to ITEMMENU_* constants
+ dw .Oak ; ITEMMENU_NOUSE
dw .Oak
dw .Oak
dw .Oak
- dw .Oak
- dw .Unused
- dw .BattleField
- dw .BattleOnly
+ dw .Unused ; ITEMMENU_CURRENT
+ dw .BattleField ; ITEMMENU_PARTY
+ dw .BattleOnly ; ITEMMENU_CLOSE
.Oak: ; 10645 (4:4645)
ld hl, Text_ThisIsntTheTime
@@ -937,7 +947,7 @@
cp $2
jr z, .didnt_use_item
.quit_run_script ; 1067e (4:467e)
- ld a, 10
+ ld a, PACKSTATE_QUITRUNSCRIPT
ld [wJumptableIndex], a
ret
@@ -954,7 +964,7 @@
xor a
ld [wJumptableIndex], a
ld a, [wLastPocket]
- and $3
+ maskbits NUM_POCKETS +- 1
ld [wCurrPocket], a
inc a
add a
@@ -997,6 +1007,7 @@
; 106d1
.Jumptable: ; 106d1 (4:46d1)
+; entries correspond to *_POCKET constants
dw .ItemsPocket
dw .BallsPocket
dw .KeyItemsPocket
@@ -1003,7 +1014,7 @@
dw .TMHMPocket
.ItemsPocket: ; 106d9 (4:46d9)
- xor a
+ xor a ; ITEM_POCKET
call InitPocket
ld hl, PC_Mart_ItemsPocketMenuDataHeader
call CopyMenuDataHeader
@@ -1019,7 +1030,7 @@
ret
.KeyItemsPocket: ; 106ff (4:46ff)
- ld a, 2
+ ld a, KEY_ITEM_POCKET
call InitPocket
ld hl, PC_Mart_KeyItemsPocketMenuDataHeader
call CopyMenuDataHeader
@@ -1035,7 +1046,7 @@
ret
.TMHMPocket: ; 10726 (4:4726)
- ld a, 3
+ ld a, TM_HM_POCKET
call InitPocket
call WaitBGMap_DrawPackGFX
farcall TMHMPocket
@@ -1044,7 +1055,7 @@
ret
.BallsPocket: ; 1073b (4:473b)
- ld a, 1
+ ld a, BALL_POCKET
call InitPocket
ld hl, PC_Mart_BallsPocketMenuDataHeader
call CopyMenuDataHeader
@@ -1098,7 +1109,7 @@
.d_left
ld a, [wJumptableIndex]
dec a
- and $3
+ maskbits NUM_POCKETS +- 1
ld [wJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
@@ -1110,7 +1121,7 @@
.d_right
ld a, [wJumptableIndex]
inc a
- and $3
+ maskbits NUM_POCKETS +- 1
ld [wJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
@@ -1144,7 +1155,7 @@
; 107e1
.dw ; 107e1 (4:47e1)
-
+; entries correspond to *_POCKET constants
dw .Items
dw .Balls
dw .KeyItems
@@ -1151,7 +1162,7 @@
dw .TMHM
.Items: ; 107e9 (4:47e9)
- xor a
+ xor a ; ITEM_POCKET
ld hl, .ItemsMenuDataHeader
jr .DisplayPocket
@@ -1175,7 +1186,7 @@
; 10807
.KeyItems: ; 10807 (4:4807)
- ld a, 2
+ ld a, KEY_ITEM_POCKET
ld hl, .KeyItemsMenuDataHeader
jr .DisplayPocket
@@ -1199,7 +1210,7 @@
; 10826
.TMHM: ; 10826 (4:4826)
- ld a, 3
+ ld a, TM_HM_POCKET
call InitPocket
call WaitBGMap_DrawPackGFX
farcall TMHMPocket
@@ -1208,7 +1219,7 @@
ret
.Balls: ; 1083b (4:483b)
- ld a, 1
+ ld a, BALL_POCKET
ld hl, .BallsMenuDataHeader
jr .DisplayPocket
@@ -1283,7 +1294,7 @@
call WaitBGMap
DrawPackGFX: ; 1089d
ld a, [wCurrPocket]
- and $3
+ maskbits NUM_POCKETS +- 1
ld e, a
ld d, $0
ld a, [BattleType]
@@ -1310,10 +1321,10 @@
; 108cc
PackGFXPointers: ; 108cc
- dw PackGFX + (15 tiles) * 1
- dw PackGFX + (15 tiles) * 3
- dw PackGFX + (15 tiles) * 0
- dw PackGFX + (15 tiles) * 2
+ dw PackGFX + (15 tiles) * 1 ; ITEM_POCKET
+ dw PackGFX + (15 tiles) * 3 ; BALL_POCKET
+ dw PackGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET
+ dw PackGFX + (15 tiles) * 2 ; TM_HM_POCKET
; 108d4
Pack_InterpretJoypad: ; 108d4 (4:48d4)
@@ -1344,7 +1355,7 @@
ret
.b_button
- ld a, 9
+ ld a, PACKSTATE_QUITNOSCRIPT
ld [wJumptableIndex], a
scf
ret
@@ -1489,15 +1500,19 @@
; 109e1
.tilemap ; 109e1
+; ITEM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $06, $07, $08, $09, $0a ; Items
db $02, $05, $05, $05, $03 ; bottom border
+; BALL_POCKET
db $00, $04, $04, $04, $01 ; top border
db $15, $16, $17, $18, $19 ; Balls
db $02, $05, $05, $05, $03 ; bottom border
+; KEY_ITEM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $0b, $0c, $0d, $0e, $0f ; Key Items
db $02, $05, $05, $05, $03 ; bottom border
+; TM_HM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $10, $11, $12, $13, $14 ; TM/HM
db $02, $05, $05, $05, $03 ; bottom border
--- a/engine/player_movement.asm
+++ b/engine/player_movement.asm
@@ -140,7 +140,7 @@
.water
ld a, c
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld c, a
ld b, 0
ld hl, .water_table
@@ -244,7 +244,7 @@
ld a, [PlayerDirection]
rrca
rrca
- and 3
+ maskbits NUM_DIRECTIONS +- 1
cp e
jr z, .not_turning
@@ -430,7 +430,7 @@
ld a, [PlayerDirection]
rrca
rrca
- and 3
+ maskbits NUM_DIRECTIONS +- 1
cp e
jr nz, .not_warp
call WarpCheck
@@ -559,7 +559,7 @@
cp 0
ret z
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld e, a
ld d, 0
ld hl, .forced_dpad
--- a/engine/player_object.asm
+++ b/engine/player_object.asm
@@ -589,7 +589,7 @@
ld a, [PlayerDirection]
srl a
srl a
- and 3
+ maskbits NUM_DIRECTIONS +- 1
ld e, a
ld d, 0
ld hl, .movement_data
--- a/engine/player_step.asm
+++ b/engine/player_step.asm
@@ -154,7 +154,7 @@
jr nc, .not_overflowed
ld a, [wBGMapAnchor + 1]
inc a
- and $3
+ and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_overflowed
@@ -185,7 +185,7 @@
jr nc, .not_underflowed
ld a, [wBGMapAnchor + 1]
dec a
- and $3
+ and %11
or HIGH(vBGMap0)
ld [wBGMapAnchor + 1], a
.not_underflowed
--- a/engine/pokedex.asm
+++ b/engine/pokedex.asm
@@ -1,3 +1,4 @@
+; Pokedex_RunJumptable.Jumptable indexes
const_def
const DEXSTATE_MAIN_SCR
const DEXSTATE_UPDATE_MAIN_SCR
@@ -185,6 +186,7 @@
jp hl
.Jumptable: ; 40115 (10:4115)
+; entries correspond to DEXSTATE_* constants
dw Pokedex_InitMainScreen
dw Pokedex_UpdateMainScreen
dw Pokedex_InitDexEntryScreen
@@ -739,7 +741,7 @@
farcall DrawPokedexSearchResultsWindow
call Pokedex_PlaceSearchResultsTypeStrings
call Pokedex_UpdateSearchResultsCursorOAM
- ld a, $ff
+ ld a, -1
ld [CurPartySpecies], a
ld a, SCGB_POKEDEX
call Pokedex_GetSGBLayout
@@ -1123,13 +1125,14 @@
ret
String_SEEN: ; 407e1
- db "SEEN", $ff
+ db "SEEN", -1
String_OWN: ; 407e6
- db "OWN", $ff
+ db "OWN", -1
String_SELECT_OPTION: ; 407ea
db $3b, $48, $49, $4a, $44, $45, $46, $47 ; SELECT > OPTION
+ ; fallthrough
String_START_SEARCH: ; 407f2
- db $3c, $3b, $41, $42, $43, $4b, $4c, $4d, $4e, $3c, $ff ; START > SEARCH
+ db $3c, $3b, $41, $42, $43, $4b, $4c, $4d, $4e, $3c, -1 ; START > SEARCH
Pokedex_DrawDexEntryScreenBG: ; 407fd
call Pokedex_FillBackgroundColor2
@@ -1164,13 +1167,13 @@
ret
.Unused: ; 4084f
- db $5c, $5d, $ff ; No.
+ db $5c, $5d, -1 ; No.
.Height: ; 40852
- db "HT ?", $5e, "??", $5f, $ff ; HT ?'??"
+ db "HT ?", $5e, "??", $5f, -1 ; HT ?'??"
.Weight: ; 4085c
- db "WT ???lb", $ff ; WT ???lb
+ db "WT ???lb", -1 ; WT ???lb
.MenuItems: ; 40867
- db $3b, " PAGE AREA CRY PRNT", $ff
+ db $3b, " PAGE AREA CRY PRNT", -1
Pokedex_DrawOptionScreenBG: ; 4087c (10:487c)
call Pokedex_FillBackgroundColor2
@@ -1195,7 +1198,7 @@
ret
.Title: ; 408b2
- db $3b, " OPTION ", $3c, $ff
+ db $3b, " OPTION ", $3c, -1
.Modes: ; 408bd
db "NEW #DEX MODE"
@@ -1229,10 +1232,10 @@
ret
.Title: ; 4092a
- db $3b, " SEARCH ", $3c, $ff
+ db $3b, " SEARCH ", $3c, -1
.TypeLeftRightArrows: ; 40935
- db $3d, " ", $3e, $ff
+ db $3d, " ", $3e, -1
.Types: ; 40940
db "TYPE1"
--- a/engine/pokedex_2.asm
+++ b/engine/pokedex_2.asm
@@ -230,7 +230,7 @@
push de
rlca
rlca
- and $3
+ maskbits NUM_DEX_ENTRY_BANKS +- 1
ld hl, .PokedexEntryBanks
ld d, 0
ld e, a
@@ -241,12 +241,6 @@
ret
.PokedexEntryBanks: ; 44351
-
-GLOBAL PokedexEntries1
-GLOBAL PokedexEntries2
-GLOBAL PokedexEntries3
-GLOBAL PokedexEntries4
-
db BANK(PokedexEntries1)
db BANK(PokedexEntries2)
db BANK(PokedexEntries3)
--- a/engine/pokegear.asm
+++ b/engine/pokegear.asm
@@ -1,3 +1,27 @@
+; Pokégear cards
+ const_def
+ const POKEGEARCARD_CLOCK ; 0
+ const POKEGEARCARD_MAP ; 1
+ const POKEGEARCARD_PHONE ; 2
+ const POKEGEARCARD_RADIO ; 3
+NUM_POKEGEAR_CARDS EQU const_value
+
+; PokegearJumptable.Jumptable indexes
+ const_def
+ const POKEGEARSTATE_CLOCKINIT ; 0
+ const POKEGEARSTATE_CLOCKJOYPAD ; 1
+ const POKEGEARSTATE_MAPCHECKREGION ; 2
+ const POKEGEARSTATE_JOHTOMAPINIT ; 3
+ const POKEGEARSTATE_JOHTOMAPJOYPAD ; 4
+ const POKEGEARSTATE_KANTOMAPINIT ; 5
+ const POKEGEARSTATE_KANTOMAPJOYPAD ; 6
+ const POKEGEARSTATE_PHONEINIT ; 7
+ const POKEGEARSTATE_PHONEJOYPAD ; 8
+ const POKEGEARSTATE_MAKEPHONECALL ; 9
+ const POKEGEARSTATE_FINISHPHONECALL ; a
+ const POKEGEARSTATE_RADIOINIT ; b
+ const POKEGEARSTATE_RADIOJOYPAD ; c
+
PokeGear: ; 90b8d (24:4b8d)
ld hl, Options
ld a, [hl]
@@ -163,7 +187,10 @@
; 90d52 (24:4d52)
.XCoords: ; 90d52
- db $00, $10, $20, $30
+ db $00 ; POKEGEARCARD_CLOCK
+ db $10 ; POKEGEARCARD_MAP
+ db $20 ; POKEGEARCARD_PHONE
+ db $30 ; POKEGEARCARD_RADIO
; 90d56
TownMap_GetCurrentLandmark: ; 90d56
@@ -210,7 +237,7 @@
ret
Pokegear_InitJumptableIndices: ; 90d9e (24:4d9e)
- ld a, $0
+ ld a, POKEGEARSTATE_CLOCKINIT
ld [wJumptableIndex], a
xor a
ld [wcf64], a
@@ -224,7 +251,7 @@
ld a, $4f
call ByteFill
ld a, [wcf64]
- and $3
+ maskbits NUM_POKEGEAR_CARDS +- 1
add a
ld e, a
ld d, 0
@@ -260,6 +287,7 @@
xor a
.finish
ld [hWY], a
+ ; swap region maps
ld a, [wcf65]
and 1
xor 1
@@ -281,6 +309,7 @@
; 90e12 (24:4e12)
.Jumptable: ; 90e12
+; entries correspond to POKEGEARCARD_* constants
dw .Clock
dw .Map
dw .Phone
@@ -319,12 +348,12 @@
ld e, 1
.ok
farcall PokegearMap
- ld a, $7
+ ld a, $07
ld bc, $12
hlcoord 1, 2
call ByteFill
hlcoord 0, 2
- ld [hl], $6
+ ld [hl], $06
hlcoord 19, 2
ld [hl], $17
ld a, [wPokegearMapCursorLandmark]
@@ -382,13 +411,13 @@
call ByteFill
ld de, wPokegearFlags
ld a, [de]
- bit 0, a
+ bit 0, a ; ENGINE_MAP_CARD
call nz, .PlaceMapIcon
ld a, [de]
- bit 2, a
+ bit 2, a ; ENGINE_PHONE_CARD
call nz, .PlacePhoneIcon
ld a, [de]
- bit 1, a
+ bit 1, a ; ENGINE_RADIO_CARD
call nz, .PlaceRadioIcon
hlcoord 0, 0
ld a, $46
@@ -433,6 +462,7 @@
jp hl
.Jumptable: ; 90f13 (24:4f13)
+; entries correspond to POKEGEARSTATE_* constants
dw PokegearClock_Init
dw PokegearClock_Joypad
dw PokegearMap_CheckRegion
@@ -460,32 +490,32 @@
call .UpdateClock
ld hl, hJoyLast
ld a, [hl]
- and A_BUTTON + B_BUTTON + START + SELECT
+ and A_BUTTON | B_BUTTON | START | SELECT
jr nz, .quit
ld a, [hl]
and D_RIGHT
ret z
ld a, [wPokegearFlags]
- bit 0, a
+ bit 0, a ; ENGINE_MAP_CARD
jr z, .no_map_card
- ld c, $2
- ld b, $1
+ ld c, POKEGEARSTATE_MAPCHECKREGION
+ ld b, POKEGEARCARD_MAP
jr .done
.no_map_card
ld a, [wPokegearFlags]
- bit 2, a
+ bit 2, a ; ENGINE_PHONE_CARD
jr z, .no_phone_card
- ld c, $7
- ld b, $2
+ ld c, POKEGEARSTATE_PHONEINIT
+ ld b, POKEGEARCARD_PHONE
jr .done
.no_phone_card
ld a, [wPokegearFlags]
- bit 1, a
+ bit 1, a ; ENGINE_RADIO_CARD
ret z
- ld c, $b
- ld b, $3
+ ld c, POKEGEARSTATE_RADIOINIT
+ ld b, POKEGEARCARD_RADIO
.done
call Pokegear_SwitchPage
ret
@@ -535,12 +565,12 @@
cp KANTO_LANDMARK
jr nc, .kanto
.johto
- ld a, 3
+ ld a, POKEGEARSTATE_JOHTOMAPINIT
jr .done
ret
.kanto
- ld a, 5
+ ld a, POKEGEARSTATE_KANTOMAPINIT
.done
ld [wJumptableIndex], a
call ExitPokegearRadio_HandleMusic
@@ -583,23 +613,23 @@
.right
ld a, [wPokegearFlags]
- bit 2, a
+ bit 2, a ; ENGINE_PHONE_CARD
jr z, .no_phone
- ld c, $7
- ld b, $2
+ ld c, POKEGEARSTATE_PHONEINIT
+ ld b, POKEGEARCARD_PHONE
jr .done
.no_phone
ld a, [wPokegearFlags]
- bit 1, a
+ bit 1, a ; ENGINE_RADIO_CARD
ret z
- ld c, $b
- ld b, $3
+ ld c, POKEGEARSTATE_RADIOINIT
+ ld b, POKEGEARCARD_RADIO
jr .done
.left
- ld c, $0
- ld b, $0
+ ld c, POKEGEARSTATE_CLOCKINIT
+ ld b, POKEGEARCARD_CLOCK
.done
call Pokegear_SwitchPage
ret
@@ -657,7 +687,7 @@
depixel 0, 0
ld b, SPRITE_ANIM_INDEX_RED_WALK
ld a, [wPlayerGender]
- bit 0, a
+ bit 0, a ; ENGINE_PLAYER_IS_FEMALE
jr z, .got_gender
ld b, SPRITE_ANIM_INDEX_BLUE_WALK
.got_gender
@@ -688,7 +718,7 @@
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
- ld [hl], $4
+ ld [hl], $04
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_NULL
@@ -734,7 +764,7 @@
TownMap_GetKantoLandmarkLimits: ; 910e8
ld a, [wStatusFlags]
- bit 6, a
+ bit 6, a ; ENGINE_CREDITS_SKIP
jr z, .not_hof
ld d, ROUTE_28
ld e, PALLET_TOWN
@@ -754,7 +784,7 @@
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
- ld [hl], $8
+ ld [hl], $08
call _UpdateRadioStation
ld hl, wJumptableIndex
inc [hl]
@@ -780,23 +810,23 @@
.left
ld a, [wPokegearFlags]
- bit 2, a
+ bit 2, a ; ENGINE_PHONE_CARD
jr z, .no_phone
- ld c, $7
- ld b, $2
+ ld c, POKEGEARSTATE_PHONEINIT
+ ld b, POKEGEARCARD_PHONE
jr .switch_page
.no_phone
ld a, [wPokegearFlags]
- bit 0, a
+ bit 0, a ; ENGINE_MAP_CARD
jr z, .no_map
- ld c, $2
- ld b, $1
+ ld c, POKEGEARSTATE_MAPCHECKREGION
+ ld b, POKEGEARCARD_MAP
jr .switch_page
.no_map
- ld c, $0
- ld b, $0
+ ld c, POKEGEARSTATE_CLOCKINIT
+ ld b, POKEGEARCARD_CLOCK
.switch_page
call Pokegear_SwitchPage
ret
@@ -839,23 +869,23 @@
.left
ld a, [wPokegearFlags]
- bit 0, a
+ bit 0, a ; ENGINE_MAP_CARD
jr z, .no_map
- ld c, $2
- ld b, $1
+ ld c, POKEGEARSTATE_MAPCHECKREGION
+ ld b, POKEGEARCARD_MAP
jr .switch_page
.no_map
- ld c, $0
- ld b, $0
+ ld c, POKEGEARSTATE_CLOCKINIT
+ ld b, POKEGEARCARD_CLOCK
jr .switch_page
.right
ld a, [wPokegearFlags]
- bit 1, a
+ bit 1, a ; ENGINE_RADIO_CARD
ret z
- ld c, $b
- ld b, $3
+ ld c, POKEGEARSTATE_RADIOINIT
+ ld b, POKEGEARCARD_RADIO
.switch_page
call Pokegear_SwitchPage
ret
@@ -891,7 +921,7 @@
ret
.quit_submenu
- ld a, $8
+ ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ret
@@ -931,7 +961,7 @@
farcall Phone_NoSignal
ld hl, .OutOfServiceArea
call PrintText
- ld a, $8
+ ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ld hl, PokegearText_WhomToCall
call PrintText
@@ -958,7 +988,7 @@
and A_BUTTON | B_BUTTON
ret z
farcall HangUp
- ld a, $8
+ ld a, POKEGEARSTATE_PHONEJOYPAD
ld [wJumptableIndex], a
ld hl, PokegearText_WhomToCall
call PrintText
@@ -993,7 +1023,7 @@
.down
ld hl, wPokegearPhoneCursorPosition
ld a, [hl]
- cp $3
+ cp 3
jr nc, .scroll_page_down
inc [hl]
jr .done_joypad_same_page
@@ -1001,7 +1031,7 @@
.scroll_page_down
ld hl, wPokegearPhoneScrollPosition
ld a, [hl]
- cp $6
+ cp 6
ret nc
inc [hl]
jr .done_joypad_update_page
@@ -1075,7 +1105,7 @@
ld a, [wPokegearPhoneLoadNameBuffer]
inc a
ld [wPokegearPhoneLoadNameBuffer], a
- cp $4
+ cp 4
jr c, .loop
call PokegearPhone_UpdateCursor
ret
@@ -1337,9 +1367,9 @@
ExitPokegearRadio_HandleMusic: ; 91492
ld a, [wPokegearRadioMusicPlaying]
- cp $fe
+ cp RESTART_MAP_MUSIC
jr z, .restart_map_music
- cp $ff
+ cp ENTER_MAP_MUSIC
call z, EnterMapMusic
xor a
ld [wPokegearRadioMusicPlaying], a
@@ -1364,11 +1394,11 @@
Pokegear_LoadTilemapRLE: ; 914bb (24:54bb)
; Format: repeat count, tile ID
- ; Terminated with $FF
+ ; Terminated with -1
hlcoord 0, 0
.loop
ld a, [de]
- cp $ff
+ cp -1
ret z
ld b, a
inc de
@@ -1560,7 +1590,7 @@
call .InJohto
jr c, .NoSignal
ld a, [wPokegearFlags]
- bit 3, a
+ bit 3, a ; ENGINE_EXPN_CARD
jr z, .NoSignal
jp LoadStation_PlacesAndPeople
@@ -1568,7 +1598,7 @@
call .InJohto
jr c, .NoSignal
ld a, [wPokegearFlags]
- bit 3, a
+ bit 3, a ; ENGINE_EXPN_CARD
jr z, .NoSignal
jp LoadStation_LetsAllSing
@@ -1576,7 +1606,7 @@
call .InJohto
jr c, .NoSignal
ld a, [wPokegearFlags]
- bit 3, a
+ bit 3, a ; ENGINE_EXPN_CARD
jr z, .NoSignal
jp LoadStation_PokeFluteRadio
@@ -1583,7 +1613,7 @@
.EvolutionRadio:
; This station airs in the Lake of Rage area when Rocket are still in Mahogany.
ld a, [wStatusFlags]
- bit 4, a
+ bit 4, a ; ENGINE_ROCKET_SIGNAL_ON_CH20
jr z, .NoSignal
ld a, [wPokegearMapPlayerIconLandmark]
cp MAHOGANY_TOWN
@@ -1669,7 +1699,7 @@
call Radio_BackUpFarCallParams
ld de, NotBuenasPasswordName
ld a, [wStatusFlags2]
- bit 0, a
+ bit 0, a ; ENGINE_ROCKETS_IN_RADIO_TOWER
ret z
ld de, BuenasPasswordName
ret
@@ -1768,7 +1798,7 @@
RadioMusicRestartPokemonChannel: ; 91868 (24:5868)
push de
- ld a, $fe
+ ld a, RESTART_MAP_MUSIC
ld [wPokegearRadioMusicPlaying], a
ld de, MUSIC_NONE
call PlayMusic
@@ -1799,7 +1829,7 @@
NoRadioMusic: ; 9189d (24:589d)
ld de, MUSIC_NONE
call PlayMusic
- ld a, $ff
+ ld a, ENTER_MAP_MUSIC
ld [wPokegearRadioMusicPlaying], a
ret
@@ -1810,7 +1840,7 @@
lb bc, 3, 18
call ClearBox
hlcoord 0, 12
- ld bc, $412
+ lb bc, 4, 18
call TextBox
ret
@@ -1966,19 +1996,19 @@
ld a, [wTownMapPlayerIconLandmark]
cp KANTO_LANDMARK
jr nc, .kanto2
- ld e, $0
+ ld e, JOHTO_REGION
jr .okay_tilemap
.kanto2
- ld e, $1
+ ld e, KANTO_REGION
.okay_tilemap
farcall PokegearMap
- ld a, $7
+ ld a, $07
ld bc, 6
hlcoord 1, 0
call ByteFill
hlcoord 0, 0
- ld [hl], $6
+ ld [hl], $06
hlcoord 7, 0
ld [hl], $17
hlcoord 7, 1
@@ -1985,7 +2015,7 @@
ld [hl], $16
hlcoord 7, 2
ld [hl], $26
- ld a, $7
+ ld a, $07
ld bc, NAME_LENGTH
hlcoord 8, 2
call ByteFill
@@ -2001,7 +2031,7 @@
ld hl, Options
ld a, [hl]
push af
- set 4, [hl]
+ set NO_TEXT_SCROLL, [hl]
call .PlayStation
ld c, 100
call DelayFrames
@@ -2031,10 +2061,10 @@
; 91a87
.PlayStation: ; 91a87
- ld a, -1
- ld [EnemyTurnsTaken], a
+ ld a, ENTER_MAP_MUSIC
+ ld [wPokegearRadioMusicPlaying], a
ld hl, .StationPointers
- ld d, $0
+ ld d, 0
add hl, de
add hl, de
ld a, [hli]
@@ -2063,6 +2093,7 @@
; 91ab9
.StationPointers: ; 91ab9
+; entries correspond to radio station constants
dw .OakOrPnP
dw LoadStation_OaksPokemonTalk
dw LoadStation_PokedexShow
@@ -2286,7 +2317,7 @@
GetMapCursorCoordinates: ; 91c17
ld a, [wTownMapPlayerIconLandmark]
ld l, a
- ld h, $0
+ ld h, 0
add hl, hl
ld de, Flypoints
add hl, de
@@ -2296,10 +2327,10 @@
ld c, a
ld a, [wTownMapCursorCoordinates + 1]
ld b, a
- ld hl, $4
+ ld hl, 4
add hl, bc
ld [hl], e
- ld hl, $5
+ ld hl, 5
add hl, bc
ld [hl], d
ret
@@ -2477,7 +2508,7 @@
call SetPalettes
xor a
ld [hBGMapMode], a
- xor a ; Johto
+ xor a ; JOHTO_REGION
call .GetAndPlaceNest
.loop
call JoyTextDelay
@@ -2524,13 +2555,13 @@
call ClearSprites
ld a, $90
ld [hWY], a
- xor a ; Johto
+ xor a ; JOHTO_REGION
call .GetAndPlaceNest
ret
.right
ld a, [wStatusFlags]
- bit 6, a ; hall of fame
+ bit 6, a ; ENGINE_CREDITS_SKIP
ret z
ld a, [hWY]
and a
@@ -2538,7 +2569,7 @@
call ClearSprites
xor a
ld [hWY], a
- ld a, 1 ; Kanto
+ ld a, KANTO_REGION
call .GetAndPlaceNest
ret
@@ -2791,12 +2822,11 @@
; Current tile
ld a, [hli]
push hl
-; HP/borders use palette 0
+; The palette map covers tiles $00 to $5f; $60 and above use palette 0
cp $60
jr nc, .pal0
-; The palette data is condensed to nybbles,
-; least-significant first.
+; The palette data is condensed to nybbles, least-significant first.
ld hl, .PalMap
srl a
jr c, .odd
@@ -2807,7 +2837,7 @@
adc 0
ld h, a
ld a, [hl]
- and %111
+ and PALETTE_MASK
jr .update
.odd
@@ -2819,7 +2849,7 @@
ld h, a
ld a, [hl]
swap a
- and %111
+ and PALETTE_MASK
jr .update
.pal0
@@ -2839,7 +2869,7 @@
; 91f7b
TownMapMon: ; 91f7b
-; Draw the FlyMon icon at town map location in
+; Draw the FlyMon icon at town map location
; Get FlyMon species
ld a, [CurPartyMon]
@@ -2850,7 +2880,7 @@
ld a, [hl]
ld [wd265], a
; Get FlyMon icon
- ld e, 8 ; starting tile in VRAM
+ ld e, $08 ; starting tile in VRAM
farcall GetSpeciesIcon
; Animation/palette
depixel 0, 0
@@ -2858,7 +2888,7 @@
call _InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
- ld [hl], $8
+ ld [hl], $08
ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
add hl, bc
ld [hl], SPRITE_ANIM_SEQ_NULL
--- a/engine/radio.asm
+++ b/engine/radio.asm
@@ -247,7 +247,7 @@
; Generate a number, either 0, 1, or 2, to choose a time of day.
.loop2
call Random
- and $3
+ maskbits NUM_DAYTIMES +- 1
cp DARKNESS_F
jr z, .loop2
@@ -692,8 +692,8 @@
dec a
rlca
rlca
- and 3
- ld hl, .pokedexbanks
+ maskbits NUM_DEX_ENTRY_BANKS +- 1
+ ld hl, .PokedexEntryBanks
ld d, 0
ld e, a
add hl, de
@@ -702,7 +702,7 @@
pop hl
ret
-.pokedexbanks
+.PokedexEntryBanks
db BANK(PokedexEntries1)
db BANK(PokedexEntries2)
db BANK(PokedexEntries3)
--- a/engine/routines/drawkrispackgfx.asm
+++ b/engine/routines/drawkrispackgfx.asm
@@ -11,10 +11,10 @@
ret
PackFGFXPointers: ; 48e93
- dw PackFGFX + (15 tiles) * 1
- dw PackFGFX + (15 tiles) * 3
- dw PackFGFX + (15 tiles) * 0
- dw PackFGFX + (15 tiles) * 2
+ dw PackFGFX + (15 tiles) * 1 ; ITEM_POCKET
+ dw PackFGFX + (15 tiles) * 3 ; BALL_POCKET
+ dw PackFGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET
+ dw PackFGFX + (15 tiles) * 2 ; TM_HM_POCKET
PackFGFX: ; 48e9b
INCBIN "gfx/pack/pack_f.2bpp"
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -614,7 +614,7 @@
ld a, [wItemAttributeParamBuffer]
dec a
ld hl, .Pockets
- and 3
+ maskbits NUM_POCKETS +- 1
add a
ld e, a
ld d, 0
@@ -2474,7 +2474,7 @@
; parameters: facing, map_group, map_id, x, y
call GetScriptByte
- and $3
+ maskbits NUM_DIRECTIONS +- 1
ld c, a
ld a, [wPlayerSpriteSetupFlags]
set 5, a
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -1,3 +1,9 @@
+const_value set 1
+ const PINK_PAGE ; 1
+ const GREEN_PAGE ; 2
+ const BLUE_PAGE ; 3
+NUM_STAT_PAGES EQU const_value +- 1
+
BattleStatsScreenInit: ; 4dc7b (13:5c7b)
ld a, [wLinkMode]
cp LINK_MOBILE
@@ -58,12 +64,12 @@
; stupid interns
ld [wcf64], a
ld a, [wcf64]
- and $fc
- or $1
+ and %11111100
+ or 1
ld [wcf64], a
.loop ; 4dce3
ld a, [wJumptableIndex]
- and $7f
+ and $ff ^ (1 << 7)
ld hl, StatsScreenPointerTable
rst JumpTable
call StatsScreen_WaitAnim ; check for keys?
@@ -79,13 +85,13 @@
; stupid interns
ld [wcf64], a
ld a, [wcf64]
- and $fc
- or $1
+ and %11111100
+ or 1
ld [wcf64], a
.loop
farcall Mobile_SetOverworldDelay
ld a, [wJumptableIndex]
- and $7f
+ and $ff ^ (1 << 7)
ld hl, StatsScreenPointerTable
rst JumpTable
call StatsScreen_WaitAnim
@@ -277,7 +283,7 @@
StatsScreen_JoypadAction: ; 4de54 (13:5e54)
push af
ld a, [wcf64]
- and $3
+ maskbits NUM_STAT_PAGES +- 1
ld c, a
pop af
bit B_BUTTON_F, a
@@ -335,20 +341,20 @@
.a_button
ld a, c
- cp $3
+ cp BLUE_PAGE ; last page
jr z, .b_button
.d_right
inc c
- ld a, $3
+ ld a, BLUE_PAGE ; last page
cp c
jr nc, .set_page
- ld c, $1
+ ld c, PINK_PAGE ; first page
jr .set_page
.d_left
dec c
jr nz, .set_page
- ld c, $3
+ ld c, BLUE_PAGE ; last page
jr .set_page
.done
@@ -507,7 +513,7 @@
.ClearBox: ; 4dfda (13:5fda)
ld a, [wcf64]
- and $3
+ maskbits NUM_STAT_PAGES +- 1
ld c, a
call StatsScreen_LoadPageIndicators
hlcoord 0, 8
@@ -517,7 +523,7 @@
.LoadPals: ; 4dfed (13:5fed)
ld a, [wcf64]
- and $3
+ maskbits NUM_STAT_PAGES +- 1
ld c, a
farcall LoadStatsScreenPals
call DelayFrame
@@ -527,7 +533,7 @@
.PageTilemap: ; 4e002 (13:6002)
ld a, [wcf64]
- and $3
+ maskbits NUM_STAT_PAGES +- 1
dec a
ld hl, .Jumptable
rst JumpTable
@@ -534,6 +540,7 @@
ret
.Jumptable: ; 4e00d (13:600d)
+; entries correspond to *_PAGE constants
dw .PinkPage
dw .GreenPage
dw .BluePage
@@ -1089,13 +1096,13 @@
ld a, $36
call .load_square
ld a, c
- cp $2
+ cp GREEN_PAGE
ld a, $3a
- hlcoord 13, 5
+ hlcoord 13, 5 ; PINK_PAGE (< GREEN_PAGE)
jr c, .load_square
- hlcoord 15, 5
+ hlcoord 15, 5 ; GREEN_PAGE (= GREEN_PAGE)
jr z, .load_square
- hlcoord 17, 5
+ hlcoord 17, 5 ; BLUE_PAGE (> GREEN_PAGE)
.load_square ; 4e4f7 (13:64f7)
push bc
ld [hli], a
--- a/engine/time.asm
+++ b/engine/time.asm
@@ -133,7 +133,7 @@
Special_SampleKenjiBreakCountdown: ; 11485
; Generate a random number between 3 and 6
call Random
- and 3
+ and %11
add 3
ld [wKenjiBreakTimer], a
ret
@@ -140,9 +140,9 @@
; 11490
StartBugContestTimer: ; 11490
- ld a, 20
+ ld a, BUG_CONTEST_MINUTES
ld [wBugContestMinsRemaining], a
- ld a, 0
+ ld a, BUG_CONTEST_SECONDS
ld [wBugContestSecsRemaining], a
call UpdateTime
ld hl, wBugContestStartTime
@@ -252,7 +252,7 @@
ld a, FRIDAY
sub c
jr z, .friday_saturday
- jr nc, .earlier ; should've done "ret nc"
+ jr nc, .earlier ; could have done "ret nc"
.friday_saturday
add 7
--- a/engine/trade_animation.asm
+++ b/engine/trade_animation.asm
@@ -1,3 +1,14 @@
+TRADEANIM_RIGHT_ARROW EQU $ed
+TRADEANIM_LEFT_ARROW EQU $ee
+
+; TradeAnim_TubeAnimJumptable.Jumptable indexes
+ const_def
+ const TRADEANIMSTATE_0 ; 0
+ const TRADEANIMSTATE_1 ; 1
+ const TRADEANIMSTATE_2 ; 2
+ const TRADEANIMSTATE_3 ; 3
+TRADEANIMJUMPTABLE_LENGTH EQU const_value
+
TradeAnimation: ; 28f24
xor a
ld [wcf66], a
@@ -165,13 +176,13 @@
ld de, vTiles2 tile $31
call Decompress
ld hl, TradeArrowGFX
- ld de, vTiles1 tile $6d
- ld bc, $10
+ ld de, vTiles0 tile TRADEANIM_RIGHT_ARROW
+ ld bc, 1 tiles
ld a, BANK(TradeArrowGFX)
call FarCopyBytes
- ld hl, TradeArrowGFX + $10
- ld de, vTiles1 tile $6e
- ld bc, $10
+ ld hl, TradeArrowGFX + 1 tiles
+ ld de, vTiles0 tile TRADEANIM_LEFT_ARROW
+ ld bc, 1 tiles
ld a, BANK(TradeArrowGFX)
call FarCopyBytes
xor a
@@ -317,7 +328,7 @@
; 29129
TradeAnim_TubeToOT1: ; 29129
- ld a, $ed ; >>>>>>>>
+ ld a, TRADEANIM_RIGHT_ARROW
call TradeAnim_PlaceTrademonStatsOnTubeAnim
ld a, [wLinkTradeSendmonSpecies]
ld [wd265], a
@@ -327,11 +338,11 @@
jr TradeAnim_InitTubeAnim
TradeAnim_TubeToPlayer1: ; 2913c
- ld a, $ee ; <<<<<<<<
+ ld a, TRADEANIM_LEFT_ARROW
call TradeAnim_PlaceTrademonStatsOnTubeAnim
ld a, [wLinkTradeGetmonSpecies]
ld [wd265], a
- ld a, $2
+ ld a, TRADEANIMSTATE_2
depixel 9, 18, 4, 4
ld b, $4
TradeAnim_InitTubeAnim: ; 2914e
@@ -400,7 +411,7 @@
ld [hSCX], a
cp $50
ret nz
- ld a, $1
+ ld a, TRADEANIMSTATE_1
call TradeAnim_TubeAnimJumptable
call TradeAnim_IncrementJumptableIndex
ret
@@ -414,7 +425,7 @@
ld [hSCX], a
cp $a0
ret nz
- ld a, $2
+ ld a, TRADEANIMSTATE_2
call TradeAnim_TubeAnimJumptable
call TradeAnim_IncrementJumptableIndex
ret
@@ -440,7 +451,7 @@
ld [hSCX], a
cp $b0
ret nz
- ld a, $1
+ ld a, TRADEANIMSTATE_1
call TradeAnim_TubeAnimJumptable
call TradeAnim_IncrementJumptableIndex
ret
@@ -454,7 +465,7 @@
ld [hSCX], a
cp $60
ret nz
- xor a
+ xor a ; TRADEANIMSTATE_0
call TradeAnim_TubeAnimJumptable
call TradeAnim_IncrementJumptableIndex
ret
@@ -541,7 +552,7 @@
; 29281
TradeAnim_TubeAnimJumptable: ; 29281
- and 3
+ maskbits TRADEANIMJUMPTABLE_LENGTH +- 1
ld e, a
ld d, 0
ld hl, .Jumptable
@@ -554,6 +565,7 @@
; 2928f
.Jumptable: ; 2928f
+; entries correspond to TRADEANIMSTATE_* constants
dw .Zero
dw .One
dw .Two
--- a/engine/wildmons.asm
+++ b/engine/wildmons.asm
@@ -678,9 +678,9 @@
ld l, e
; Choose which map to warp to.
call Random
- and $1f ; 1/8n chance it moves to a completely random map, where n is the number of roaming connections from the current map.
+ and %00011111 ; 1/8n chance it moves to a completely random map, where n is the number of roaming connections from the current map.
jr z, JumpRoamMon
- and 3
+ and %11
cp [hl]
jr nc, .update_loop ; invalid index, try again
inc hl
@@ -739,10 +739,10 @@
JumpRoamMon: ; 2a3cd
.loop
ld hl, RoamMaps
-.innerloop1 ; This loop is completely unnecessary.
- call Random ; Choose a random number
- and $f ; Take the lower nybble only. This gives a number between 0 and 15.
- cp $10 ; If the number is greater than or equal to 16, loop back and try again.
+.innerloop1 ; This loop is completely unnecessary.
+ call Random ; Choose a random number.
+ maskbits $10 - 1 ; Mask the number to limit it between 0 and 15.
+ cp $10 ; If the number is not less than 16, try again.
jr nc, .innerloop1 ; I'm sure you can guess why this check is bogus.
inc a
ld b, a
@@ -825,7 +825,7 @@
call AddNTimes
.randloop1
call Random
- and $3
+ and %11
jr z, .randloop1
dec a
ld c, a
@@ -902,7 +902,7 @@
.done
call Random
- and $3
+ and %11
ld c, a
ld b, $0
add hl, bc
--- a/home/map.asm
+++ b/home/map.asm
@@ -1371,7 +1371,7 @@
inc d
; cap d at HIGH(vBGMap0)
ld a, d
- and $3
+ and %11
or HIGH(vBGMap0)
ld d, a