ref: 7254c100931d6c96c877ca7a2db3dc03076d138a
parent: a831b34e5c73b3166b6d45301861522b3c207cac
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Tue Nov 3 18:25:22 EST 2020
Identify remaining uses of wBuffer1-6 as general-purpose HP buffers or mobile
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -1797,26 +1797,26 @@
.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 @@
ret
GetMaxHP:
-; output: bc, wBuffer1-2
+; output: bc, wHPBuffer1
ld hl, wBattleMonMaxHP
ldh a, [hBattleTurn]
@@ -1891,11 +1891,11 @@
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 @@
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,26 +1940,26 @@
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
@@ -1966,10 +1966,10 @@
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 @@
; 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 @@
.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 @@
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
--- a/engine/battle/effect_commands.asm
+++ b/engine/battle/effect_commands.asm
@@ -2406,19 +2406,19 @@
.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 @@
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 @@
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 @@
.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,33 +3495,33 @@
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
@@ -3528,9 +3528,9 @@
.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,8 +3911,8 @@
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]
@@ -3919,7 +3919,7 @@
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 @@
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 @@
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 @@
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
--- a/engine/battle/move_effects/pain_split.asm
+++ b/engine/battle/move_effects/pain_split.asm
@@ -16,13 +16,13 @@
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 @@
.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 @@
.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:
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -1817,7 +1817,7 @@
ld [hl], d
inc hl
ld [hl], e
- jp LoadCurHPIntoBuffer5
+ jp LoadCurHPIntoBuffer3
RestoreHealth:
ld a, MON_HP + 1
@@ -1829,7 +1829,7 @@
adc d
ld [hl], a
jr c, .full_hp
- call LoadCurHPIntoBuffer5
+ call LoadCurHPIntoBuffer3
ld a, MON_HP + 1
call GetPartyParamLocation
ld d, h
@@ -1862,14 +1862,14 @@
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
@@ -1876,7 +1876,7 @@
ret
IsMonAtFullHealth:
- call LoadHPFromBuffer3
+ call LoadHPFromBuffer2
ld h, d
ld l, e
call LoadHPFromBuffer1
@@ -1886,60 +1886,60 @@
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
--- a/mobile/mobile_40.asm
+++ b/mobile/mobile_40.asm
@@ -6904,7 +6904,7 @@
Function103309:
xor a
ldh [hBGMapMode], a
- ld hl, wBuffer1
+ ld hl, wd1ea
ld bc, 10
xor a
call ByteFill
@@ -6912,7 +6912,7 @@
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 @@
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 @@
.b
call PlayClickSFX
- ld hl, wBuffer2
+ ld hl, wd1eb
set 7, [hl]
ret
@@ -7038,9 +7038,9 @@
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 @@
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 @@
call Function103487
ld bc, 8
call Function10350f
- ld a, [wBuffer1]
+ ld a, [wd1ea]
and e
ld bc, 2
jr z, .asm_10347d
--- a/mobile/mobile_5b.asm
+++ b/mobile/mobile_5b.asm
@@ -78,7 +78,7 @@
Function16c089:
ld a, $1
- ld [wBuffer2], a
+ ld [wd1eb], a
ld [wd1f1], a
xor a
ldh [hWY], a
@@ -96,7 +96,7 @@
Function16c0a8:
xor a
- ld [wBuffer2], a
+ ld [wd1eb], a
ld [wd1f1], a
call ClearSprites
ld a, $90
@@ -515,8 +515,8 @@
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 @@
ret
Function16cb2e:
- ld a, [wBuffer2]
+ ld a, [wd1eb]
and a
ret z
call Function16cb40
--- a/mobile/mobile_5e.asm
+++ b/mobile/mobile_5e.asm
@@ -41,7 +41,7 @@
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 @@
ret
Function17a6f5:
- ld hl, wBuffer1
+ ld hl, wd1ea
ld c, $0
ld b, $8
.asm_17a6fc
@@ -107,7 +107,7 @@
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 @@
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 @@
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 @@
lb bc, 2, 18
call ClearBox
hlcoord 3, 2
- ld de, wBuffer1
+ ld de, wd1ea
ld a, [$d08c]
and a
ret z
--- a/wram.asm
+++ b/wram.asm
@@ -2227,13 +2227,10 @@
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 @@
NEXTU
; mobile
- ds 2
+wd1ea:: ds 1
+wd1eb:: ds 1
wd1ec:: ds 1
wd1ed:: ds 1
wd1ee:: ds 1
@@ -2372,6 +2370,7 @@
wd1f1:: ds 1
wd1f2:: ds 1
wd1f3:: ds 1
+ ds 6
NEXTU
; miscellaneous bytes