summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--constants/misc_constants.asm6
-rw-r--r--engine/battle/common_text.asm39
-rwxr-xr-xengine/battle/core.asm86
-rw-r--r--engine/battle/wild_encounters.asm10
-rwxr-xr-xengine/hidden_object_functions17.asm2
-rwxr-xr-xengine/hidden_object_functions7.asm8
-rwxr-xr-xengine/oak_speech.asm2
-rwxr-xr-xengine/overworld/card_key.asm4
-rw-r--r--home.asm18
-rw-r--r--hram.asm6
-rwxr-xr-xwram.asm7
11 files changed, 104 insertions, 84 deletions
diff --git a/constants/misc_constants.asm b/constants/misc_constants.asm
index 68090c78..4f2eb275 100644
--- a/constants/misc_constants.asm
+++ b/constants/misc_constants.asm
@@ -139,6 +139,12 @@ FLAG_RESET EQU 0
FLAG_SET EQU 1
FLAG_TEST EQU 2
+; special text IDs
+TEXT_MON_FAINTED EQU $d0
+TEXT_BLACKED_OUT EQU $d1
+TEXT_REPEL_WORE_OFF EQU $d2
+TEXT_SAFARI_GAME_OVER EQU $d3
+
; serial
ESTABLISH_CONNECTION_WITH_INTERNAL_CLOCK EQU $01
diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm
index 1acef280..a00e9d59 100644
--- a/engine/battle/common_text.asm
+++ b/engine/battle/common_text.asm
@@ -104,10 +104,10 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59)
ld [H_MULTIPLICAND], a
ld hl, wEnemyMonHP
ld a, [hli]
- ld [wcce3], a
+ ld [wLastSwitchInEnemyMonHP], a
ld [H_MULTIPLICAND + 1], a
ld a, [hl]
- ld [wcce4], a
+ ld [wLastSwitchInEnemyMonHP + 1], a
ld [H_MULTIPLICAND + 2], a
ld a, 25
ld [H_MULTIPLIER], a
@@ -120,7 +120,7 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59)
srl a
rr b
ld a, b
- ld b, $4
+ ld b, 4
ld [H_DIVISOR], a ; enemy mon max HP divided by 4
call Divide
ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP
@@ -174,19 +174,19 @@ PlayerMon2Text: ; 58ed7 (16:4ed7)
push de
push bc
ld hl, wEnemyMonHP + 1
- ld de, wcce4
+ ld de, wLastSwitchInEnemyMonHP + 1
ld b, [hl]
dec hl
ld a, [de]
sub b
- ld [$ff98], a
+ ld [H_MULTIPLICAND + 2], a
dec de
ld b, [hl]
ld a, [de]
sbc b
- ld [$ff97], a
- ld a, $19
- ld [H_POWEROFTEN], a
+ ld [H_MULTIPLICAND + 1], a
+ ld a, 25
+ ld [H_MULTIPLIER], a
call Multiply
ld hl, wEnemyMonMaxHP
ld a, [hli]
@@ -196,22 +196,27 @@ PlayerMon2Text: ; 58ed7 (16:4ed7)
srl a
rr b
ld a, b
- ld b, $4
- ld [H_POWEROFTEN], a
+ ld b, 4
+ ld [H_DIVISOR], a
call Divide
pop bc
pop de
- ld a, [$ff98]
- ld hl, EnoughText
+ ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4)
+; Assuming that the enemy mon hasn't gained HP since the last switch in,
+; a approximates the percentage that the enemy mon's total HP has decreased
+; since the last switch in.
+; If the enemy mon has gained HP, then a is garbage due to wrap-around and
+; can fall in any of the ranges below.
+ ld hl, EnoughText ; HP stayed the same
and a
ret z
- ld hl, ComeBackText
- cp $1e
+ ld hl, ComeBackText ; HP went down 1% - 29%
+ cp 30
ret c
- ld hl, OKExclamationText
- cp $46
+ ld hl, OKExclamationText ; HP went down 30% - 69%
+ cp 70
ret c
- ld hl, GoodText
+ ld hl, GoodText ; HP went down 70% or more
ret
EnoughText: ; 58f25 (16:4f25)
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 4c29e003..2be2f78a 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -175,7 +175,7 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
ld a, $31
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 1, 5
predef CopyUncompressedPicToTilemap
xor a
@@ -1429,9 +1429,9 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call LoadEnemyMonData
ld hl,wEnemyMonHP
ld a,[hli]
- ld [wcce3],a
+ ld [wLastSwitchInEnemyMonHP],a
ld a,[hl]
- ld [wcce4],a
+ ld [wLastSwitchInEnemyMonHP + 1],a
ld a,1
ld [wCurrentMenuItem],a
ld a,[wd11d]
@@ -1497,8 +1497,8 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call GetMonHeader
ld de,vFrontPic
call LoadMonFrontSprite
- ld a,$CF
- ld [$FFE1],a
+ ld a,-$31
+ ld [hStartTileID],a
coord hl, 15, 6
predef AnimateSendingOutMon
ld a,[wEnemyMonSpecies2]
@@ -1802,7 +1802,7 @@ SendOutMon: ; 3cc91 (f:4c91)
call DrawPlayerHUDAndHPBar
predef LoadMonBackPic
xor a
- ld [$ffe1], a
+ ld [hStartTileID], a
ld hl, wBattleAndStartSavedMenuItem
ld [hli], a
ld [hl], a
@@ -1839,23 +1839,23 @@ SendOutMon: ; 3cc91 (f:4c91)
; show 2 stages of the player mon getting smaller before disappearing
AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
coord hl, 1, 5
- ld bc, $707
+ lb bc, 7, 7
call ClearScreenArea
coord hl, 3, 7
- ld bc, $505
+ lb bc, 5, 5
xor a
ld [wDownscaledMonSize], a
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hBaseTileID], a
predef CopyDownscaledMonTiles
ld c, 4
call DelayFrames
call .clearScreenArea
coord hl, 4, 9
- ld bc, $303
- ld a, $1
+ lb bc, 3, 3
+ ld a, 1
ld [wDownscaledMonSize], a
xor a
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hBaseTileID], a
predef CopyDownscaledMonTiles
call Delay3
call .clearScreenArea
@@ -1863,7 +1863,7 @@ AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa)
Coorda 5, 11
.clearScreenArea
coord hl, 1, 5
- ld bc, $707
+ lb bc, 7, 7
jp ClearScreenArea
; reads player's current mon's HP into wBattleMonHP
@@ -6449,7 +6449,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92)
xor a
ld [$0], a
ld a, $31
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 1, 5
predef_jump CopyUncompressedPicToTilemap
@@ -6862,7 +6862,7 @@ InitBattleCommon: ; 3ef3d (f:6f3d)
call _LoadTrainerPic
xor a
ld [wEnemyMonSpecies2], a
- ld [$ffe1], a
+ ld [hStartTileID], a
dec a
ld [wAICount], a
coord hl, 12, 0
@@ -6918,7 +6918,7 @@ InitWildBattle: ; 3ef8b (f:6f8b)
.spriteLoaded
xor a
ld [W_TRAINERCLASS], a
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 12, 0
predef CopyUncompressedPicToTilemap
@@ -6995,38 +6995,38 @@ AnimateSendingOutMon: ; 3f073 (f:7073)
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
- ld [H_DOWNARROWBLINKCNT1], a
+ ld a, [hStartTileID]
+ ld [hBaseTileID], a
ld b, $4c
ld a, [W_ISINBATTLE]
and a
- jr z, .asm_3f0bc
+ jr z, .notInBattle
add b
ld [hl], a
call Delay3
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
- ld a, $1
+ ld a, 1
ld [wDownscaledMonSize], a
- ld bc, $303
+ lb bc, 3, 3
predef CopyDownscaledMonTiles
ld c, 4
call DelayFrames
- ld bc, -41
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
add hl, bc
xor a
ld [wDownscaledMonSize], a
- ld bc, $505
+ lb bc, 5, 5
predef CopyDownscaledMonTiles
ld c, 5
call DelayFrames
- ld bc, -41
- jr .asm_3f0bf
-.asm_3f0bc
- ld bc, -123
-.asm_3f0bf
+ ld bc, -(SCREEN_WIDTH * 2 + 1)
+ jr .next
+.notInBattle
+ ld bc, -(SCREEN_WIDTH * 6 + 3)
+.next
add hl, bc
- ld a, [H_DOWNARROWBLINKCNT1]
+ ld a, [hBaseTileID]
add $31
jr CopyUncompressedPicToHL
@@ -7035,52 +7035,52 @@ CopyUncompressedPicToTilemap: ; 3f0c6 (f:70c6)
ld h, a
ld a, [wPredefRegisters + 1]
ld l, a
- ld a, [$ffe1]
+ ld a, [hStartTileID]
CopyUncompressedPicToHL: ; 3f0d0 (f:70d0)
- ld bc, $707
+ lb bc, 7, 7
ld de, SCREEN_WIDTH
push af
ld a, [W_SPRITEFLIPPED]
and a
- jr nz, .asm_3f0ed
+ jr nz, .flipped
pop af
-.asm_3f0de
+.loop
push bc
push hl
-.asm_3f0e0
+.innerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0e0
+ jr nz, .innerLoop
pop hl
inc hl
pop bc
dec b
- jr nz, .asm_3f0de
+ jr nz, .loop
ret
-.asm_3f0ed
+.flipped
push bc
- ld b, $0
+ ld b, 0
dec c
add hl, bc
pop bc
pop af
-.asm_3f0f4
+.flippedLoop
push bc
push hl
-.asm_3f0f6
+.flippedInnerLoop
ld [hl], a
add hl, de
inc a
dec c
- jr nz, .asm_3f0f6
+ jr nz, .flippedInnerLoop
pop hl
dec hl
pop bc
dec b
- jr nz, .asm_3f0f4
+ jr nz, .flippedLoop
ret
LoadMonBackPic: ; 3f103 (f:7103)
diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm
index 5964f996..144234bb 100644
--- a/engine/battle/wild_encounters.asm
+++ b/engine/battle/wild_encounters.asm
@@ -18,11 +18,11 @@ TryDoWildEncounter: ; 13870 (4:7870)
jr z, .CantEncounter
ld a, [wRepelRemainingSteps]
and a
- jr z, .asm_1389e
+ jr z, .next
dec a
jr z, .lastRepelStep
ld [wRepelRemainingSteps], a
-.asm_1389e
+.next
; determine if wild pokemon can appear in the half-block we're standing in
; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile?
coord hl, 9, 9
@@ -71,7 +71,7 @@ TryDoWildEncounter: ; 13870 (4:7870)
; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not,
; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters.
.gotWildEncounterType
- ld b, $0
+ ld b, 0
add hl, bc
ld a, [hli]
ld [W_CURENEMYLVL], a
@@ -89,8 +89,8 @@ TryDoWildEncounter: ; 13870 (4:7870)
jr .willEncounter
.lastRepelStep
ld [wRepelRemainingSteps], a
- ld a, 210
- ld [H_DOWNARROWBLINKCNT2], a
+ ld a, TEXT_REPEL_WORE_OFF
+ ld [hSpriteIndexOrTextID], a
call EnableAutoTextBoxDrawing
call DisplayTextID
.CantEncounter2
diff --git a/engine/hidden_object_functions17.asm b/engine/hidden_object_functions17.asm
index 01787e3e..97681b79 100755
--- a/engine/hidden_object_functions17.asm
+++ b/engine/hidden_object_functions17.asm
@@ -71,7 +71,7 @@ DisplayMonFrontSpriteInBox: ; 5dbd9 (17:5bd9)
ld de, vChars1 + $310
call LoadMonFrontSprite
ld a, $80
- ld [$ffe1], a
+ ld [hStartTileID], a
coord hl, 10, 11
predef AnimateSendingOutMon
call WaitForTextScrollButtonPress
diff --git a/engine/hidden_object_functions7.asm b/engine/hidden_object_functions7.asm
index 6f1eef61..283bf32f 100755
--- a/engine/hidden_object_functions7.asm
+++ b/engine/hidden_object_functions7.asm
@@ -73,19 +73,19 @@ SafariZoneGameOver: ; 1e9b0 (7:69b0)
ld a, [wc02a]
cp $b9
jr nz, .asm_1e9c2
- ld a, $d3
- ld [H_DOWNARROWBLINKCNT2], a
+ ld a, TEXT_SAFARI_GAME_OVER
+ ld [hSpriteIndexOrTextID], a
call DisplayTextID
xor a
ld [wPlayerMovingDirection], a
ld a, SAFARI_ZONE_ENTRANCE
- ld [H_DOWNARROWBLINKCNT1], a
+ ld [hWarpDestinationMap], a
ld a, $3
ld [wDestinationWarpID], a
ld a, $5
ld [W_SAFARIZONEENTRANCECURSCRIPT], a
SetEvent EVENT_SAFARI_GAME_OVER
- ld a, $1
+ ld a, 1
ld [wSafariZoneGameOver], a
ret
diff --git a/engine/oak_speech.asm b/engine/oak_speech.asm
index be84b99d..5b6c29e1 100755
--- a/engine/oak_speech.asm
+++ b/engine/oak_speech.asm
@@ -229,5 +229,5 @@ IntroDisplayPicCenteredOrUpperRight: ; 62a4 (1:62a4)
coord hl, 6, 4
.next
xor a
- ld [$FFE1],a
+ ld [hStartTileID],a
predef_jump CopyUncompressedPicToTilemap
diff --git a/engine/overworld/card_key.asm b/engine/overworld/card_key.asm
index 746ea326..0bb2e1b4 100755
--- a/engine/overworld/card_key.asm
+++ b/engine/overworld/card_key.asm
@@ -28,7 +28,7 @@ PrintCardKeyText: ; 52673 (14:6673)
call GetCoordsInFrontOfPlayer
push de
tx_pre_id CardKeySuccessText
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
call PrintPredefTextID
pop de
srl d
@@ -55,7 +55,7 @@ PrintCardKeyText: ; 52673 (14:6673)
jp PlaySound
.noCardKey
tx_pre_id CardKeyFailText
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
jp PrintPredefTextID
SilphCoMapList: ; 526e3 (14:66e3)
diff --git a/home.asm b/home.asm
index ddb3e190..d5961082 100644
--- a/home.asm
+++ b/home.asm
@@ -301,7 +301,7 @@ LoadFrontSpriteByMonIndex:: ; 1389 (0:1389)
ld [H_LOADEDROMBANK], a
ld [MBC1RomBank], a
xor a
- ld [$ffe1], a
+ ld [hStartTileID], a
call CopyUncompressedPicToHL
xor a
ld [W_SPRITEFLIPPED], a
@@ -1071,13 +1071,13 @@ DisplayTextID:: ; 2920 (0:2920)
ld [wSpriteIndex],a
and a
jp z,DisplayStartMenu
- cp a,$d3
+ cp a,TEXT_SAFARI_GAME_OVER
jp z,DisplaySafariGameOverText
- cp a,$d0
+ cp a,TEXT_MON_FAINTED
jp z,DisplayPokemonFaintedText
- cp a,$d1
+ cp a,TEXT_BLACKED_OUT
jp z,DisplayPlayerBlackedOutText
- cp a,$d2
+ cp a,TEXT_REPEL_WORE_OFF
jp z,DisplayRepelWoreOffText
ld a,[W_NUMSPRITES]
ld e,a
@@ -2825,7 +2825,7 @@ DecodeRLEList:: ; 350c (0:350c)
ld a, [de]
cp $ff
jr z, .endOfList
- ld [H_DOWNARROWBLINKCNT1], a ; store byte value to be written
+ ld [hRLEByteValue], a ; store byte value to be written
inc de
ld a, [de]
ld b, $0
@@ -2833,7 +2833,7 @@ DecodeRLEList:: ; 350c (0:350c)
ld a, [wRLEByteCount]
add c
ld [wRLEByteCount], a ; update total number of written bytes
- ld a, [H_DOWNARROWBLINKCNT1]
+ ld a, [hRLEByteValue]
call FillMemory ; write a c-times to output
inc de
jr .listLoop
@@ -3906,7 +3906,7 @@ HandleMenuInputPokemonSelection:: ; 3ac2 (0:3ac2)
push af ; save existing values on stack
xor a
ld [H_DOWNARROWBLINKCNT1],a ; blinking down arrow timing value 1
- ld a,$06
+ ld a,6
ld [H_DOWNARROWBLINKCNT2],a ; blinking down arrow timing value 2
.loop1
xor a
@@ -4631,7 +4631,7 @@ CheckForHiddenObjectOrBookshelfOrCardKeyDoor:: ; 3eb5 (0:3eb5)
ret
PrintPredefTextID:: ; 3ef5 (0:3ef5)
- ld [H_DOWNARROWBLINKCNT2], a
+ ld [hSpriteIndexOrTextID], a
ld hl, TextPredefs
call SetMapTextPointer
ld hl, wTextPredefFlag
diff --git a/hram.asm b/hram.asm
index 0b7274ad..27da5c22 100644
--- a/hram.asm
+++ b/hram.asm
@@ -4,6 +4,7 @@ hSoftReset EQU $FF8A
; presses the reset sequence (A+B+SEL+START).
; Soft reset when 0 is reached.
+; base tile ID to which offsets are added
hBaseTileID EQU $FF8B
; 3-byte BCD number
@@ -23,6 +24,8 @@ hEastWestConnectedMapWidth EQU $FF8B
hSlideAmount EQU $FF8B
+hRLEByteValue EQU $FF8B
+
H_SPRITEWIDTH EQU $FF8B ; in tiles
H_SPRITEINTERLACECOUNTER EQU $FF8B
H_SPRITEHEIGHT EQU $FF8C ; in tiles
@@ -261,6 +264,9 @@ H_CURRENTSPRITEOFFSET EQU $FFDA ; multiple of $10
hVendingMachineItem EQU $FFDB
hVendingMachinePrice EQU $FFDC ; 3-byte BCD number
+; the first tile ID in a sequence of tile IDs that increase by 1 each step
+hStartTileID EQU $FFE1
+
hNewPartyLength EQU $FFE4
hDividend2 EQU $FFE5
diff --git a/wram.asm b/wram.asm
index ed14cdf5..da981d22 100755
--- a/wram.asm
+++ b/wram.asm
@@ -479,8 +479,11 @@ wAICount:: ; ccdf
wEnemyMoveListIndex:: ; cce2
ds 1
-wcce3:: ds 1 ; used in battle-related text functions
-wcce4:: ds 1 ; used in battle-related text functions
+wLastSwitchInEnemyMonHP:: ; cce3
+; The enemy mon's HP when it was switched in or when the current player mon
+; was switched in, which was more recent.
+; It's used to determine the message to print when switching out the player mon.
+ ds 2
wTotalPayDayMoney:: ; cce5
; total amount of money made using Pay Day during the current battle