shithub: pokecrystal

Download patch

ref: 9f62d7911bdc0550d9ef1e66195ed22fb7f3ba1c
parent: c88c4a834094e91f1505eab0e22294963e1dd987
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Tue Nov 3 17:45:12 EST 2020

Identify some more uses of wBuffer1-6

--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -3226,13 +3226,13 @@
 
 FindMonInOTPartyToSwitchIntoBattle:
 	ld b, -1
-	ld a, $1
-	ld [wBuffer1], a
-	ld [wBuffer2], a
+	ld a, %000001
+	ld [wEnemyEffectivenessVsPlayerMons], a
+	ld [wPlayerEffectivenessVsEnemyMons], a
 .loop
-	ld hl, wBuffer1
+	ld hl, wEnemyEffectivenessVsPlayerMons
 	sla [hl]
-	inc hl
+	inc hl ; wPlayerEffectivenessVsEnemyMons
 	sla [hl]
 	inc b
 	ld a, [wOTPartyCount]
@@ -3256,7 +3256,7 @@
 	jr .loop
 
 .discourage
-	ld hl, wBuffer2
+	ld hl, wPlayerEffectivenessVsEnemyMons
 	set 0, [hl]
 	jr .loop
 
@@ -3291,7 +3291,7 @@
 	ld a, [wTypeMatchup]
 	cp EFFECTIVE + 1
 	jr c, .loop
-	ld hl, wBuffer1
+	ld hl, wEnemyEffectivenessVsPlayerMons
 	set 0, [hl]
 	ret
 .done
@@ -3334,10 +3334,10 @@
 
 .super_effective
 	pop bc
-	ld hl, wBuffer1
+	ld hl, wEnemyEffectivenessVsPlayerMons
 	bit 0, [hl]
 	jr nz, .reset
-	inc hl
+	inc hl ; wPlayerEffectivenessVsEnemyMons
 	set 0, [hl]
 	ret
 
@@ -3347,9 +3347,9 @@
 
 ScoreMonTypeMatchups:
 .loop1
-	ld hl, wBuffer1
+	ld hl, wEnemyEffectivenessVsPlayerMons
 	sla [hl]
-	inc hl
+	inc hl ; wPlayerEffectivenessVsEnemyMons
 	sla [hl]
 	jr nc, .loop1
 	ld a, [wOTPartyCount]
@@ -3363,7 +3363,7 @@
 	jr .loop2
 
 .okay
-	ld a, [wBuffer1]
+	ld a, [wEnemyEffectivenessVsPlayerMons]
 	and a
 	jr z, .okay2
 	ld b, -1
@@ -3376,7 +3376,7 @@
 
 .okay2
 	ld b, -1
-	ld a, [wBuffer2]
+	ld a, [wPlayerEffectivenessVsEnemyMons]
 	ld c, a
 .loop4
 	inc b
--- a/engine/battle_anims/pokeball_wobble.asm
+++ b/engine/battle_anims/pokeball_wobble.asm
@@ -8,12 +8,12 @@
 	ld d, a
 	push de
 
-	ld a, BANK(wBuffer2)
+	ld a, BANK(wThrownBallWobbleCount) ; aka BANK(wFinalCatchRate)
 	ldh [rSVBK], a
 
-	ld a, [wBuffer2]
+	ld a, [wThrownBallWobbleCount]
 	inc a
-	ld [wBuffer2], a
+	ld [wThrownBallWobbleCount], a
 
 ; Wobble up to 3 times.
 	cp 3 + 1
@@ -25,7 +25,7 @@
 	jr nz, .done
 
 	ld hl, WobbleProbabilities
-	ld a, [wBuffer1]
+	ld a, [wFinalCatchRate]
 	ld b, a
 .loop
 	ld a, [hli]
--- a/engine/events/checkforhiddenitems.asm
+++ b/engine/events/checkforhiddenitems.asm
@@ -1,14 +1,14 @@
 CheckForHiddenItems:
 ; Checks to see if there are hidden items on the screen that have not yet been found.  If it finds one, returns carry.
 	call GetMapScriptsBank
-	ld [wBuffer1], a
-; Get the coordinate of the bottom right corner of the screen, and load it in wBuffer3/wBuffer4.
+	ld [wCurMapScriptBank], a
+; Get the coordinate of the bottom right corner of the screen, and load it in wBottomRightYCoord/wBottomRightXCoord.
 	ld a, [wXCoord]
 	add SCREEN_WIDTH / 4
-	ld [wBuffer4], a
+	ld [wBottomRightXCoord], a
 	ld a, [wYCoord]
 	add SCREEN_HEIGHT / 4
-	ld [wBuffer3], a
+	ld [wBottomRightYCoord], a
 ; Get the pointer for the first bg_event in the map...
 	ld hl, wCurMapBGEventsPointer
 	ld a, [hli]
@@ -20,14 +20,14 @@
 	jr z, .nobgeventitems
 ; For i = 1:wCurMapBGEventCount...
 .loop
-; Store the counter in wBuffer2, and store the bg_event pointer in the stack.
-	ld [wBuffer2], a
+; Store the counter in wRemainingBGEventCount, and store the bg_event pointer in the stack.
+	ld [wRemainingBGEventCount], a
 	push hl
 ; Get the Y coordinate of the BG event.
 	call .GetFarByte
 	ld e, a
 ; Is the Y coordinate of the BG event on the screen?  If not, go to the next BG event.
-	ld a, [wBuffer3]
+	ld a, [wBottomRightYCoord]
 	sub e
 	jr c, .next
 	cp SCREEN_HEIGHT / 2
@@ -35,7 +35,7 @@
 ; Is the X coordinate of the BG event on the screen?  If not, go to the next BG event.
 	call .GetFarByte
 	ld d, a
-	ld a, [wBuffer4]
+	ld a, [wBottomRightXCoord]
 	sub d
 	jr c, .next
 	cp SCREEN_WIDTH / 2
@@ -45,9 +45,9 @@
 	cp BGEVENT_ITEM
 	jr nz, .next
 ; Has this item already been found?  If not, set off the Itemfinder.
-	ld a, [wBuffer1]
+	ld a, [wCurMapScriptBank]
 	call GetFarHalfword
-	ld a, [wBuffer1]
+	ld a, [wCurMapScriptBank]
 	call GetFarHalfword
 	ld d, h
 	ld e, l
@@ -63,7 +63,7 @@
 	ld bc, BG_EVENT_SIZE
 	add hl, bc
 ; Restore the BG event counter and decrement it.  If it hits zero, there are no hidden items in range.
-	ld a, [wBuffer2]
+	ld a, [wRemainingBGEventCount]
 	dec a
 	jr nz, .loop
 
@@ -77,7 +77,7 @@
 	ret
 
 .GetFarByte:
-	ld a, [wBuffer1]
+	ld a, [wCurMapScriptBank]
 	call GetFarByte
 	inc hl
 	ret
--- a/engine/events/overworld.asm
+++ b/engine/events/overworld.asm
@@ -1,14 +1,14 @@
 FieldMoveJumptableReset:
 	xor a
-	ld hl, wBuffer1
-	ld bc, 7
+	ld hl, wFieldMoveData
+	ld bc, wFieldMoveDataEnd - wFieldMoveData
 	call ByteFill
 	ret
 
 FieldMoveJumptable:
-	ld a, [wBuffer1]
+	ld a, [wFieldMoveJumptableIndex]
 	rst JumpTable
-	ld [wBuffer1], a
+	ld [wFieldMoveJumptableIndex], a
 	bit 7, a
 	jr nz, .okay
 	and a
@@ -183,17 +183,15 @@
 	call CheckOverworldTileArrays
 	pop hl
 	jr nc, .fail
-	; Back up the wOverworldMapBlocks address to wBuffer3
+	; Save the Cut field move data
 	ld a, l
-	ld [wBuffer3], a
+	ld [wCutWhirlpoolOverworldBlockAddr], a
 	ld a, h
-	ld [wBuffer4], a
-	; Back up the replacement tile to wBuffer5
+	ld [wCutWhirlpoolOverworldBlockAddr + 1], a
 	ld a, b
-	ld [wBuffer5], a
-	; Back up the animation index to wBuffer6
+	ld [wCutWhirlpoolReplacementBlock], a
 	ld a, c
-	ld [wBuffer6], a
+	ld [wCutWhirlpoolAnimationType], a
 	xor a
 	ret
 
@@ -214,11 +212,11 @@
 	end
 
 CutDownTreeOrGrass:
-	ld hl, wBuffer3 ; OverworldMapTile
+	ld hl, wCutWhirlpoolOverworldBlockAddr
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld a, [wBuffer5] ; ReplacementTile
+	ld a, [wCutWhirlpoolReplacementBlock]
 	ld [hl], a
 	xor a
 	ldh [hBGMapMode], a
@@ -225,7 +223,7 @@
 	call OverworldTextModeSwitch
 	call UpdateSprites
 	call DelayFrame
-	ld a, [wBuffer6] ; Animation type
+	ld a, [wCutWhirlpoolAnimationType]
 	ld e, a
 	farcall OWCutAnimation
 	call BufferScreen
@@ -380,7 +378,7 @@
 
 .DoSurf:
 	call GetSurfType
-	ld [wBuffer2], a
+	ld [wSurfingPlayerState], a
 	call GetPartyNick
 	ld hl, SurfFromMenuScript
 	call QueueScript
@@ -409,7 +407,7 @@
 
 	callasm .stubbed_fn
 
-	readmem wBuffer2
+	readmem wSurfingPlayerState
 	writevar VAR_MOVEMENT
 
 	special UpdatePlayerSprite
@@ -517,7 +515,7 @@
 	jr nz, .quit
 
 	call GetSurfType
-	ld [wBuffer2], a
+	ld [wSurfingPlayerState], a
 	call GetPartyNick
 
 	ld a, BANK(AskSurfScript)
@@ -757,7 +755,7 @@
 	ld a, $2
 
 EscapeRopeOrDig:
-	ld [wBuffer2], a
+	ld [wEscapeRopeOrDigType], a
 .loop
 	ld hl, .DigTable
 	call FieldMoveJumptable
@@ -801,7 +799,7 @@
 	ld bc, 3
 	call CopyBytes
 	call GetPartyNick
-	ld a, [wBuffer2]
+	ld a, [wEscapeRopeOrDigType]
 	cp $2
 	jr nz, .escaperope
 	ld hl, .UsedDigScript
@@ -817,7 +815,7 @@
 	ret
 
 .FailDig:
-	ld a, [wBuffer2]
+	ld a, [wEscapeRopeOrDigType]
 	cp $2
 	jr nz, .failescaperope
 	ld hl, .CantUseDigText
@@ -1000,7 +998,7 @@
 	ld hl, wPartySpecies
 	add hl, de
 	ld a, [hl]
-	ld [wBuffer6], a
+	ld [wStrengthSpecies], a
 	call GetPartyNick
 	ret
 
@@ -1011,8 +1009,8 @@
 Script_UsedStrength:
 	callasm SetStrengthFlag
 	writetext .UseStrengthText
-	readmem wBuffer6
-	cry 0
+	readmem wStrengthSpecies
+	cry 0 ; plays [wStrengthSpecies] cry
 	pause 3
 	writetext .MoveBoulderText
 	closetext
@@ -1147,14 +1145,15 @@
 	call CheckOverworldTileArrays
 	pop hl
 	jr nc, .failed
+	; Save the Whirlpool field move data
 	ld a, l
-	ld [wBuffer3], a
+	ld [wCutWhirlpoolOverworldBlockAddr], a
 	ld a, h
-	ld [wBuffer4], a
+	ld [wCutWhirlpoolOverworldBlockAddr + 1], a
 	ld a, b
-	ld [wBuffer5], a
+	ld [wCutWhirlpoolReplacementBlock], a
 	ld a, c
-	ld [wBuffer6], a
+	ld [wCutWhirlpoolAnimationType], a
 	xor a
 	ret
 
@@ -1175,16 +1174,16 @@
 	end
 
 DisappearWhirlpool:
-	ld hl, wBuffer3
+	ld hl, wCutWhirlpoolOverworldBlockAddr
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld a, [wBuffer5]
+	ld a, [wCutWhirlpoolReplacementBlock]
 	ld [hl], a
 	xor a
 	ldh [hBGMapMode], a
 	call OverworldTextModeSwitch
-	ld a, [wBuffer6]
+	ld a, [wCutWhirlpoolAnimationType]
 	ld e, a
 	farcall PlayWhirlpoolSound
 	call BufferScreen
@@ -1429,7 +1428,7 @@
 	push af
 	call FieldMoveJumptableReset
 	pop af
-	ld [wBuffer2], a
+	ld [wFishingRodUsed], a
 .loop
 	ld hl, .FishTable
 	call FieldMoveJumptable
@@ -1468,7 +1467,7 @@
 
 .goodtofish
 	ld d, a
-	ld a, [wBuffer2]
+	ld a, [wFishingRodUsed]
 	ld e, a
 	farcall Fish
 	ld a, d
@@ -1492,7 +1491,7 @@
 
 .FishGotSomething:
 	ld a, $1
-	ld [wBuffer6], a
+	ld [wFishingResult], a
 	ld hl, Script_GotABite
 	call QueueScript
 	ld a, $81
@@ -1500,7 +1499,7 @@
 
 .FishNoBite:
 	ld a, $2
-	ld [wBuffer6], a
+	ld [wFishingResult], a
 	ld hl, Script_NotEvenANibble
 	call QueueScript
 	ld a, $81
@@ -1508,7 +1507,7 @@
 
 .FishNoFish:
 	ld a, $0
-	ld [wBuffer6], a
+	ld [wFishingResult], a
 	ld hl, Script_NotEvenANibble2
 	call QueueScript
 	ld a, $81
--- a/engine/items/item_effects.asm
+++ b/engine/items/item_effects.asm
@@ -360,7 +360,7 @@
 
 .skip_hp_calc
 	ld b, a
-	ld [wBuffer1], a
+	ld [wFinalCatchRate], a
 	call Random
 
 	cp b
@@ -390,7 +390,7 @@
 	ld [wFXAnimID + 1], a
 	xor a
 	ldh [hBattleTurn], a
-	ld [wBuffer2], a
+	ld [wThrownBallWobbleCount], a
 	ld [wNumHits], a
 	predef PlayBattleAnim
 
@@ -397,21 +397,21 @@
 	ld a, [wWildMon]
 	and a
 	jr nz, .caught
-	ld a, [wBuffer2]
-	cp $1
+	ld a, [wThrownBallWobbleCount]
+	cp 1
 	ld hl, BallBrokeFreeText
 	jp z, .shake_and_break_free
-	cp $2
+	cp 2
 	ld hl, BallAppearedCaughtText
 	jp z, .shake_and_break_free
-	cp $3
+	cp 3
 	ld hl, BallAlmostHadItText
 	jp z, .shake_and_break_free
-	cp $4
+	cp 4
 	ld hl, BallSoCloseText
 	jp z, .shake_and_break_free
-.caught
 
+.caught
 	ld hl, wEnemyMonStatus
 	ld a, [hli]
 	push af
@@ -2723,12 +2723,12 @@
 	ld a, MON_MOVES
 	call GetPartyParamLocation
 	push hl
-	ld de, wBuffer1
+	ld de, wPPUpPPBuffer
 	predef FillPP
 	pop hl
 	ld bc, MON_PP - MON_MOVES
 	add hl, bc
-	ld de, wBuffer1
+	ld de, wPPUpPPBuffer
 	ld b, 0
 .loop
 	inc b
--- a/wram.asm
+++ b/wram.asm
@@ -2248,14 +2248,24 @@
 wCurHPAnimHighHP::  db
 
 NEXTU
-; battle AI
+; move AI
 wEnemyAIMoveScores:: ds NUM_MOVES
 
 NEXTU
+; switch AI
+wEnemyEffectivenessVsPlayerMons:: flag_array PARTY_LENGTH
+wPlayerEffectivenessVsEnemyMons:: flag_array PARTY_LENGTH
+
+NEXTU
 ; battle HUD
 wBattleHUDTiles:: ds PARTY_LENGTH
 
 NEXTU
+; thrown ball data
+wFinalCatchRate:: db
+wThrownBallWobbleCount:: db
+
+NEXTU
 ; evolution data
 wEvolutionOldSpecies:: db
 wEvolutionNewSpecies:: db
@@ -2267,6 +2277,10 @@
 wExpToNextLevel:: ds 3
 
 NEXTU
+; PP Up
+wPPUpPPBuffer:: ds NUM_MOVES
+
+NEXTU
 ; lucky number show
 wMonIDDigitsBuffer:: ds 5
 
@@ -2274,6 +2288,28 @@
 ; mon submenu
 wMonSubmenuCount:: db
 wMonSubmenuItems:: ds NUM_MONMENU_ITEMS + 1
+
+NEXTU
+; field move data
+wFieldMoveData::
+wFieldMoveJumptableIndex:: db
+wEscapeRopeOrDigType::
+wSurfingPlayerState::
+wFishingRodUsed:: db
+wCutWhirlpoolOverworldBlockAddr:: dw
+wCutWhirlpoolReplacementBlock:: db
+wCutWhirlpoolAnimationType::
+wStrengthSpecies::
+wFishingResult:: db
+	ds 1
+wFieldMoveDataEnd::
+
+NEXTU
+; hidden items
+wCurMapScriptBank:: db
+wRemainingBGEventCount:: db
+wBottomRightYCoord:: db
+wBottomRightXCoord:: db
 
 NEXTU
 ; heal machine anim