Use labels instead of constants for HRAM

Use explicit ldh instruction to access HRAM locations, don't rely on optimizing ld
This commit is contained in:
Rangi
2018-08-25 14:28:22 -04:00
parent 376c64468b
commit eb1e3636bb
243 changed files with 4706 additions and 4661 deletions

View File

@@ -520,7 +520,7 @@ AIUpdateHUD:
call UpdateEnemyMonInParty
farcall UpdateEnemyHUD
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld hl, wEnemyItemState
dec [hl]
scf
@@ -671,7 +671,7 @@ AI_Switch:
ld hl, wEnemySubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar PursuitSwitch
push af
@@ -755,17 +755,17 @@ EnemyUsedDireHit:
jp PrintText_UsedItemOn_AND_AIUpdateHUD
Function3851e: ; This appears to be unused
ld [hDivisor], a
ldh [hDivisor], a
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld [hDividend], a
ldh [hDividend], a
ld a, [hl]
ld [hDividend + 1], a
ldh [hDividend + 1], a
ld b, 2
call Divide
ld a, [hQuotient + 2]
ldh a, [hQuotient + 2]
ld c, a
ld a, [hQuotient + 1]
ldh a, [hQuotient + 1]
ld b, a
ld hl, wEnemyMonHP + 1
ld a, [hld]

View File

@@ -165,7 +165,7 @@ AI_Types:
push bc
push de
ld a, 1
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
pop de
pop bc
@@ -410,7 +410,7 @@ AI_Smart_Sleep:
AI_Smart_LeechHit:
push hl
ld a, 1
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
pop hl
@@ -486,7 +486,7 @@ AI_Smart_LockOn:
jr nc, .asm_3884f
ld a, $1
ld [hBattleTurn], a
ldh [hBattleTurn], a
push hl
push bc
@@ -1289,7 +1289,7 @@ AI_Smart_Mimic:
call AIGetEnemyMove
ld a, $1
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
ld a, [wTypeMatchup]
@@ -1631,7 +1631,7 @@ AI_Smart_PriorityHit:
; Greatly encourage this move if it will KO the player.
ld a, $1
ld [hBattleTurn], a
ldh [hBattleTurn], a
push hl
callfar EnemyAttackDamage
callfar BattleCommand_DamageCalc
@@ -1675,7 +1675,7 @@ AI_Smart_Conversion2:
ld [wPlayerMoveStruct + MOVE_TYPE], a
xor a
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
@@ -2285,7 +2285,7 @@ AI_Smart_RapidSpin:
AI_Smart_HiddenPower:
push hl
ld a, 1
ld [hBattleTurn], a
ldh [hBattleTurn], a
; Calculate Hidden Power's type and base power based on enemy's DVs.
callfar HiddenPowerDamage
@@ -3013,7 +3013,7 @@ INCLUDE "data/battle/ai/reckless_moves.asm"
AIDamageCalc:
ld a, 1
ld [hBattleTurn], a
ldh [hBattleTurn], a
ld a, [wEnemyMoveStruct + MOVE_EFFECT]
ld de, 1
ld hl, ConstantDamageEffects
@@ -3119,7 +3119,7 @@ AI_Status:
push bc
push de
ld a, 1
ld [hBattleTurn], a
ldh [hBattleTurn], a
callfar BattleCheckTypeMatchup
pop de
pop bc

View File

@@ -277,7 +277,7 @@ HPBarAnim_UpdateHPRemaining:
ret
HPBarAnim_PaletteUpdate:
ld a, [hCGB]
ldh a, [hCGB]
and a
ret z
ld hl, wCurHPAnimPal
@@ -288,7 +288,7 @@ HPBarAnim_PaletteUpdate:
ret
HPBarAnim_BGMapUpdate:
ld a, [hCGB]
ldh a, [hCGB]
and a
jr nz, .cgb
call DelayFrame
@@ -316,15 +316,15 @@ HPBarAnim_BGMapUpdate:
cp $5
jr z, .skip_delay
ld a, $2
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, c
ld [hBGMapThird], a
ldh [hBGMapThird], a
call DelayFrame
.skip_delay
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, c
ld [hBGMapThird], a
ldh [hBGMapThird], a
call DelayFrame
pop af
cp $2
@@ -336,14 +336,14 @@ HPBarAnim_BGMapUpdate:
.two_frames
inc c
ld a, $2
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, c
ld [hBGMapThird], a
ldh [hBGMapThird], a
call DelayFrame
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, c
ld [hBGMapThird], a
ldh [hBGMapThird], a
call DelayFrame
ret
@@ -356,7 +356,7 @@ HPBarAnim_BGMapUpdate:
.finish
call DelayFrame
ld a, c
ld [hBGMapThird], a
ldh [hBGMapThird], a
call DelayFrame
ret

View File

@@ -10,11 +10,11 @@ BATTLETRANSITION_SQUARE EQUS "\"8\"" ; $fe
DoBattleTransition:
call .InitGFX
ld a, [rBGP]
ldh a, [rBGP]
ld [wBGP], a
ld a, [rOBP0]
ldh a, [rOBP0]
ld [wOBP0], a
ld a, [rOBP1]
ldh a, [rOBP1]
ld [wOBP1], a
call DelayFrame
ld hl, hVBlank
@@ -31,10 +31,10 @@ DoBattleTransition:
jr .loop
.done
ld a, [rSVBK]
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ld [rSVBK], a
ldh [rSVBK], a
ld hl, wBGPals1
ld bc, 8 palettes
@@ -42,22 +42,22 @@ DoBattleTransition:
call ByteFill
pop af
ld [rSVBK], a
ldh [rSVBK], a
ld a, %11111111
ld [wBGP], a
call DmgToCgbBGPals
call DelayFrame
xor a
ld [hLCDCPointer], a
ld [hLYOverrideStart], a
ld [hLYOverrideEnd], a
ld [hSCY], a
ldh [hLCDCPointer], a
ldh [hLYOverrideStart], a
ldh [hLYOverrideEnd], a
ldh [hSCY], a
ld a, 1 ; unnecessary bankswitch?
ld [rSVBK], a
ldh [rSVBK], a
pop af
ld [hVBlank], a
ldh [hVBlank], a
call DelayFrame
ret
@@ -77,10 +77,10 @@ DoBattleTransition:
.resume
ld a, SCREEN_HEIGHT_PX
ld [hWY], a
ldh [hWY], a
call DelayFrame
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld hl, wJumptableIndex
xor a
ld [hli], a
@@ -104,10 +104,10 @@ LoadTrainerBattlePokeballTiles:
ld c, 2
call Request2bpp
ld a, [rVBK]
ldh a, [rVBK]
push af
ld a, $1
ld [rVBK], a
ldh [rVBK], a
ld de, TrainerBattlePokeballTiles
ld hl, vTiles3 tile BATTLETRANSITION_SQUARE
@@ -116,14 +116,14 @@ LoadTrainerBattlePokeballTiles:
call Request2bpp
pop af
ld [rVBK], a
ldh [rVBK], a
ret
ConvertTrainerBattlePokeballTilesTo2bpp:
ld a, [rSVBK]
ldh a, [rSVBK]
push af
ld a, BANK(wDecompressScratch)
ld [rSVBK], a
ldh [rSVBK], a
push hl
ld hl, wDecompressScratch
ld bc, $28 tiles
@@ -142,7 +142,7 @@ ConvertTrainerBattlePokeballTilesTo2bpp:
ld c, $28
call Request2bpp
pop af
ld [rSVBK], a
ldh [rSVBK], a
ret
TrainerBattlePokeballTiles:
@@ -258,7 +258,7 @@ StartTrainerBattle_SetUpBGMap:
call StartTrainerBattle_NextScene
xor a
ld [wcf64], a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ret
StartTrainerBattle_Flash:
@@ -311,16 +311,16 @@ StartTrainerBattle_Flash:
StartTrainerBattle_SetUpForWavyOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
ldh [rSVBK], a
call StartTrainerBattle_NextScene
ld a, rSCX - $ff00
ld [hLCDCPointer], a
ldh [hLCDCPointer], a
xor a
ld [hLYOverrideStart], a
ldh [hLYOverrideStart], a
ld a, $90
ld [hLYOverrideEnd], a
ldh [hLYOverrideEnd], a
xor a
ld [wcf64], a
ld [wcf65], a
@@ -369,7 +369,7 @@ StartTrainerBattle_SineWave:
StartTrainerBattle_SetUpForSpinOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
ldh [rSVBK], a
call StartTrainerBattle_NextScene
xor a
ld [wcf64], a
@@ -377,7 +377,7 @@ StartTrainerBattle_SetUpForSpinOutro:
StartTrainerBattle_SpinToBlack:
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, [wcf64]
ld e, a
ld d, 0
@@ -391,7 +391,7 @@ endr
ld [wcf65], a
call .load
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
ld hl, wcf64
@@ -400,12 +400,12 @@ endr
.end
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
call DelayFrame
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
@@ -511,12 +511,12 @@ ENDM
StartTrainerBattle_SetUpForRandomScatterOutro:
farcall Function5602
ld a, BANK(wLYOverrides)
ld [rSVBK], a
ldh [rSVBK], a
call StartTrainerBattle_NextScene
ld a, $10
ld [wcf64], a
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ret
StartTrainerBattle_SpeckleToBlack:
@@ -536,12 +536,12 @@ StartTrainerBattle_SpeckleToBlack:
.done
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
call DelayFrame
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ld a, BATTLETRANSITION_FINISH
ld [wJumptableIndex], a
ret
@@ -583,7 +583,7 @@ StartTrainerBattle_LoadPokeBallGraphics:
jp z, .nextscene ; don't need to be here if wild
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
hlcoord 0, 0, wAttrMap
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
inc b
@@ -640,11 +640,11 @@ StartTrainerBattle_LoadPokeBallGraphics:
dec b
jr nz, .loop2
ld a, [hCGB]
ldh a, [hCGB]
and a
jr nz, .cgb
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
call DelayFrame
call DelayFrame
jr .nextscene
@@ -657,10 +657,10 @@ StartTrainerBattle_LoadPokeBallGraphics:
jr nz, .daytime
ld hl, .nightpals
.daytime
ld a, [rSVBK]
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals1)
ld [rSVBK], a
ldh [rSVBK], a
call .copypals
push hl
ld de, wBGPals1 palette PAL_BG_TEXT
@@ -671,9 +671,9 @@ StartTrainerBattle_LoadPokeBallGraphics:
ld bc, 1 palettes
call CopyBytes
pop af
ld [rSVBK], a
ldh [rSVBK], a
ld a, $1
ld [hCGBPalUpdate], a
ldh [hCGBPalUpdate], a
call DelayFrame
call BattleStart_CopyTilemapAtOnce
@@ -731,10 +731,10 @@ PokeBallTransition:
db %00000011, %11000000
WipeLYOverrides:
ld a, [rSVBK]
ldh a, [rSVBK]
push af
ld a, BANK(wLYOverrides)
ld [rSVBK], a
ldh [rSVBK], a
ld hl, wLYOverrides
call .wipe
@@ -742,7 +742,7 @@ WipeLYOverrides:
call .wipe
pop af
ld [rSVBK], a
ldh [rSVBK], a
ret
.wipe
@@ -777,7 +777,7 @@ StartTrainerBattle_ZoomToBlack:
inc de
ld h, a
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
call .Copy
call WaitBGMap
jr .loop
@@ -823,8 +823,8 @@ ENDM
Unreferenced_Function8c7c9:
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
call WaitBGMap
xor a
ld [hBGMapMode], a
ldh [hBGMapMode], a
ret

View File

@@ -2,7 +2,7 @@ ConsumeHeldItem:
push hl
push de
push bc
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
ld hl, wOTPartyMon1Item
ld de, wEnemyMonItem
@@ -38,7 +38,7 @@ ConsumeHeldItem:
pop af
pop hl
call GetPartyLocation
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr nz, .ourturn
ld a, [wBattleMode]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@ HiddenPowerDamage:
; Override Hidden Power's type and power based on the user's DVs.
ld hl, wBattleMonDVs
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_dvs
ld hl, wEnemyMonDVs

View File

@@ -83,13 +83,13 @@ DetermineLinkBattleResult:
jr z, .next
dec hl
xor a
ld [hDividend + 0], a
ldh [hDividend + 0], a
ld a, [hli]
ld [hDividend + 1], a
ldh [hDividend + 1], a
ld a, [hli]
ld [hDividend + 2], a
ldh [hDividend + 2], a
xor a
ld [hDividend + 3], a
ldh [hDividend + 3], a
ld a, [hli]
ld b, a
ld a, [hld]
@@ -97,13 +97,13 @@ DetermineLinkBattleResult:
rr a
srl b
rr a
ld [hDivisor], a
ldh [hDivisor], a
ld b, $4
call Divide
ld a, [hQuotient + 2]
ldh a, [hQuotient + 2]
add e
ld e, a
ld a, [hQuotient + 1]
ldh a, [hQuotient + 1]
adc d
ld d, a
dec hl

View File

@@ -1,7 +1,7 @@
_DisappearUser:
xor a
ld [hBGMapMode], a
ld a, [hBattleTurn]
ldh [hBGMapMode], a
ldh a, [hBattleTurn]
and a
jr z, .player
call GetEnemyFrontpicCoords
@@ -21,8 +21,8 @@ _AppearUserLowerSub:
AppearUser:
xor a
ld [hBGMapMode], a
ld a, [hBattleTurn]
ldh [hBGMapMode], a
ldh a, [hBattleTurn]
and a
jr z, .player
call GetEnemyFrontpicCoords
@@ -32,11 +32,11 @@ AppearUser:
call GetPlayerBackpicCoords
ld a, $31
.okay
ld [hGraphicStartTile], a
ldh [hGraphicStartTile], a
predef PlaceGraphic
FinishAppearDisappearUser:
ld a, $1
ld [hBGMapMode], a
ldh [hBGMapMode], a
ret
GetEnemyFrontpicCoords:
@@ -101,32 +101,32 @@ DoWeatherModifiers:
.ApplyModifier:
xor a
ld [hMultiplicand + 0], a
ldh [hMultiplicand + 0], a
ld hl, wCurDamage
ld a, [hli]
ld [hMultiplicand + 1], a
ldh [hMultiplicand + 1], a
ld a, [hl]
ld [hMultiplicand + 2], a
ldh [hMultiplicand + 2], a
inc de
ld a, [de]
ld [hMultiplier], a
ldh [hMultiplier], a
call Multiply
ld a, 10
ld [hDivisor], a
ldh [hDivisor], a
ld b, 4
call Divide
ld a, [hQuotient + 0]
ldh a, [hQuotient + 0]
and a
ld bc, -1
jr nz, .Update
ld a, [hQuotient + 1]
ldh a, [hQuotient + 1]
ld b, a
ld a, [hQuotient + 2]
ldh a, [hQuotient + 2]
ld c, a
or b
jr nz, .Update
@@ -153,7 +153,7 @@ DoBadgeTypeBoosts:
and a
ret nz
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
ret nz

View File

@@ -1,7 +1,7 @@
BattleCommand_BatonPass:
; batonpass
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jp nz, .Enemy

View File

@@ -2,7 +2,7 @@ BattleCommand_BeatUp:
; beatup
call ResetDamage
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jp nz, .enemy_beats_up
@@ -210,7 +210,7 @@ GetBeatupMonLocation:
push bc
ld c, a
ld b, 0
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
ld hl, wPartyMon1Species
jr z, .got_species

View File

@@ -7,7 +7,7 @@ BattleCommand_StoreEnergy:
ret z
ld hl, wPlayerRolloutCount
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .check_still_storing_energy
ld hl, wEnemyRolloutCount
@@ -28,7 +28,7 @@ BattleCommand_StoreEnergy:
ld [hl], a
ld hl, wPlayerDamageTaken + 1
ld de, wPlayerCharging ; player
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .player
ld hl, wEnemyDamageTaken + 1
@@ -74,7 +74,7 @@ BattleCommand_UnleashEnergy:
ld de, wPlayerDamageTaken
ld bc, wPlayerRolloutCount
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_damage
ld de, wEnemyDamageTaken

View File

@@ -3,7 +3,7 @@ BattleCommand_Conversion:
ld hl, wBattleMonMoves
ld de, wBattleMonType1
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_moves
ld hl, wEnemyMonMoves

View File

@@ -5,7 +5,7 @@ BattleCommand_Conversion2:
and a
jr nz, .failed
ld hl, wBattleMonType1
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_type
ld hl, wEnemyMonType1

View File

@@ -3,7 +3,7 @@ BattleCommand_Curse:
ld de, wBattleMonType1
ld bc, wPlayerStatLevels
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .go
ld de, wEnemyMonType1

View File

@@ -7,7 +7,7 @@ BattleCommand_Disable:
ld de, wEnemyDisableCount
ld hl, wEnemyMonMoves
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_moves
ld de, wPlayerDisableCount
@@ -33,7 +33,7 @@ BattleCommand_Disable:
cp b
jr nz, .loop
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
ld hl, wEnemyMonPP
jr z, .got_pp
@@ -55,7 +55,7 @@ BattleCommand_Disable:
ld [de], a
call AnimateCurrentMove
ld hl, wDisabledMove
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr nz, .got_disabled_move_pointer
inc hl

View File

@@ -3,7 +3,7 @@ BattleCommand_Encore:
ld hl, wEnemyMonMoves
ld de, wEnemyEncoreCount
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .ok
ld hl, wBattleMonMoves
@@ -47,7 +47,7 @@ BattleCommand_Encore:
ld [de], a
call CheckOpponentWentFirst
jr nz, .finish_move
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .force_last_enemy_move

View File

@@ -4,7 +4,7 @@ BattleCommand_FalseSwipe:
; Makes sure wCurDamage < MonHP
ld hl, wEnemyMonHP
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_hp
ld hl, wBattleMonHP

View File

@@ -3,25 +3,25 @@ BattleCommand_FrustrationPower:
push bc
ld hl, wBattleMonHappiness
ld a, [hBattleTurn]
ldh a, [hBattleTurn]
and a
jr z, .got_happiness
ld hl, wEnemyMonHappiness
.got_happiness
ld a, $ff
sub [hl]
ld [hMultiplicand + 2], a
ldh [hMultiplicand + 2], a
xor a
ld [hMultiplicand + 0], a
ld [hMultiplicand + 1], a
ldh [hMultiplicand + 0], a
ldh [hMultiplicand + 1], a
ld a, 10
ld [hMultiplier], a
ldh [hMultiplier], a
call Multiply
ld a, 25
ld [hDivisor], a
ldh [hDivisor], a
ld b, 4
call Divide
ld a, [hQuotient + 2]
ldh a, [hQuotient + 2]
ld d, a
pop bc
ret

Some files were not shown because too many files have changed in this diff Show More