Identify remaining uses of wBuffer1-6 as general-purpose HP buffers or mobile

This commit is contained in:
Rangi 2020-11-03 23:25:22 -05:00
parent a831b34e5c
commit 7254c10093
8 changed files with 145 additions and 146 deletions

View File

@ -1797,26 +1797,26 @@ SubtractHP:
.ok
inc hl
ld a, [hl]
ld [wBuffer3], a
ld [wHPBuffer2], a
sub c
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ld a, [hl]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
sbc b
ld [hl], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ret nc
ld a, [wBuffer3]
ld a, [wHPBuffer2]
ld c, a
ld a, [wBuffer4]
ld a, [wHPBuffer2 + 1]
ld b, a
xor a
ld [hli], a
ld [hl], a
ld [wBuffer5], a
ld [wBuffer6], a
ld [wHPBuffer3], a
ld [wHPBuffer3 + 1], a
ret
GetSixteenthMaxHP:
@ -1882,7 +1882,7 @@ GetHalfMaxHP:
ret
GetMaxHP:
; output: bc, wBuffer1-2
; output: bc, wHPBuffer1
ld hl, wBattleMonMaxHP
ldh a, [hBattleTurn]
@ -1891,11 +1891,11 @@ GetMaxHP:
ld hl, wEnemyMonMaxHP
.ok
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld b, a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
ld c, a
ret
@ -1913,9 +1913,9 @@ GetHalfHP: ; unreferenced
srl b
rr c
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
ret
CheckUserHasEnoughHP:
@ -1940,36 +1940,36 @@ RestoreHP:
ld hl, wBattleMonMaxHP
.ok
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hld]
ld [wBuffer1], a
ld [wHPBuffer1], a
dec hl
ld a, [hl]
ld [wBuffer3], a
ld [wHPBuffer2], a
add c
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ld a, [hl]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
adc b
ld [hli], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, [wBuffer1]
ld a, [wHPBuffer1]
ld c, a
ld a, [hld]
sub c
ld a, [wBuffer2]
ld a, [wHPBuffer1 + 1]
ld b, a
ld a, [hl]
sbc b
jr c, .overflow
ld a, b
ld [hli], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, c
ld [hl], a
ld [wBuffer5], a
ld [wHPBuffer3], a
.overflow
call SwitchTurnCore
@ -4270,13 +4270,13 @@ HandleHPHealingItem:
; Store current HP in Buffer 3/4
push bc
ld a, [de]
ld [wBuffer3], a
ld [wHPBuffer2], a
add a
ld c, a
dec de
ld a, [de]
inc de
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
adc a
ld b, a
ld a, b
@ -4295,19 +4295,19 @@ HandleHPHealingItem:
.less
call ItemRecoveryAnim
; store max HP in wBuffer1/2
; store max HP in wHPBuffer1
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
ld a, [de]
add c
ld [wBuffer5], a
ld [wHPBuffer3], a
ld c, a
dec de
ld a, [de]
adc 0
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld b, a
ld a, [hld]
cp c
@ -4315,15 +4315,15 @@ HandleHPHealingItem:
sbc b
jr nc, .okay
ld a, [hli]
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, [hl]
ld [wBuffer5], a
ld [wHPBuffer3], a
.okay
ld a, [wBuffer6]
ld a, [wHPBuffer3 + 1]
ld [de], a
inc de
ld a, [wBuffer5]
ld a, [wHPBuffer3]
ld [de], a
ldh a, [hBattleTurn]
ld [wWhichHPBar], a

View File

@ -2406,19 +2406,19 @@ BattleCommand_CheckFaint:
.got_max_hp
ld [wWhichHPBar], a
ld a, [hld]
ld [wBuffer1], a
ld [wHPBuffer1], a
ld a, [hld]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer3], a
ld [wHPBuffer2], a
xor a
ld [hld], a
ld a, [hl]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
xor a
ld [hl], a
ld [wBuffer5], a
ld [wBuffer6], a
ld [wHPBuffer3], a
ld [wHPBuffer3 + 1], a
ld h, b
ld l, c
predef AnimateHPBar
@ -3418,18 +3418,18 @@ DoEnemyDamage:
jp nz, DoSubstituteDamage
.ignore_substitute
; Substract wCurDamage from wEnemyMonHP.
; store original HP in little endian wBuffer3/4
; Subtract wCurDamage from wEnemyMonHP.
; store original HP in little endian wHPBuffer2
ld a, [hld]
ld b, a
ld a, [wEnemyMonHP + 1]
ld [wBuffer3], a
ld [wHPBuffer2], a
sub b
ld [wEnemyMonHP + 1], a
ld a, [hl]
ld b, a
ld a, [wEnemyMonHP]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
sbc b
ld [wEnemyMonHP], a
if DEF(_DEBUG)
@ -3451,9 +3451,9 @@ else
jr nc, .no_underflow
endc
ld a, [wBuffer4]
ld a, [wHPBuffer2 + 1]
ld [hli], a
ld a, [wBuffer3]
ld a, [wHPBuffer2]
ld [hl], a
xor a
ld hl, wEnemyMonHP
@ -3463,14 +3463,14 @@ endc
.no_underflow
ld hl, wEnemyMonMaxHP
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
ld hl, wEnemyMonHP
ld a, [hli]
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, [hl]
ld [wBuffer5], a
ld [wHPBuffer3], a
hlcoord 2, 2
xor a
@ -3495,42 +3495,42 @@ DoPlayerDamage:
jp nz, DoSubstituteDamage
.ignore_substitute
; Substract wCurDamage from wBattleMonHP.
; store original HP in little endian wBuffer3/4
; store new HP in little endian wBuffer5/6
; Subtract wCurDamage from wBattleMonHP.
; store original HP in little endian wHPBuffer2
; store new HP in little endian wHPBuffer3
ld a, [hld]
ld b, a
ld a, [wBattleMonHP + 1]
ld [wBuffer3], a
ld [wHPBuffer2], a
sub b
ld [wBattleMonHP + 1], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ld b, [hl]
ld a, [wBattleMonHP]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
sbc b
ld [wBattleMonHP], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
jr nc, .no_underflow
ld a, [wBuffer4]
ld a, [wHPBuffer2 + 1]
ld [hli], a
ld a, [wBuffer3]
ld a, [wHPBuffer2]
ld [hl], a
xor a
ld hl, wBattleMonHP
ld [hli], a
ld [hl], a
ld hl, wBuffer5
ld hl, wHPBuffer3
ld [hli], a
ld [hl], a
.no_underflow
ld hl, wBattleMonMaxHP
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
hlcoord 10, 9
ld a, 1
@ -3911,15 +3911,15 @@ SapHealth:
ld de, wEnemyMonMaxHP
.battlemonhp
; Store current HP in little endian wBuffer3/4
ld bc, wBuffer4
; Store current HP in little endian wHPBuffer2
ld bc, wHPBuffer2 + 1
ld a, [hli]
ld [bc], a
ld a, [hl]
dec bc
ld [bc], a
; Store max HP in little endian wBuffer1/2
; Store max HP in little endian wHPBuffer1
ld a, [de]
dec bc
ld [bc], a
@ -3928,20 +3928,20 @@ SapHealth:
dec bc
ld [bc], a
; Add hDividend to current HP and copy it to little endian wBuffer5/6
; Add hDividend to current HP and copy it to little endian wHPBuffer3
ldh a, [hDividend + 1]
ld b, [hl]
add b
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ldh a, [hDividend]
ld b, [hl]
adc b
ld [hli], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
jr c, .max_hp
; Substract current HP from max HP (to see if we have more than max HP)
; Subtract current HP from max HP (to see if we have more than max HP)
ld a, [hld]
ld b, a
ld a, [de]
@ -3955,14 +3955,14 @@ SapHealth:
jr nc, .finish
.max_hp
; Load max HP into current HP and copy it to little endian wBuffer5/6
; Load max HP into current HP and copy it to little endian wHPBuffer3
ld a, [de]
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
dec de
ld a, [de]
ld [hli], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
inc de
.finish
@ -5805,26 +5805,26 @@ BattleCommand_Recoil:
inc c
.min_damage
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
dec hl
dec hl
ld a, [hl]
ld [wBuffer3], a
ld [wHPBuffer2], a
sub c
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ld a, [hl]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
sbc b
ld [hl], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
jr nc, .dont_ko
xor a
ld [hli], a
ld [hl], a
ld hl, wBuffer5
ld hl, wHPBuffer3
ld [hli], a
ld [hl], a
.dont_ko

View File

@ -16,13 +16,13 @@ BattleCommand_PainSplit:
predef AnimateHPBar
ld hl, wEnemyMonHP
ld a, [hli]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
ld a, [hli]
ld [wBuffer3], a
ld [wHPBuffer2], a
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
call .EnemyShareHP
xor a
ld [wWhichHPBar], a
@ -36,14 +36,14 @@ BattleCommand_PainSplit:
.PlayerShareHP:
ld a, [hld]
ld [wBuffer1], a
ld [wHPBuffer1], a
ld a, [hld]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hld]
ld b, a
ld [wBuffer3], a
ld [wHPBuffer2], a
ld a, [hl]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
dec de
dec de
ld a, [de]
@ -83,10 +83,10 @@ BattleCommand_PainSplit:
.skip
ld a, c
ld [hld], a
ld [wBuffer5], a
ld [wHPBuffer3], a
ld a, b
ld [hli], a
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ret
.ButItFailed:

View File

@ -1817,7 +1817,7 @@ ContinueRevive:
ld [hl], d
inc hl
ld [hl], e
jp LoadCurHPIntoBuffer5
jp LoadCurHPIntoBuffer3
RestoreHealth:
ld a, MON_HP + 1
@ -1829,7 +1829,7 @@ RestoreHealth:
adc d
ld [hl], a
jr c, .full_hp
call LoadCurHPIntoBuffer5
call LoadCurHPIntoBuffer3
ld a, MON_HP + 1
call GetPartyParamLocation
ld d, h
@ -1862,21 +1862,21 @@ RemoveHP:
ld [hld], a
ld [hl], a
.okay
call LoadCurHPIntoBuffer5
call LoadCurHPIntoBuffer3
ret
IsMonFainted:
push de
call LoadMaxHPToBuffer1
call LoadCurHPToBuffer3
call LoadHPFromBuffer3
call LoadMaxHPIntoBuffer1
call LoadCurHPIntoBuffer2
call LoadHPFromBuffer2
ld a, d
or e
pop de
ret
IsMonAtFullHealth:
call LoadHPFromBuffer3
call LoadHPFromBuffer2
ld h, d
ld l, e
call LoadHPFromBuffer1
@ -1886,60 +1886,60 @@ IsMonAtFullHealth:
sbc d
ret
LoadCurHPIntoBuffer5:
LoadCurHPIntoBuffer3:
ld a, MON_HP
call GetPartyParamLocation
ld a, [hli]
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, [hl]
ld [wBuffer5], a
ld [wHPBuffer3], a
ret
LoadHPIntoBuffer5: ; unreferenced
LoadHPIntoBuffer3: ; unreferenced
ld a, d
ld [wBuffer6], a
ld [wHPBuffer3 + 1], a
ld a, e
ld [wBuffer5], a
ld [wHPBuffer3], a
ret
LoadHPFromBuffer5: ; unreferenced
ld a, [wBuffer6]
LoadHPFromBuffer3: ; unreferenced
ld a, [wHPBuffer3 + 1]
ld d, a
ld a, [wBuffer5]
ld a, [wHPBuffer3]
ld e, a
ret
LoadCurHPToBuffer3:
LoadCurHPIntoBuffer2:
ld a, MON_HP
call GetPartyParamLocation
ld a, [hli]
ld [wBuffer4], a
ld [wHPBuffer2 + 1], a
ld a, [hl]
ld [wBuffer3], a
ld [wHPBuffer2], a
ret
LoadHPFromBuffer3:
ld a, [wBuffer4]
LoadHPFromBuffer2:
ld a, [wHPBuffer2 + 1]
ld d, a
ld a, [wBuffer3]
ld a, [wHPBuffer2]
ld e, a
ret
LoadMaxHPToBuffer1:
LoadMaxHPIntoBuffer1:
push hl
ld a, MON_MAXHP
call GetPartyParamLocation
ld a, [hli]
ld [wBuffer2], a
ld [wHPBuffer1 + 1], a
ld a, [hl]
ld [wBuffer1], a
ld [wHPBuffer1], a
pop hl
ret
LoadHPFromBuffer1:
ld a, [wBuffer2]
ld a, [wHPBuffer1 + 1]
ld d, a
ld a, [wBuffer1]
ld a, [wHPBuffer1]
ld e, a
ret

View File

@ -6904,7 +6904,7 @@ Function103302:
Function103309:
xor a
ldh [hBGMapMode], a
ld hl, wBuffer1
ld hl, wd1ea
ld bc, 10
xor a
call ByteFill
@ -6912,7 +6912,7 @@ Function103309:
call OpenSRAM
ld a, [wdc41]
ld [s4_a60c], a
ld [wBuffer1], a
ld [wd1ea], a
call CloseSRAM
call Function1035c6
ld a, [hli]
@ -6954,15 +6954,15 @@ Function103362:
call Function10339a
call Function10342c
farcall HDMATransferTilemapToWRAMBank3
ld a, [wBuffer2]
ld a, [wd1eb]
bit 7, a
jr z, .asm_103362
ld hl, wBuffer2
ld hl, wd1eb
bit 6, [hl]
jr z, .asm_103398
ld a, BANK(s4_a60c)
call OpenSRAM
ld a, [wBuffer1]
ld a, [wd1ea]
ld [s4_a60c], a
ld [wdc41], a
call CloseSRAM
@ -7028,7 +7028,7 @@ Function1033af:
.b
call PlayClickSFX
ld hl, wBuffer2
ld hl, wd1eb
set 7, [hl]
ret
@ -7038,9 +7038,9 @@ Function1033af:
jr nz, .a_return
ld de, SFX_TRANSACTION
call PlaySFX
ld hl, wBuffer2
ld hl, wd1eb
set 7, [hl]
ld hl, wBuffer2
ld hl, wd1eb
set 6, [hl]
ret
@ -7054,9 +7054,9 @@ Function1033af:
call PlaySFX
ld bc, 8
call Function10350f
ld a, [wBuffer1]
ld a, [wd1ea]
xor e
ld [wBuffer1], a
ld [wd1ea], a
ret
Function10342c:
@ -7092,7 +7092,7 @@ Function10343c:
call Function103487
ld bc, 8
call Function10350f
ld a, [wBuffer1]
ld a, [wd1ea]
and e
ld bc, 2
jr z, .asm_10347d

View File

@ -78,7 +78,7 @@ Function16c000: ; unreferenced
Function16c089:
ld a, $1
ld [wBuffer2], a
ld [wd1eb], a
ld [wd1f1], a
xor a
ldh [hWY], a
@ -96,7 +96,7 @@ Function16c09e:
Function16c0a8:
xor a
ld [wBuffer2], a
ld [wd1eb], a
ld [wd1f1], a
call ClearSprites
ld a, $90
@ -515,8 +515,8 @@ Function16cb08:
Function16cb0f:
xor a
ld [wBuffer1], a
ld [wBuffer2], a
ld [wd1ea], a
ld [wd1eb], a
xor a
ld [wd1ec], a
ld a, $70
@ -530,7 +530,7 @@ Function16cb0f:
ret
Function16cb2e:
ld a, [wBuffer2]
ld a, [wd1eb]
and a
ret z
call Function16cb40

View File

@ -41,7 +41,7 @@ Function17a6a8:
ld bc, $a
xor a
call ByteFill
ld hl, wBuffer1
ld hl, wd1ea
ld bc, $10
ld a, $ff
call ByteFill
@ -66,7 +66,7 @@ Function17a6a8:
ret
Function17a6f5:
ld hl, wBuffer1
ld hl, wd1ea
ld c, $0
ld b, $8
.asm_17a6fc
@ -107,7 +107,7 @@ Function17a721:
ld a, $ff
call ByteFill
pop de
ld hl, wBuffer1
ld hl, wd1ea
ld b, $8
.asm_17a732
ld c, $0
@ -457,7 +457,7 @@ Function17a943:
ld [$d08c], a
ld c, a
ld b, $0
ld hl, wBuffer1
ld hl, wd1ea
add hl, bc
ld [hl], $ff
ld a, $2
@ -479,7 +479,7 @@ Function17a964:
ld b, $0
inc a
ld [$d08c], a
ld hl, wBuffer1
ld hl, wd1ea
add hl, bc
ld [hl], e
and a
@ -494,7 +494,7 @@ Function17a97b:
lb bc, 2, 18
call ClearBox
hlcoord 3, 2
ld de, wBuffer1
ld de, wd1ea
ld a, [$d08c]
and a
ret z

View File

@ -2227,13 +2227,10 @@ wEvolvableFlags:: flag_array PARTY_LENGTH
wForceEvolution:: db
UNION
; unidentified
wBuffer1:: db
wBuffer2:: db
wBuffer3:: db
wBuffer4:: db
wBuffer5:: db
wBuffer6:: db
; general-purpose HP buffers
wHPBuffer1:: dw
wHPBuffer2:: dw
wHPBuffer3:: dw
NEXTU
; HP bar animations
@ -2363,7 +2360,8 @@ wLinkBattleRNs:: ds SERIAL_RNS_LENGTH
NEXTU
; mobile
ds 2
wd1ea:: ds 1
wd1eb:: ds 1
wd1ec:: ds 1
wd1ed:: ds 1
wd1ee:: ds 1
@ -2372,6 +2370,7 @@ wd1f0:: ds 1
wd1f1:: ds 1
wd1f2:: ds 1
wd1f3:: ds 1
ds 6
NEXTU
; miscellaneous bytes