shithub: pokecrystal

Download patch

ref: 7b3de85a06e81d14ac0c73e8f9e1ab8e4a474beb
parent: 80480821142d7a7b16dd2b1a98a213e7b389af0f
author: Remy Oukaour <[email protected]>
date: Tue Jan 16 12:27:50 EST 2018

Avoid "+- 1" at every maskbits

--- a/audio/engine.asm
+++ b/audio/engine.asm
@@ -1304,7 +1304,7 @@
 	ld [hl], a
 	; are we on the last channel? (noise sampling)
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	cp CHAN4
 	ret z
 	; update hi frequency from next param
@@ -1668,7 +1668,7 @@
 ; if ????, jump
 	; get channel
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	ld e, a
 	ld d, 0
 	; hl = Channel1JumpCondition + channel id
@@ -1966,7 +1966,7 @@
 	add hl, bc
 	ld [hl], a
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	cp CHAN4
 	ret z
 	; intensity
@@ -2414,7 +2414,7 @@
 	push de
 	; store current channel in de
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	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
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	inc a
 .loop
 ; start playing channels
@@ -2505,7 +2505,7 @@
 	; Top 2 bits contain the number of channels
 	rlca
 	rlca
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 
 ; For each channel:
 	inc a
@@ -2530,7 +2530,7 @@
 
 ; No tempo for channel 4
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	cp CHAN4
 	jr nc, .start
 
@@ -2669,7 +2669,7 @@
 	call LoadMusicByte
 	rlca ; top 2
 	rlca ; bits
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	inc a ; # channels -> # loops
 .startchannels
 	push af
@@ -2722,7 +2722,7 @@
 	call LoadMusicByte
 	rlca
 	rlca
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	inc a
 
 .loop
@@ -2736,7 +2736,7 @@
 	push de
 	; get tracks for this channel
 	ld a, [CurChannel]
-	maskbits NUM_MUSIC_CHANS +- 1
+	maskbits NUM_MUSIC_CHANS
 	ld e, a
 	ld d, 0
 	call GetLRTracks
--- a/constants/pokemon_data_constants.asm
+++ b/constants/pokemon_data_constants.asm
@@ -216,6 +216,8 @@
 GRASS_WILDDATA_LENGTH EQU (NUM_GRASSMON * 2 + 1) * 3 + 2
 WATER_WILDDATA_LENGTH EQU (NUM_WATERMON * 2 + 1) * 1 + 2
 
+NUM_ROAMMON_MAPS EQU 16 ; RoamMaps table size (see data/wild/roammon_maps.asm)
+
 
 ; swarms
 
--- a/data/wild/roammon_maps.asm
+++ b/data/wild/roammon_maps.asm
@@ -13,6 +13,7 @@
 ENDM
 
 RoamMaps: ; 2a40f
+; there are NUM_ROAMMON_MAPS entries
 	roam_map ROUTE_29, 2, ROUTE_30, ROUTE_46
 	roam_map ROUTE_30, 2, ROUTE_29, ROUTE_31
 	roam_map ROUTE_31, 3, ROUTE_30, ROUTE_32, ROUTE_36
--- a/engine/battle/ai/move.asm
+++ b/engine/battle/ai/move.asm
@@ -186,7 +186,7 @@
 .ChooseMove:
 	ld hl, Buffer1
 	call Random
-	maskbits NUM_MOVES +- 1
+	maskbits NUM_MOVES
 	ld c, a
 	ld b, 0
 	add hl, bc
--- a/engine/battle/battle_transition.asm
+++ b/engine/battle/battle_transition.asm
@@ -640,7 +640,7 @@
 .cgb
 	ld hl, .daypals
 	ld a, [TimeOfDayPal]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	cp DARKNESS_F
 	jr nz, .daytime
 	ld hl, .nightpals
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -6031,7 +6031,7 @@
 .loop2
 	ld hl, EnemyMonMoves
 	call BattleRandom
-	maskbits NUM_MOVES +- 1
+	maskbits NUM_MOVES
 	ld c, a
 	ld b, 0
 	add hl, bc
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -932,7 +932,7 @@
 
 .RandomMove:
 	call BattleRandom
-	maskbits NUM_MOVES +- 1
+	maskbits NUM_MOVES
 
 	cp b
 	jr nc, .RandomMove
@@ -4387,7 +4387,7 @@
 .sample_move
 	push hl
 	call BattleRandom
-	maskbits NUM_MOVES +- 1
+	maskbits NUM_MOVES
 	ld c, a
 	ld b, 0
 	add hl, bc
@@ -8204,7 +8204,7 @@
 .done
 .loop3
 	call BattleRandom
-	maskbits NUM_MOVES +- 1
+	maskbits NUM_MOVES
 	ld c, a
 	ld b, 0
 	ld hl, StringBuffer1
--- a/engine/battle_anims/anim_commands.asm
+++ b/engine/battle_anims/anim_commands.asm
@@ -1206,7 +1206,7 @@
 	srl a
 	ld [wSFXDuration], a
 	call .GetCryTrack
-	maskbits NUM_NOISE_CHANS +- 1
+	maskbits NUM_NOISE_CHANS
 	ld [CryTracks], a ; CryTracks
 
 	ld e, a
@@ -1243,7 +1243,7 @@
 
 BattleAnimCmd_Cry: ; cc807 (33:4807)
 	call GetBattleAnimByte
-	maskbits NUM_NOISE_CHANS +- 1
+	maskbits NUM_NOISE_CHANS
 	ld e, a
 	ld d, 0
 	ld hl, .CryData
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -1230,7 +1230,7 @@
 	ld l, a
 	; Futher refine by time of day
 	ld a, [TimeOfDayPal]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	add a
 	add a
 	add a
@@ -1276,7 +1276,7 @@
 
 .got_pals
 	ld a, [TimeOfDayPal]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	ld bc, 8 palettes
 	ld hl, MapObjectPals
 	call AddNTimes
@@ -1300,7 +1300,7 @@
 	ld de, RoofPals
 	add hl, de
 	ld a, [TimeOfDayPal]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	cp NITE_F
 	jr c, .morn_day
 rept 4
--- a/engine/events/battle_tower/load_trainer.asm
+++ b/engine/events/battle_tower/load_trainer.asm
@@ -27,12 +27,12 @@
 	add b
 	ld b, a ; b contains the nr of the trainer
 if DEF(_CRYSTAL11)
-	maskbits BATTLETOWER_NUM_UNIQUE_TRAINERS +- 1
+	maskbits BATTLETOWER_NUM_UNIQUE_TRAINERS
 	cp BATTLETOWER_NUM_UNIQUE_TRAINERS
 else
 ; Crystal 1.0 used the wrong constant here, so only the first 21
 ; trainers in BattleTowerTrainers can be sampled.
-	maskbits BATTLETOWER_NUM_UNIQUE_PKMN +- 1
+	maskbits BATTLETOWER_NUM_UNIQUE_PKMN
 	cp BATTLETOWER_NUM_UNIQUE_PKMN
 endc
 	jr nc, .resample
@@ -115,7 +115,7 @@
 	ld a, [hRandomAdd]
 	add b
 	ld b, a
-	maskbits BATTLETOWER_NUM_UNIQUE_PKMN +- 1
+	maskbits BATTLETOWER_NUM_UNIQUE_PKMN
 	cp BATTLETOWER_NUM_UNIQUE_PKMN
 	jr nc, .resample
 	; in register 'a' is the chosen Pkmn of the LevelGroup
--- a/engine/events/buena.asm
+++ b/engine/events/buena.asm
@@ -17,7 +17,7 @@
 	ld a, [MenuSelection]
 	ld c, a
 	ld a, [wBuenasPassword]
-	maskbits NUM_PASSWORDS_PER_CATEGORY +- 1
+	maskbits NUM_PASSWORDS_PER_CATEGORY
 	cp c
 	jr nz, .wrong
 	ld b, $1
--- a/engine/events/fish.asm
+++ b/engine/events/fish.asm
@@ -80,7 +80,7 @@
 endr
 
 	ld a, [TimeOfDay]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	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]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	ld [TimeOfDayPal], a
 	ld a, $1
 	ld [wEnvironment], a
--- a/engine/events/poisonstep_pals.asm
+++ b/engine/events/poisonstep_pals.asm
@@ -10,7 +10,7 @@
 	and a
 	jr nz, .cgb
 	ld a, [TimeOfDayPal]
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	cp DARKNESS_F
 	ld a, %00000000
 	jr z, .convert_pals
--- a/engine/item_effects.asm
+++ b/engine/item_effects.asm
@@ -775,7 +775,7 @@
 	ld a, [EnemyMonSpecies]
 	rlca
 	rlca
-	maskbits NUM_DEX_ENTRY_BANKS +- 1
+	maskbits NUM_DEX_ENTRY_BANKS
 	ld hl, .PokedexEntryBanks
 	ld d, 0
 	ld e, a
--- a/engine/load_font.asm
+++ b/engine/load_font.asm
@@ -82,7 +82,7 @@
 
 LoadFrame: ; fb4cc
 	ld a, [TextBoxFrame]
-	maskbits NUM_FRAMES +- 1
+	maskbits NUM_FRAMES
 	ld bc, 6 * LEN_1BPP_TILE
 	ld hl, Frames
 	call AddNTimes
--- a/engine/map_objects.asm
+++ b/engine/map_objects.asm
@@ -893,7 +893,7 @@
 	ld hl, OBJECT_DIRECTION_WALKING
 	add hl, de
 	ld a, [hl]
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld d, 1 * 8 + 6
 	cp DOWN
 	jr z, .ok_13
--- a/engine/npc_movement.asm
+++ b/engine/npc_movement.asm
@@ -106,7 +106,7 @@
 	ld hl, OBJECT_DIRECTION_WALKING
 	add hl, bc
 	ld a, [hl]
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld e, a
 	ld d, 0
 	ld hl, .data_6f5b
@@ -131,7 +131,7 @@
 	push af
 	ld hl, OBJECT_DIRECTION_WALKING
 	add hl, bc
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld e, a
 	ld d, 0
 	ld hl, .data_6f7b
@@ -178,7 +178,7 @@
 	ld hl, OBJECT_DIRECTION_WALKING
 	add hl, bc
 	ld a, [hl]
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	jr z, .down
 	dec a
 	jr z, .up
--- a/engine/pack.asm
+++ b/engine/pack.asm
@@ -954,7 +954,7 @@
 	ld [wJumptableIndex], a
 	; pocket id -> jumptable index
 	ld a, [wLastPocket]
-	maskbits NUM_POCKETS +- 1
+	maskbits NUM_POCKETS
 	ld [wCurrPocket], a
 	inc a
 	add a
@@ -1099,7 +1099,7 @@
 .d_left
 	ld a, [wJumptableIndex]
 	dec a
-	maskbits NUM_POCKETS +- 1
+	maskbits NUM_POCKETS
 	ld [wJumptableIndex], a
 	push de
 	ld de, SFX_SWITCH_POCKETS
@@ -1111,7 +1111,7 @@
 .d_right
 	ld a, [wJumptableIndex]
 	inc a
-	maskbits NUM_POCKETS +- 1
+	maskbits NUM_POCKETS
 	ld [wJumptableIndex], a
 	push de
 	ld de, SFX_SWITCH_POCKETS
@@ -1281,7 +1281,7 @@
 	call WaitBGMap
 DrawPackGFX: ; 1089d
 	ld a, [wCurrPocket]
-	maskbits NUM_POCKETS +- 1
+	maskbits NUM_POCKETS
 	ld e, a
 	ld d, $0
 	ld a, [BattleType]
--- a/engine/player_movement.asm
+++ b/engine/player_movement.asm
@@ -140,7 +140,7 @@
 
 .water
 	ld a, c
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld c, a
 	ld b, 0
 	ld hl, .water_table
@@ -244,7 +244,7 @@
 	ld a, [PlayerDirection]
 	rrca
 	rrca
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	cp e
 	jr z, .not_turning
 
@@ -430,7 +430,7 @@
 	ld a, [PlayerDirection]
 	rrca
 	rrca
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	cp e
 	jr nz, .not_warp
 	call WarpCheck
@@ -559,7 +559,7 @@
 	cp 0
 	ret z
 
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	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
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld e, a
 	ld d, 0
 	ld hl, .movement_data
--- a/engine/pokedex_2.asm
+++ b/engine/pokedex_2.asm
@@ -230,7 +230,7 @@
 	push de
 	rlca
 	rlca
-	maskbits NUM_DEX_ENTRY_BANKS +- 1
+	maskbits NUM_DEX_ENTRY_BANKS
 	ld hl, .PokedexEntryBanks
 	ld d, 0
 	ld e, a
--- a/engine/pokegear.asm
+++ b/engine/pokegear.asm
@@ -251,7 +251,7 @@
 	ld a, $4f
 	call ByteFill
 	ld a, [wPokegearCard]
-	maskbits NUM_POKEGEAR_CARDS +- 1
+	maskbits NUM_POKEGEAR_CARDS
 	add a
 	ld e, a
 	ld d, 0
@@ -289,7 +289,7 @@
 	ld [hWY], a
 	; swap region maps
 	ld a, [wPokegearMapRegion]
-	maskbits NUM_REGIONS +- 1
+	maskbits NUM_REGIONS
 	xor 1
 	ld [wPokegearMapRegion], a
 	ret
--- 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
-	maskbits NUM_DAYTIMES +- 1
+	maskbits NUM_DAYTIMES
 	cp DARKNESS_F
 	jr z, .loop2
 
@@ -351,7 +351,7 @@
 	; 0-15 are all valid indexes into .Adverbs,
 	; so no need for a retry loop
 	call Random
-	maskbits NUM_OAKS_MON_TALK_ADVERBS +- 1
+	maskbits NUM_OAKS_MON_TALK_ADVERBS
 	ld e, a
 	ld d, 0
 	ld hl, .Adverbs
@@ -466,7 +466,7 @@
 	; 0-15 are all valid indexes into .Adjectives,
 	; so no need for a retry loop
 	call Random
-	maskbits NUM_OAKS_MON_TALK_ADJECTIVES +- 1
+	maskbits NUM_OAKS_MON_TALK_ADJECTIVES
 	ld e, a
 	ld d, 0
 	ld hl, .Adjectives
@@ -692,7 +692,7 @@
 	dec a
 	rlca
 	rlca
-	maskbits NUM_DEX_ENTRY_BANKS +- 1
+	maskbits NUM_DEX_ENTRY_BANKS
 	ld hl, .PokedexEntryBanks
 	ld d, 0
 	ld e, a
@@ -1164,7 +1164,7 @@
 
 PeoplePlaces4: ; People
 	call Random
-	maskbits NUM_TRAINER_CLASSES +- 1
+	maskbits NUM_TRAINER_CLASSES
 	inc a
 	cp NUM_TRAINER_CLASSES - 1
 	jr nc, PeoplePlaces4
@@ -1208,7 +1208,7 @@
 	; 0-15 are all valid indexes into .Adjectives,
 	; so no need for a retry loop
 	call Random
-	maskbits NUM_PNP_PEOPLE_ADJECTIVES +- 1
+	maskbits NUM_PNP_PEOPLE_ADJECTIVES
 	ld e, a
 	ld d, 0
 	ld hl, .Adjectives
@@ -1358,7 +1358,7 @@
 	; 0-15 are all valid indexes into .Adjectives,
 	; so no need for a retry loop
 	call Random
-	maskbits NUM_PNP_PLACES_ADJECTIVES +- 1
+	maskbits NUM_PNP_PLACES_ADJECTIVES
 	ld e, a
 	ld d, 0
 	ld hl, .Adjectives
@@ -1565,7 +1565,7 @@
 ; There are only 11 groups to choose from.
 .greater_than_11
 	call Random
-	maskbits NUM_PASSWORD_CATEGORIES +- 1
+	maskbits NUM_PASSWORD_CATEGORIES
 	cp NUM_PASSWORD_CATEGORIES
 	jr nc, .greater_than_11
 ; Store it in the high nybble of e.
@@ -1574,7 +1574,7 @@
 ; For each group, choose one of the three passwords.
 .greater_than_three
 	call Random
-	maskbits NUM_PASSWORDS_PER_CATEGORY +- 1
+	maskbits NUM_PASSWORDS_PER_CATEGORY
 	cp NUM_PASSWORDS_PER_CATEGORY
 	jr nc, .greater_than_three
 ; The high nybble of wBuenasPassword will now contain the password group index, and the low nybble contains the actual password.
--- a/engine/scripting.asm
+++ b/engine/scripting.asm
@@ -614,7 +614,7 @@
 	ld a, [wItemAttributeParamBuffer]
 	dec a
 	ld hl, .Pockets
-	maskbits NUM_POCKETS +- 1
+	maskbits NUM_POCKETS
 	add a
 	ld e, a
 	ld d, 0
@@ -2474,7 +2474,7 @@
 ; parameters: facing, map_group, map_id, x, y
 
 	call GetScriptByte
-	maskbits NUM_DIRECTIONS +- 1
+	maskbits NUM_DIRECTIONS
 	ld c, a
 	ld a, [wPlayerSpriteSetupFlags]
 	set 5, a
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -283,7 +283,7 @@
 StatsScreen_JoypadAction: ; 4de54 (13:5e54)
 	push af
 	ld a, [wcf64]
-	maskbits NUM_STAT_PAGES +- 1
+	maskbits NUM_STAT_PAGES
 	ld c, a
 	pop af
 	bit B_BUTTON_F, a
@@ -512,7 +512,7 @@
 
 .ClearBox: ; 4dfda (13:5fda)
 	ld a, [wcf64]
-	maskbits NUM_STAT_PAGES +- 1
+	maskbits NUM_STAT_PAGES
 	ld c, a
 	call StatsScreen_LoadPageIndicators
 	hlcoord 0, 8
@@ -522,7 +522,7 @@
 
 .LoadPals: ; 4dfed (13:5fed)
 	ld a, [wcf64]
-	maskbits NUM_STAT_PAGES +- 1
+	maskbits NUM_STAT_PAGES
 	ld c, a
 	farcall LoadStatsScreenPals
 	call DelayFrame
@@ -532,7 +532,7 @@
 
 .PageTilemap: ; 4e002 (13:6002)
 	ld a, [wcf64]
-	maskbits NUM_STAT_PAGES +- 1
+	maskbits NUM_STAT_PAGES
 	dec a
 	ld hl, .Jumptable
 	rst JumpTable
--- a/engine/trade_animation.asm
+++ b/engine/trade_animation.asm
@@ -552,7 +552,7 @@
 ; 29281
 
 TradeAnim_TubeAnimJumptable: ; 29281
-	maskbits TRADEANIMJUMPTABLE_LENGTH +- 1
+	maskbits TRADEANIMJUMPTABLE_LENGTH
 	ld e, a
 	ld d, 0
 	ld hl, .Jumptable
--- a/engine/unown_puzzle.asm
+++ b/engine/unown_puzzle.asm
@@ -835,7 +835,7 @@
 
 LoadUnownPuzzlePiecesGFX: ; e17a3
 	ld a, [ScriptVar]
-	maskbits NUM_UNOWN_PUZZLES +- 1
+	maskbits NUM_UNOWN_PUZZLES
 	ld e, a
 	ld d, 0
 	ld hl, .LZPointers
--- a/engine/wildmons.asm
+++ b/engine/wildmons.asm
@@ -739,11 +739,11 @@
 JumpRoamMon: ; 2a3cd
 .loop
 	ld hl, RoamMaps
-.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.
+.innerloop1                   ; This loop happens to be unnecessary.
+	call Random               ; Choose a random number.
+	maskbits NUM_ROAMMON_MAPS ; Mask the number to limit it between 0 and 15.
+	cp NUM_ROAMMON_MAPS       ; 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
 .innerloop2 ; Loop to get hl to the address of the chosen roam map.
--- a/home/time.asm
+++ b/home/time.asm
@@ -48,17 +48,17 @@
 
 	ld [hl], RTC_S
 	ld a, [de]
-	maskbits 60 - 1
+	maskbits 60
 	ld [hRTCSeconds], a
 
 	ld [hl], RTC_M
 	ld a, [de]
-	maskbits 60 - 1
+	maskbits 60
 	ld [hRTCMinutes], a
 
 	ld [hl], RTC_H
 	ld a, [de]
-	maskbits 24 - 1
+	maskbits 24
 	ld [hRTCHours], a
 
 	ld [hl], RTC_DL
--- a/macros/code.asm
+++ b/macros/code.asm
@@ -37,17 +37,17 @@
 
 maskbits: MACRO
 ; masks just enough bits to cover the argument
-; e.g. "maskbits %00010100" becomes "and %00011111"
+; e.g. "maskbits 26" becomes "and %00011111" (since 26 - 1 = %00011001)
 ; example usage in rejection sampling:
 ; .loop
 ; 	call Random
-; 	maskbits 30 +- 1
+; 	maskbits 30
 ; 	cp 30
 ; 	jr nc, .loop
 x = 1
 rept 8
-if x < (\1)
-x = (x + 1) * 2 +- 1
+if x + 1 < (\1)
+x = x << 1 | 1
 endc
 endr
 	and x
--- a/mobile/mobile_41.asm
+++ b/mobile/mobile_41.asm
@@ -1072,7 +1072,7 @@
 
 Function10649b: ; 10649b
 	ld a, [TextBoxFrame]
-	maskbits NUM_FRAMES +- 1
+	maskbits NUM_FRAMES
 	ld bc, 6 * LEN_1BPP_TILE
 	ld hl, Frames
 	call AddNTimes